Esempio n. 1
0
bool Libdc1394SequenceGrabber::initFrameRate(unsigned int rate) 
{
	msg(osg::INFO) << "initFrameRate" << std::endl;
	
	if (!_camera) return false;
    
    if (_format7) {
        uint32_t bit_size;
        dc1394_get_color_coding_bit_size(_sourceFormat,&bit_size);
        int packet_size = DC1394_USE_MAX_AVAIL;
        
        if(rate != 0) {
            double bus_period;
			if(_speed == DC1394_ISO_SPEED_800) {
				bus_period = 0.0000625;
			}
			else {
				bus_period = 0.000125;
			}

            int num_packets = (int)(1.0/(bus_period*rate)+0.5);
            packet_size = ((_roi.width - _roi.x)*(_roi.height - _roi.y)*bit_size + (num_packets*8) - 1) / (num_packets*8);
        }
        
        dc1394error_t err = dc1394_format7_set_packet_size(_camera, _videomode, packet_size);
        checkSuccess(err, "dc1394_format7_set_packet_size failed");
        
        err = dc1394_format7_set_roi(_camera, _videomode, _sourceFormat, packet_size, _roi.x,_roi.y,_roi.width,_roi.height);
        checkSuccess(err, "dc1394_format7_set_roi failed");
        return (err == DC1394_SUCCESS);
    }
	
	dc1394framerates_t framerates;
	dc1394error_t err=dc1394_video_get_supported_framerates(_camera,_videomode, &framerates);
    checkSuccess(err, "dc1394_video_get_supported_framerates failed");
    
	dc1394framerate_t framerate=framerates.framerates[framerates.num-1];
	
	switch (rate) {
		case 15:
			framerate = DC1394_FRAMERATE_15;
			break;
		case 30:
			framerate = DC1394_FRAMERATE_30;
			break;
		case 60:
			framerate = DC1394_FRAMERATE_60;
			break;
		case 120:
			framerate = DC1394_FRAMERATE_120;
			break;
		case 240:
			framerate = DC1394_FRAMERATE_240;
	}
	
	err=dc1394_video_set_framerate(_camera, framerate);
    checkSuccess(err, "dc1394_video_set_framerate failed");
    
	return (err == DC1394_SUCCESS);
}
Esempio n. 2
0
void ofxLibdc::applySettings() {
	if(camera)
		dc1394_capture_stop(camera);
		
	if(use1394b) {
		// assumes you want to run your 1394b camera at 800 Mbps
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_800);
	} else {
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_LEGACY);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
	}
		
	dc1394framerate_t framerate;
	if(useFormat7) {
		videoMode = (dc1394video_mode_t) ((int) DC1394_VIDEO_MODE_FORMAT7_0 + format7Mode);
	} else {
		dc1394video_modes_t video_modes;
		dc1394_video_get_supported_modes(camera, &video_modes);
		dc1394color_coding_t coding;
		dc1394color_coding_t targetCoding = getLibdcType(imageType);
		for (int i = 0; i < video_modes.num; i++) {
			if (!dc1394_is_video_mode_scalable(video_modes.modes[i])) {
				dc1394video_mode_t curMode = video_modes.modes[i];
				dc1394_get_color_coding_from_video_mode(camera, curMode, &coding);
				unsigned int curWidth, curHeight;
				dc1394_get_image_size_from_video_mode(camera, curMode, &curWidth, &curHeight);
				if (coding == targetCoding && width == curWidth && height == curHeight) {
					videoMode = curMode;
					break;
				}
			}
			if(i == video_modes.num - 1) {
				ofLog(OF_LOG_ERROR, "Camera does not support target mode.");
				return;
			}
		}
		
		// get fastest framerate
		// todo: make this settable
		dc1394framerates_t framerates;
		dc1394_video_get_supported_framerates(camera, videoMode, &framerates);
		framerate = framerates.framerates[framerates.num - 1];
	}
	
	if(useFormat7) {
		quantizePosition();
		quantizeSize();
		dc1394_format7_set_roi(camera, videoMode, getLibdcType(imageType), DC1394_USE_MAX_AVAIL, left, top, width, height);
		unsigned int curWidth, curHeight;
		dc1394_format7_get_image_size(camera, videoMode, &curWidth, &curHeight);
	} else {
		dc1394_video_set_framerate(camera, framerate);
	}
	
	// contrary to the libdc1394 format7 demo, this should go after the roi setting
	dc1394_video_set_mode(camera, videoMode);
		
	dc1394_capture_setup(camera, OFXLIBDC_BUFFER_SIZE, DC1394_CAPTURE_FLAGS_DEFAULT);
}
Esempio n. 3
0
int _setVideoMode(int mode, long *sizex, long *sizey){
  if(camera==NULL) {
    dc1394_log_error("Camera is not initialised");
    return -1;
  }

  switch(mode) { 
  case 0 : video_mode=DC1394_VIDEO_MODE_FORMAT7_0;break;
  case 1 : video_mode=DC1394_VIDEO_MODE_FORMAT7_1;break;
  case 2 : video_mode=DC1394_VIDEO_MODE_FORMAT7_2;break;
  case 3 : video_mode=DC1394_VIDEO_MODE_FORMAT7_3;break;
  default : ;
  }
  unsigned int h_size = 160;
  unsigned int v_size = 120;

  err = dc1394_format7_get_max_image_size(camera, video_mode, &h_size, &v_size);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not get max image size of Format7 mode");
  *sizex = h_size;
  *sizey = v_size;

  err = dc1394_video_set_mode(camera, video_mode);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not set Format7 mode");

  err = dc1394_format7_set_roi(camera, video_mode,
			       DC1394_COLOR_CODING_MONO16,
			       DC1394_USE_MAX_AVAIL, // use max packet size
			       0, 0, // left, top
			       h_size, v_size);  // width, height
  DC1394_ERR_RTN(err,"Unable to set Format7 mode 0.\nEdit the example file manually to fit your camera capabilities");

  return 0;
}
Esempio n. 4
0
int _setROI(long yX, long yY, long ySizeX, long ySizeY){
  if(camera==NULL) {
    dc1394_log_error("Camera is not initialised");
    return -1;
  }

  err = dc1394_format7_set_roi(camera, video_mode,
			       DC1394_COLOR_CODING_MONO16,
			       DC1394_USE_MAX_AVAIL, // use max packet size
			       yX, yY, // left, top
			       ySizeX, ySizeY);  // width, height
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not define ROI");

  return 0;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
  fitsfile *fptr;
  long fpixel=1, nelements, naxes[3];
  dc1394camera_t *camera;
  int grab_n_frames;
  struct timeval start_time, end_time;
  time_t start_sec, end_sec;
  suseconds_t start_usec, end_usec;
  float elapsed_time, fps;
  int i, status;
  unsigned int min_bytes, max_bytes, max_height, max_width;
  unsigned int actual_bytes;
  uint64_t total_bytes = 0;
  unsigned int width, height;
  dc1394video_frame_t *frame=NULL;
  dc1394_t * d;
  dc1394camera_list_t * list;
  dc1394error_t err;
  char *filename;
  
  grab_n_frames = atoi(argv[1]);
  filename = argv[2];
  
  width = 320;
  height = 240;
  naxes[0] = width;
  naxes[1] = height;
  naxes[2] = grab_n_frames;
  
  nelements = naxes[0]*naxes[1]*naxes[2];
  
  stderr = freopen("grab_cube.log", "w", stderr);
  
  d = dc1394_new ();
  if (!d)
    return 1;
  err=dc1394_camera_enumerate (d, &list);
  DC1394_ERR_RTN(err,"Failed to enumerate cameras");
  
  if (list->num == 0) {
    dc1394_log_error("No cameras found");
    return 1;
  }
  
  camera = dc1394_camera_new (d, list->ids[0].guid);
  if (!camera) {
    dc1394_log_error("Failed to initialize camera with guid %"PRIx64,
                     list->ids[0].guid);
    return 1;
  }
  dc1394_camera_free_list (list);
  
  printf("Using camera with GUID %"PRIx64"\n", camera->guid);
  
  /*-----------------------------------------------------------------------
   *  setup capture for format 7
   *-----------------------------------------------------------------------*/
  // err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
  // DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot operate at 1394B");
  
  // libdc1394 doesn't work well with firewire800 yet so set to legacy 400 mode
  dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
  
  // configure camera for format7
  err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot choose format7_0");
  printf ("I: video mode is format7_0\n");
  
  err = dc1394_format7_get_max_image_size (camera, DC1394_VIDEO_MODE_FORMAT7_1, 
                                           &max_width, &max_height);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get max image size for format7_0");
  printf ("I: max image size is: height = %d, width = %d\n", max_height, max_width);
  printf ("I: current image size is: height = %d, width = %d\n", height, width);
  
  err = dc1394_format7_set_roi (camera, 
                                DC1394_VIDEO_MODE_FORMAT7_1, 
                                DC1394_COLOR_CODING_MONO16, // not sure why RAW8/16 don't work
                                DC1394_USE_MAX_AVAIL, 
                                0, 0, // left, top
                                width, height); // width, height
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set roi");
  printf ("I: roi is (0, 0) - (%d, %d)\n", width, height);
  
  // set the frame rate to absolute value in frames/sec
  err = dc1394_feature_set_mode(camera, DC1394_FEATURE_FRAME_RATE, DC1394_FEATURE_MODE_MANUAL);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to manual");
  err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_FRAME_RATE, DC1394_TRUE);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to absolute mode");
  err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_FRAME_RATE, 330.0);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate");
  printf("I: framerate is %f fps\n", 330.0);
  
  // set the shutter speed to absolute value in seconds 
  err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to manual");
  err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_SHUTTER, DC1394_TRUE);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to absolute mode");
  err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_SHUTTER, 3.0e-3);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter");
  printf("I: exptime is %f s\n", 3.0e-3);
  
  // set gain manually.  use relative value here in range 48 to 730. 
  err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain to manual");
  err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 400);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain");
  printf ("I: gain is %d\n", 400);
  
  // set brightness manually.  use relative value in range 0 to 1023.
  err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness to manual");
  err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 100);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness");
  printf ("I: brightness is %d\n", 100);

  err = dc1394_format7_get_total_bytes (camera, DC1394_VIDEO_MODE_FORMAT7_1, &total_bytes);
  DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get total bytes");
  printf ("I: total bytes is %"PRIu64" before SFF enabled\n", total_bytes);
  
  err=dc1394_capture_setup(camera, 16, DC1394_CAPTURE_FLAGS_DEFAULT);
  DC1394_ERR_CLN_RTN(err, dc1394_camera_free(camera), "Error capturing");
  
  /*-----------------------------------------------------------------------
   *  print allowed and used packet size
   *-----------------------------------------------------------------------*/
  err=dc1394_format7_get_packet_parameters(camera, DC1394_VIDEO_MODE_FORMAT7_1, &min_bytes, &max_bytes);
  
  DC1394_ERR_RTN(err,"Packet para inq error");
  printf( "camera reports allowed packet size from %d - %d bytes\n", min_bytes, max_bytes);
  
  err=dc1394_format7_get_packet_size(camera, DC1394_VIDEO_MODE_FORMAT7_1, &actual_bytes);
  DC1394_ERR_RTN(err,"dc1394_format7_get_packet_size error");
  printf( "camera reports actual packet size = %d bytes\n", actual_bytes);
  
  err=dc1394_format7_get_total_bytes(camera, DC1394_VIDEO_MODE_FORMAT7_1, &total_bytes);
  DC1394_ERR_RTN(err,"dc1394_query_format7_total_bytes error");
  printf( "camera reports total bytes per frame = %"PRId64" bytes\n",
         total_bytes);
  
  /*-----------------------------------------------------------------------
   *  have the camera start sending us data
   *-----------------------------------------------------------------------*/
  err=dc1394_video_set_transmission(camera,DC1394_ON);
  if (err!=DC1394_SUCCESS) {
    dc1394_log_error("unable to start camera iso transmission");
    dc1394_capture_stop(camera);
    dc1394_camera_free(camera);
    exit(1);
  }
  
  // set up FITS image and capture
  fits_create_file(&fptr, filename, &status);
  dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1, &width, &height);
  fits_create_img(fptr, USHORT_IMG, 3, naxes, &status);
  
  /*-----------------------------------------------------------------------
   *  capture frames and measure the time for this operation
   *-----------------------------------------------------------------------*/
  gettimeofday(&start_time, NULL);
  
  printf("Start capture:\n");
  
  for( i = 0; i < grab_n_frames; ++i) {
    /*-----------------------------------------------------------------------
     *  capture one frame
     *-----------------------------------------------------------------------*/
    err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
    if (err!=DC1394_SUCCESS) {
      dc1394_log_error("unable to capture");
      dc1394_capture_stop(camera);
      dc1394_camera_free(camera);
      exit(1);
    }
    
    // attempt to preallocate image array and write to memory before dumping to disk.
    // turns out to be slow due to large size of images. cfitsio buffering is far
    // more efficient.
    
    //memcpy(im_buffer+2*i*naxes[0]*naxes[1], 
    //frame->image-1, 
    //naxes[0]*naxes[1]*sizeof(short));
    
    // just writing each frame to the FITS file goes pretty fast
    fits_write_img(fptr, 
                   TUSHORT, 
                   fpixel+i*naxes[0]*naxes[1], 
                   naxes[0]*naxes[1], 
                   frame->image-1, 
                   &status);
    
    // release buffer
    dc1394_capture_enqueue(camera,frame);
  }
  
  gettimeofday(&end_time, NULL);
  printf("End capture.\n");
  
  /*-----------------------------------------------------------------------
   *  stop data transmission
   *-----------------------------------------------------------------------*/
  start_sec = start_time.tv_sec;
  start_usec = start_time.tv_usec;
  end_sec = end_time.tv_sec;
  end_usec = end_time.tv_usec;
  
  elapsed_time = (float)((end_sec + 1.0e-6*end_usec) - (start_sec + 1.0e-6*start_usec));
  fps = grab_n_frames/elapsed_time;
  printf("Elapsed time = %g seconds.\n", elapsed_time);
  printf("Framerate = %g fps.\n", fps);
  
  err=dc1394_video_set_transmission(camera,DC1394_OFF);
  DC1394_ERR_RTN(err,"couldn't stop the camera?");
  
  /*-----------------------------------------------------------------------
   *  save FITS image to disk
   *-----------------------------------------------------------------------*/
  //fits_write_img(fptr, TUSHORT, fpixel, naxes[0]*naxes[1]*naxes[2], im_buffer, &status);
  fits_close_file(fptr, &status);
  fits_report_error(stderr, status);
  //free(im_buffer);
  
  printf("wrote: %s\n", filename);
  printf("Image is %d bits/pixel.\n", frame->data_depth);
  
  /*-----------------------------------------------------------------------
   *  close camera, cleanup
   *-----------------------------------------------------------------------*/
  dc1394_capture_stop(camera);
  dc1394_video_set_transmission(camera, DC1394_OFF);
  dc1394_camera_free(camera);
  dc1394_free (d);
  return 0;
}
Esempio n. 6
0
//=============================================================================
// setStereoVideoCapture()
//
// Given that the camera handle is a stereo camera, query the camera for 
// stereo specific information about this camera and populate the 
// PGRStereoCamera_t handle structure
//
// note: currently always allocated maximum framerate
dc1394error_t
setStereoVideoCapture( PGRStereoCamera_t* stereoCamera )
{
   dc1394error_t 	err;
   dc1394color_coding_t	coding;

   switch( stereoCamera->model )
   {
      case BUMBLEBEE:
	 dc1394video_mode_t 	videoMode;
	 dc1394framerate_t 	fps;

	 // note: both B&W and Bayer Bumblebees transmit in mono mode
	 if ( stereoCamera->nCols == 640 )
	 {
	    // lo res 
            printf("capture mode: DC1394_VIDEO_MODE_640x480_MONO16 ");
            printf("capture mode: %d\n", DC1394_VIDEO_MODE_640x480_MONO16);
	    videoMode 	= DC1394_VIDEO_MODE_640x480_MONO16;
	    fps		= DC1394_FRAMERATE_30;
	 }
	 else
	 {
            printf("capture mode: DC1394_VIDEO_MODE_1024x768_MONO16 ");
            printf("capture mode: %d\n", DC1394_VIDEO_MODE_1024x768_MONO16);
	    // assume hi res 
	    videoMode 	= DC1394_VIDEO_MODE_1024x768_MONO16;
	    fps		= DC1394_FRAMERATE_15;
	 }
	 
	 // make the calls to set up the capture mode
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_400 );
	 dc1394_video_set_mode(      stereoCamera->camera, videoMode );
	 dc1394_video_set_framerate( stereoCamera->camera, fps );
	 err = dc1394_capture_setup( stereoCamera->camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      case BUMBLEBEE2:
	 // Bumblebee2 transmits stereo images in Format 7

	 // load the factory defaults - this is auto-everything
	 err = dc1394_memory_load( stereoCamera->camera, 0 );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't load default memory channel\n" );
	    return err;
	 }

	 // set 16-bit transmission to be PGR-default little endian mode
	 err = setEndian( stereoCamera->camera, false );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't set Bumblebee2 into little-endian mode\n" );
	    return err;
	 }

	 // color cameras transmit in "RAW16", mono cameras in "MONO16"
	 coding	= DC1394_COLOR_CODING_MONO16;
	 if ( stereoCamera->bColor )
	    coding = DC1394_COLOR_CODING_RAW16;
	 
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_400 );
	 dc1394_video_set_mode( stereoCamera->camera, DC1394_VIDEO_MODE_FORMAT7_3 );

	 err = dc1394_format7_set_roi( stereoCamera->camera,
				       DC1394_VIDEO_MODE_FORMAT7_3,
				       coding,
                                       // bytes per packet - sets frame rate
				       DC1394_USE_MAX_AVAIL, 
				       0, 
				       0,
				       stereoCamera->nCols,
				       stereoCamera->nRows );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee2 capture\n" );
	    return err;
	 }

	 err = dc1394_capture_setup( stereoCamera->camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      case BUMBLEBEEXB3:
	 // Bumblebee3 transmits stereo images in Format 7

	 // load the factory defaults - this is auto-everything
	 err = dc1394_memory_load( stereoCamera->camera, 0 );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't load default memory channel\n" );
	    return err;
	 }


	 if ( stereoCamera->nBytesPerPixel == 2 )
	 {
	    // run in 2 camera mode

	    // NOTE: this code will always only set up the wide-baseline pair
	    // To change to the inner baseline pair you need to set the PAN
	    // register to 1.
	    // PAN = 0 is the wide baseline pair which is set by default.
	    // To change to all 3 images being transmitted you need to change
	    // modes to "coding	= DC1394_COLOR_CODING_RGB8;"
	    //

	    // set 16-bit transmission to be PGR-default little endian mode
	    err = setEndian( stereoCamera->camera, false );
	    if ( err != DC1394_SUCCESS ) 
	    {
	       fprintf( stderr, "Can't set Bumblebee2 into little-endian mode\n" );
	       return err;
	    }

	    // color cameras transmit in "RAW16", mono cameras in "MONO16"
	    coding	= DC1394_COLOR_CODING_MONO16;
	    if ( stereoCamera->bColor )
	       coding = DC1394_COLOR_CODING_RAW16;
	 }
	 else
	 {
	    // 3 camera mode transmits in RGB8
	    coding	= DC1394_COLOR_CODING_RGB8;
	 }

	 // assume the XB is plugged into a 1394B network
	 // XB3 can work with a 1394A bus but code changes will be required
	 dc1394_video_set_operation_mode( stereoCamera->camera, DC1394_OPERATION_MODE_1394B );
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_800 );
	 dc1394_video_set_mode( stereoCamera->camera, DC1394_VIDEO_MODE_FORMAT7_3 );
	 err = dc1394_format7_set_roi( stereoCamera->camera,
				       DC1394_VIDEO_MODE_FORMAT7_3,
				       coding,
                                       // bytes per packet - sets frame rate
				       DC1394_USE_MAX_AVAIL, 
				       0, 
				       0,
				       stereoCamera->nCols,
				       stereoCamera->nRows );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee XB3 capture\n" );
	    return err;
	 }

	 err = dc1394_capture_setup( stereoCamera->camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      default:
	 fprintf( stderr, 
		  "setStereoVideoCapture() - \n"
		  "\tThis camera is not a supported stereo camera!\n" );
	 return DC1394_FAILURE;
   }

   // get the bayer tile info so we will know how to color process
   // this mode
   err = getBayerTile( stereoCamera->camera,
		       &stereoCamera->bayerTile );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Could not query the Bayer Tile Register!\n" );
      return err;
   }

   return DC1394_SUCCESS;
}
Esempio n. 7
0
int main(int argc, char *argv[]) {
    fitsfile *fptr;
    long fpixel=1, nelements, naxes[2];
    dc1394camera_t *camera;
    int grab_n_frames;
    struct timeval start_time, end_time;
    int i, j, status;
    unsigned int max_height, max_width;
    uint64_t total_bytes = 0;
    unsigned int width, height;
    dc1394video_frame_t *frame=NULL;
    dc1394_t * d;
    dc1394camera_list_t * list;
    dc1394error_t err;
    char *filename;
    unsigned char *buffer;
    float *average;

    grab_n_frames = atoi(argv[1]);
    filename = argv[2];
    status = 0;
    width = 320;
    height = 240;
    naxes[0] = width;
    naxes[1] = height;
    nelements = naxes[0]*naxes[1];

    stderr = freopen("grab_cube.log", "w", stderr);

    d = dc1394_new();
    if (!d)
        return 1;
    err = dc1394_camera_enumerate(d, &list);
    DC1394_ERR_RTN(err, "Failed to enumerate cameras.");

    if (list->num == 0) {
        dc1394_log_error("No cameras found.");
        return 1;
    }

    camera = dc1394_camera_new (d, list->ids[0].guid);
    if (!camera) {
        dc1394_log_error("Failed to initialize camera with guid %"PRIx64,
                         list->ids[0].guid);
        return 1;
    }
    dc1394_camera_free_list(list);

    printf("Using camera with GUID %"PRIx64"\n", camera->guid);

    /*-----------------------------------------------------------------------
     *  setup capture for format 7
     *-----------------------------------------------------------------------*/
    // err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
    // DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot operate at 1394B");

    // libdc1394 doesn't work well with firewire800 yet so set to legacy 400 mode
    dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);

    // configure camera for format7
    err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot choose format7_0");

    err = dc1394_format7_get_max_image_size (camera, DC1394_VIDEO_MODE_FORMAT7_1,
            &max_width, &max_height);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get max image size for format7_0");

    err = dc1394_format7_set_roi (camera,
                                  DC1394_VIDEO_MODE_FORMAT7_1,
                                  DC1394_COLOR_CODING_MONO8, // not sure why RAW8/16 don't work
                                  DC1394_USE_MAX_AVAIL,
                                  0, 0, // left, top
                                  width, height); // width, height
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set roi");

    // set the frame rate to absolute value in frames/sec
    err = dc1394_feature_set_mode(camera, DC1394_FEATURE_FRAME_RATE, DC1394_FEATURE_MODE_MANUAL);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to manual");
    err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_FRAME_RATE, DC1394_TRUE);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate to absolute mode");
    err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_FRAME_RATE, 100.0);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set framerate");

    // set the shutter speed to absolute value in seconds
    err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to manual");
    err = dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_SHUTTER, DC1394_TRUE);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter to absolute mode");
    err = dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_SHUTTER, 1.0e-2);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set shutter");

    // set gain manually.  use relative value here in range 48 to 730.
    err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain to manual");
    err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 200);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set gain");

    // set brightness manually.  use relative value in range 0 to 1023.
    err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness to manual");
    err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 50);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot set brightness");

    err = dc1394_format7_get_total_bytes (camera, DC1394_VIDEO_MODE_FORMAT7_1, &total_bytes);
    DC1394_ERR_CLN_RTN(err,dc1394_camera_free (camera),"cannot get total bytes");

    // err = dc1394_feature_set_value (camera, DC1394_FEATURE_GAIN, 24);
    //DC1394_ERR_CLN_RTN(err, dc1394_camera_free(camera), "Error setting gain");

    err = dc1394_capture_setup(camera, 16, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_ERR_CLN_RTN(err, dc1394_camera_free(camera), "Error capturing");

    /*-----------------------------------------------------------------------
     *  have the camera start sending us data
     *-----------------------------------------------------------------------*/
    err = dc1394_video_set_transmission(camera, DC1394_ON);
    if (err != DC1394_SUCCESS) {
        dc1394_log_error("unable to start camera iso transmission");
        dc1394_capture_stop(camera);
        dc1394_camera_free(camera);
        exit(1);
    }

    /* allocate the buffers */
    if (!(buffer = malloc(nelements*sizeof(char)))) {
        printf("Couldn't Allocate Image Buffer\n");
        exit(-1);
    }

    if (!(average = calloc(nelements, sizeof(float)))) {
        printf("Couldn't Allocate Average Image Buffer\n");
        exit(-1);
    }

    // set up FITS image and capture
    fits_create_file(&fptr, filename, &status);
    dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_1, &width, &height);
    fits_create_img(fptr, FLOAT_IMG, 2, naxes, &status);

    /*-----------------------------------------------------------------------
     *  capture frames and measure the time for this operation
     *-----------------------------------------------------------------------*/
    gettimeofday(&start_time, NULL);

    printf("Start capture:\n");

    for (i=0; i<grab_n_frames; ++i) {
        /*-----------------------------------------------------------------------
         *  capture one frame
         *-----------------------------------------------------------------------*/
        err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("unable to capture");
            dc1394_capture_stop(camera);
            dc1394_camera_free(camera);
            exit(1);
        }

        memcpy(buffer, frame->image, nelements*sizeof(char));

        // release buffer
        dc1394_capture_enqueue(camera,frame);

        for (j=0; j<nelements; j++) {
            average[j] += (1.0/grab_n_frames)*(buffer[j]);
        }

    }

    gettimeofday(&end_time, NULL);
    printf("End capture.\n");

    /*-----------------------------------------------------------------------
     *  stop data transmission
     *-----------------------------------------------------------------------*/

    err = dc1394_video_set_transmission(camera, DC1394_OFF);
    DC1394_ERR_RTN(err,"couldn't stop the camera?");

    /*-----------------------------------------------------------------------
     *  save FITS image to disk
     *-----------------------------------------------------------------------*/
    fits_write_img(fptr, TFLOAT, fpixel, naxes[0]*naxes[1], average, &status);
    fits_close_file(fptr, &status);
    fits_report_error(stderr, status);
    free(buffer);
    free(average);

    printf("wrote: %s\n", filename);
    printf("Readout is %d bits/pixel.\n", frame->data_depth);

    /*-----------------------------------------------------------------------
     *  close camera, cleanup
     *-----------------------------------------------------------------------*/
    dc1394_capture_stop(camera);
    dc1394_video_set_transmission(camera, DC1394_OFF);
    dc1394_camera_free(camera);
    dc1394_free(d);
    return 0;
}
//--------------------------------------------------------------------
bool ofxVideoGrabberPtgrey::initGrabber(int w, int h, bool setUseTexture){
    width = w;
    height = h;
    bUseTexture = setUseTexture;
	
	// In format_7 the framerate is set by setting the packet_size
	// this is used in dc1394_format7_set_roi()
	// The following formula is from the libdc1394 faq
	// http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/faq/#How_can_I_work_out_the_packet_size_for_a_wanted_frame_rate
	float bus_period = 0.000125;  // for firewire 400
	int frame_rate = 60;
	int depth = 3;
	int num_packets = (int)(1.0/(bus_period*frame_rate) + 0.5);
	//packet_size =  (width*height*depth + (num_packets*8) - 1)/(num_packets*8);
	packet_size = DC1394_USE_MAX_AVAIL;	

    //first choose a device to use
    if( bChooseDevice ) {
        bool bFound = false;
        for (uint32_t index = 0; index < deviceList->num; index++) {
            if (deviceList->ids[index].unit == deviceID) {
                bFound = true;
                deviceID = deviceList->ids[index].guid;
            }
        }
        if (!bFound) {
            printf("initGrabber warning: Device ID for unit %x not found, using first device\n", deviceID);
            deviceID = deviceList->ids[0].guid;
        }
    } else if(deviceList->num > 0) {
        deviceID = deviceList->ids[0].guid;
    } else {
        ofLog(OF_LOG_ERROR, "in initGrabber, No cameras found");
    }


    camera = dc1394_camera_new(driver, deviceID);
	if (!camera) {
		ofLog(OF_LOG_ERROR, "Failed to initialize camera with guid %x", deviceID);
		return 1;
	}

    /*-----------------------------------------------------------------------
     *  setup capture
     *-----------------------------------------------------------------------*/

    err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
    if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set iso speed"); }
	
	err = dc1394_video_set_mode( camera, video_mode );
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 video mode"); }
	
	err = dc1394_format7_set_color_coding(camera, video_mode, color_coding);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 color coding"); }
	
	err = dc1394_format7_set_packet_size(camera, video_mode, packet_size);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 packet_size"); }
	
	err = dc1394_format7_set_roi(camera, video_mode, color_coding, packet_size, 0,0, width,height);
	if( err != DC1394_SUCCESS ) {
		ofLog(OF_LOG_ERROR, "failed to set format 7");
	}

    //err = dc1394_video_set_framerate(camera, framerate);
	//DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate");

    err = dc1394_capture_setup(camera,2, DC1394_CAPTURE_FLAGS_DEFAULT);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to setup dma capturing"); }


	/*-----------------------------------------------------------------------
     *  set camera's features
     *-----------------------------------------------------------------------*/

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 200);  //1-255

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_EXPOSURE, 62);  //7-62

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, 60);  //1-263, 64 being the max for 60fps

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 50);  //16-64

	//err = dc1394_feature_set_mode(camera, DC1394_FEATURE_PAN, DC1394_FEATURE_MODE_MANUAL);
	//err = dc1394_feature_set_value(camera, DC1394_FEATURE_PAN, 56);


    /*-----------------------------------------------------------------------
     *  report camera's features
     *-----------------------------------------------------------------------*/
    err=dc1394_feature_get_all(camera,&features);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get feature set");
    }
    else {
        dc1394_feature_print_all(&features, stdout);
    }

    /*-----------------------------------------------------------------------
     *  have the camera start sending us data
     *-----------------------------------------------------------------------*/
    err=dc1394_video_set_transmission(camera, DC1394_ON);
    //DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission");

	//create pixel buffer
    pixels	= new unsigned char[width * height * 3];

    //create texture
    if (bUseTexture) {
        tex.allocate(width,height,GL_LUMINANCE);
        memset(pixels, 0, width*height);
        tex.loadData(pixels, width, height, GL_LUMINANCE);
    }

}
Esempio n. 9
0
int main(int argc, char *argv[])
{
    double lapse=0;
    double fps;
    double ntime=0, ptime=0, tmp;
    int index;
    dc1394video_frame_t *frame;
    dc1394error_t err;
    GLuint texture;
    TimeLapse_t timer;
    int cam_id=0;

    if ( argc!=1 && argc!=2) {
        fprintf(stderr,"Usage:\n\tdc1394_iso <optional camera_ID>\n");
        fprintf(stderr,"\t\tDefault values for histogram are min=%.0f, max=%.0f and %d bins\n\n",DEF_BIN_MIN, DEF_BIN_MAX, (int)DEF_BIN_N);
        exit(0);
    }

    signal(SIGINT, DisplayStatsAndExit);

    if (argc==2)
        cam_id=atoi(argv[1]);

    bin_n=DEF_BIN_N;
    bin_max=DEF_BIN_MAX;
    bin_min=DEF_BIN_MIN;
    bins = calloc(bin_n,sizeof(unsigned int));

    // init 1394
    d = dc1394_new();
    if (!d) return 1;
    // find cameras
    dc1394camera_list_t * list;
    err=dc1394_camera_enumerate (d, &list);
    DC1394_ERR_RTN(err,"Failed to enumerate cameras");
    if (list->num == 0) {
        fprintf(stderr,"No cameras found\n");
        return 1;
    }
    else {
        if (list->num<cam_id+1) {
            fprintf(stderr,"Not enough cameras found for id\n");
            return 1;
        }
    }
    // use selected camera
    camera = dc1394_camera_new (d, list->ids[cam_id].guid);
    if (!camera) {
        dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[cam_id].guid);
        return 1;
    }
    dc1394_camera_free_list (list);
    // setup video format
    dc1394_video_set_transmission(camera, DC1394_OFF); // just in case
    dc1394_video_set_mode(camera, MODE);
    dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
    err=dc1394_format7_set_roi(camera, MODE, DC1394_COLOR_CODING_MONO8, PKT, 0, 0, SX, SY);
    if (err!=DC1394_SUCCESS) {
        fprintf(stderr,"Could not set ROI!\n");
        return 0;
    }
    // setup catpure
    err=dc1394_capture_setup(camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT);
    if (err!=DC1394_SUCCESS) {
        fprintf(stderr,"Could not set capture!\n");
        return 0;
    }

    fps_min=9e6;
    fps_max=0;

    fprintf(stderr,"\t\t\t\t------------- FPS --------------        \n");
    fprintf(stderr,"Time:\t\tFrames:\t\tInst:\tMin:\tMax:\tAvg:\n");
    fprintf(stderr,"Stabilizing...\r");
    unsigned int stabilized=0;

    video=SDL_Start_GL(SX, SY);

    // start image transmission
    dc1394_video_set_transmission(camera, DC1394_ON);

    ResetTimer(&timer);

    // ----- ready to roll on all images! -----
    int quit = 0;
    while (!quit) {
        // capture image
        err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);/* Capture */
        DC1394_ERR_RTN(err,"Problem getting an image");

        // display image
        glGenTextures( 1, &texture);
        glBindTexture( GL_TEXTURE_2D, texture);
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
        glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE8, SX, SY, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, frame->image );

        // return buffer
        dc1394_capture_enqueue(camera, frame);

        glBegin( GL_QUADS );
        {
            glTexCoord2f(0, 0);
            glVertex3f(0, 0, 1 );
            glTexCoord2f(0, 1);
            glVertex3f(0, SY, 1 );
            glTexCoord2f(1, 1);
            glVertex3f(SX, SY, 1 );
            glTexCoord2f(1, 0);
            glVertex3f(SX, 0, 1 );
        }
        glEnd();
        SDL_GL_SwapBuffers();
        glDeleteTextures(1, &texture);

        if (ntime>0.1) // if ntime is valid...
            ptime=ntime;
        ntime=(double)frame->timestamp/1000000.0;

        // display the framerate
        nframes++;
        fps=1.0/(ntime-ptime+1e-20);
        tmp=GetTimeLapseSec(&timer);
        lapse+=tmp;
        if (lapse>STABILIZING_TIME && stabilized==0) {
            stabilized=1;
            lapse=tmp;
            nframes=1;
            fprintf(stderr,"                                       \r");
        }

        if (stabilized>0) {

            if (nframes>1) {
                fprintf(stderr,"%9.3f\t%7d   \t%-3.2f \t%3.2f \t%3.2f \t%3.3f     \r", lapse, nframes, fps, fps_min, fps_max, ((float)nframes)/(lapse+1e-10));
            }
            index=(int)((fps-bin_min)/((double)(bin_max-bin_min)/(double)bin_n));

            if (index>bin_n-1)
                index=bin_n-1;
            if (index<0)
                index=0;
            bins[index]++;
            if (fps_min>fps)
                fps_min=fps;
            if (fps_max<fps)
                fps_max=fps;
        }

        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_QUIT:
                quit = 1;
                break;
            }
        }
    } // --------------- END OF BIG IMAGE LOOP -------------------

    DisplayStatsAndExit(0);

    return 0;
}
Esempio n. 10
0
int main(int argc, const char * argv[]) {

    dc1394_t *d;
    dc1394camera_list_t *list;
    dc1394error_t err;
    dc1394camera_t *camera;
    dc1394format7modeset_t modeset;
    dc1394video_frame_t *frame;
    FILE* imagefile;
    char filename[256];
    int i = 0;

    d = dc1394_new();
    if (!d) {
        return 1;
    }

    err = dc1394_camera_enumerate(d, &list);
    DC1394_ERR_RTN(err, "Failed to enumerate cameras");
    if (list->num == 0) {
        dc1394_log_error("No cameras found");
        dc1394_free(d);
        return 1;
    }
    printf("Detected %d cameras\n", list->num);

    // Assume that Ladybug 5 is detected as camera #0
    camera = dc1394_camera_new(d, list->ids[0].guid);
    if (!camera) {
        dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid);
        dc1394_free(d);
    }
    dc1394_camera_free_list(list);
    printf("Using camera %s %s\n", camera->vendor, camera->model);

    // Report camera info
    err = dc1394_camera_print_info(camera, stdout);
    DC1394_ERR_RTN(err, "Could not print camera info");


    // Setup video mode, etc...
    err = dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
    DC1394_ERR_RTN(err, "Could not set B mode");
    err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_MAX);
    DC1394_ERR_RTN(err, "Could not set max speed");
    err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0);
    DC1394_ERR_RTN(err, "Could not set DC1394_VIDEO_MODE_FORMAT7_0");

    // Get format7 mode info
    err = dc1394_format7_get_modeset(camera, &modeset);
    DC1394_ERR_RTN(err, "Could not get format 7 mode info\n");
    print_format7_info(&modeset);


    // Set format 7 roi
    err = dc1394_format7_set_roi(camera,
                                 DC1394_VIDEO_MODE_FORMAT7_0,
                                 modeset.mode[0].color_coding,
                                 modeset.mode[0].max_packet_size,
                                 modeset.mode[0].pos_x,
                                 modeset.mode[0].pos_y,
                                 modeset.mode[0].max_size_x,
                                 modeset.mode[0].max_size_y);
    DC1394_ERR_RTN(err, "Could not set max ROI");

    // Set capture
    err = dc1394_capture_setup(camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_ERR_RTN(err, "Could not setup capture");
    err = dc1394_video_set_transmission(camera, DC1394_ON);
    DC1394_ERR_RTN(err, "Could not start transmission");

    while (i < NFRAMES) {
        // Capture image
        printf("Capturing image %d\n", i);
        err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
        DC1394_ERR_RTN(err, "Could not dequeue a frame");
        
        // Do something with the image
        print_frame_info(frame);

        // Save the image
        sprintf(filename, "%05d.pgm",i);
        imagefile = fopen(filename, "wb");
        if ( imagefile == NULL ) {
            printf("Could not save image\n");
            continue;
        }
        fprintf(imagefile, "P5\n%u %u 255\n", frame->size[0], frame->size[1]);
        fwrite(frame->image, 1, frame->image_bytes, imagefile);
        fclose(imagefile);
        printf("Saved image %s\n", filename);

        err = dc1394_capture_enqueue(camera, frame);
        DC1394_ERR_RTN(err, "Could enqueue a frame");

        i++;
    }

    dc1394_camera_free(camera);
    dc1394_free(d);
    return 0;
}