コード例 #1
0
ファイル: ofxLibdc.cpp プロジェクト: BluntBlade/eyewriter
void ofxLibdc::setTransmit(bool transmit) {
	dc1394switch_t cur, target;
	dc1394_video_get_transmission(camera, &cur);
	target = transmit ? DC1394_ON : DC1394_OFF;
	if(cur != target)
		dc1394_video_set_transmission(camera, target);
}
コード例 #2
0
ファイル: firewire.cpp プロジェクト: WooYoungChoi/Pangolin
void FirewireVideo::init_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    dc1394framerate_t framerate
    ) {

    if(video_mode>=DC1394_VIDEO_MODE_FORMAT7_0)
      throw VideoException("format7 modes need to be initialized through the constructor that allows for specifying the roi");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }


    cout << "Using camera with GUID " << camera->guid << endl;

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

    if( iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
            throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set video mode");

    err=dc1394_video_set_framerate(camera, framerate);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set framerate");

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    //-----------------------------------------------------------------------
    //  initialise width and height from mode
    //-----------------------------------------------------------------------
    dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height);

    Start();
}
コード例 #3
0
ファイル: gstdc1394.c プロジェクト: asrashley/gst-plugins-bad
gboolean
gst_dc1394_change_camera_transmission (GstDc1394 * src, gboolean on)
{
    dc1394switch_t status = DC1394_OFF;
    dc1394error_t err = DC1394_FAILURE;
    gint i = 0;

    g_return_val_if_fail (src->camera, FALSE);

    if (on) {

        status = dc1394_video_set_transmission (src->camera, DC1394_ON);

        i = 0;
        while (status == DC1394_OFF && i++ < 5) {
            g_usleep (50000);
            if (dc1394_video_get_transmission (src->camera,
                                               &status) != DC1394_SUCCESS) {
                if (status == DC1394_OFF) {
                    GST_LOG_OBJECT (src, "camera is still off , retrying");
                }
            }
        }

        if (i == 5) {
            GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                               ("Camera doesn't seem to want to turn on!"),
                               ("Camera doesn't seem to want to turn on!"));
            return FALSE;
        }

        GST_LOG_OBJECT (src, "got transmision status ON");

    } else {

        if (dc1394_video_set_transmission (src->camera,
                                           DC1394_OFF) != DC1394_SUCCESS) {
            GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Unable to stop transmision"),
                               ("Unable to stop transmision"));
            return FALSE;
        }

        GST_LOG_OBJECT (src, "Stopping capture");

        err = dc1394_capture_stop (src->camera);
        if (err > 0) {
            GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Capture stop error : %d ",
                               err), ("Capture stop error : %d ", err));
            return FALSE;
        } else {
            GST_LOG_OBJECT (src, "Capture stoped successfully");
        }
    }

    return TRUE;
}
コード例 #4
0
ファイル: FWCamera.cpp プロジェクト: lynxis/libavg
void FWCamera::startCapture()
{
#ifdef AVG_ENABLE_1394_2
    int err = dc1394_video_set_transmission(m_pCamera, DC1394_ON);
    AVG_ASSERT(err == DC1394_SUCCESS);

    dc1394switch_t status = DC1394_OFF;

    int i = 0;
    while (status == DC1394_OFF && i++ < 5) {
        usleep(50000);
        err = dc1394_video_get_transmission(m_pCamera, &status);
        AVG_ASSERT(err == DC1394_SUCCESS);
    }

    if (i == 5) {
        AVG_ASSERT(false);
    }
    // Default to turning off any camera sharpness manipulation.
    setFeature(CAM_FEATURE_SHARPNESS, 0);

    // Turn off possible auto exposure.
    dc1394_feature_set_mode(m_pCamera, DC1394_FEATURE_EXPOSURE, 
            DC1394_FEATURE_MODE_MANUAL);
    dc1394_feature_set_power(m_pCamera, DC1394_FEATURE_EXPOSURE, DC1394_OFF);

    AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO, "Firewire camera opened.");
    for (FeatureMap::iterator it=m_Features.begin(); it != m_Features.end(); it++) {
        setFeature(it->first, it->second, true);
    }
    setWhitebalance(m_WhitebalanceU, m_WhitebalanceV, true);
    
    if (getCamPF() == BAYER8) {
        if (strcmp(m_pCamera->model, "DFx 31BF03") == 0) {
            AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
                    "Applying bayer pattern fixup for IS DFx31BF03 camera");
            setCamPF(BAYER8_GRBG);
        } else if (strcmp(m_pCamera->vendor, "Point Grey Research") == 0) {
            AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
                    "Applying bayer pattern fixup for PointGrey cameras");
            enablePtGreyBayer();
        }
    }
#endif
}
コード例 #5
0
void Libdc1394Grabber::cleanupCamera()
{
    closeCamera = true;
    ofxThread::stopThread();
    ofLog(OF_LOG_VERBOSE,"Stopped capture thread.");

    //this sleep seems necessary, at least on OSX, to avoid an occasional hang on exit
    ofSleepMillis(150);

    dc1394switch_t is_iso_on = DC1394_OFF;
    if(camera) {
        if (dc1394_video_get_transmission(camera, &is_iso_on)!=DC1394_SUCCESS) {
            is_iso_on = DC1394_ON; // try to shut ISO anyway
        }
        if (is_iso_on > DC1394_OFF) {
            if (dc1394_video_set_transmission(camera, DC1394_OFF)!=DC1394_SUCCESS) {
                ofLog(OF_LOG_ERROR, "Could not stop ISO transmission!");
            }
        }
    }
    ofLog(OF_LOG_VERBOSE,"Stopped ISO transmission.");

    /* cleanup and exit */
    if(cameraList)
        dc1394_camera_free_list (cameraList);
    if(camera) {
        dc1394_capture_stop(camera);
        dc1394_camera_free (camera);
        camera = NULL;
    }
    ofLog(OF_LOG_VERBOSE,"Stopped camera.");

    if(dc1394) {
        dc1394_free (dc1394);
        dc1394 = NULL;
    }

    if(pixels) {
        delete [] pixels;
        pixels = NULL;
    }

    printf("Closed!\n");
}
コード例 #6
0
ファイル: capture.c プロジェクト: nagyistoce/openvgr
static void s_flush_buffer(capture_t *cap, const int index)
{
  dc1394camera_t *cam = cap->cameras[index];

  dc1394switch_t pwr = DC1394_OFF;
  dc1394video_frame_t *frame = NULL;

  dc1394_video_get_transmission(cam, &pwr);
  if (pwr == DC1394_ON) {
    dc1394_video_set_transmission(cam, DC1394_OFF);
  }

  while (dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_POLL, &frame), frame != NULL) {
    dc1394error_t err;

    err = dc1394_capture_enqueue(cam, frame);
    DC1394_ERR(err, "could not enqueue");
  }
}
コード例 #7
0
ファイル: pgr_stereocam.cpp プロジェクト: flame85/techx
//=============================================================================
// startTransmission()
//
// A helper function to wrap up the sleeps involved with starting transmission.
// This loop method was taken from the libdc1394-2 examples.
//
dc1394error_t
startTransmission( PGRStereoCamera_t* stereoCamera )
{
   dc1394error_t err;
   // have the camera start sending us data
   err = dc1394_video_set_transmission( stereoCamera->camera, DC1394_ON );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Unable to start camera iso transmission\n" );
      return err;
   }

   // printf( "Waiting for transmission... \n" );
   //  Sleep untill the camera has a transmission
   dc1394switch_t status = DC1394_OFF;

   for ( int i = 0; i <= 5; i++ )
   {
      usleep(50000);
      err = dc1394_video_get_transmission( stereoCamera->camera, &status );
      if ( err != DC1394_SUCCESS ) 
      {
	 fprintf( stderr, "Unable to get transmision status\n" );
	 return err;
      }
      if ( status != DC1394_OFF )
	 break;

      if( i == 5 ) 
      {
	 fprintf(stderr,"Camera doesn't seem to want to turn on!\n");
	 return DC1394_FAILURE;
      }
   }
   
   return DC1394_SUCCESS;
}
コード例 #8
0
ファイル: capture.c プロジェクト: robhemsley/libdc1394
dc1394error_t
dc1394_juju_capture_setup(platform_camera_t *craw, uint32_t num_dma_buffers,
        uint32_t flags)
{
    struct fw_cdev_create_iso_context create;
    struct fw_cdev_start_iso start_iso;
    dc1394error_t err;
    dc1394video_frame_t proto;
    int i, j, retval;
    dc1394camera_t * camera = craw->camera;

    if (flags & DC1394_CAPTURE_FLAGS_DEFAULT)
        flags = DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
            DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC;

    craw->flags = flags;

    // if capture is already set, abort
    if (craw->capture_is_set>0)
        return DC1394_CAPTURE_IS_RUNNING;

    // if auto iso is requested, stop ISO (if necessary)
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        dc1394switch_t is_iso_on;
        dc1394_video_get_transmission(camera, &is_iso_on);
        if (is_iso_on == DC1394_ON) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
        }
    }

    if (capture_basic_setup(camera, &proto) != DC1394_SUCCESS) {
        dc1394_log_error("basic setup failed");
        return DC1394_FAILURE;
    }

    if (flags & (DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
                DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)) {
        uint64_t channels_allowed = 0;
        unsigned int bandwidth_units = 0;
        int channel;
        if (flags & DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC)
            channels_allowed = 0xffff;
        if (flags & DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)
            dc1394_video_get_bandwidth_usage (camera, &bandwidth_units);
        err = juju_iso_allocate (craw, channels_allowed,
                bandwidth_units, &craw->capture_iso_resource);
        if (err == DC1394_SUCCESS) {
            channel = craw->capture_iso_resource->channel;
        } else if (err == DC1394_FUNCTION_NOT_SUPPORTED) {
            channel = craw->node_id & 0x3f;
            dc1394_log_warning ("iso allocation not available in this kernel, "
                    "using channel %d...", channel);
        } else {
            dc1394_log_error ("juju: Failed to allocate iso resources");
            return err;
        }

        if (dc1394_video_set_iso_channel (camera, channel) != DC1394_SUCCESS)
            return DC1394_NO_ISO_CHANNEL;
    }

    if (dc1394_video_get_iso_channel (camera, &craw->iso_channel)
            != DC1394_SUCCESS)
        return DC1394_FAILURE;
    dc1394_log_debug ("juju: Receiving from iso channel %d", craw->iso_channel);

    craw->iso_fd = open(craw->filename, O_RDWR);
    if (craw->iso_fd < 0) {
        dc1394_log_error("error opening file: %s", strerror (errno));
        return DC1394_FAILURE;
    }

    create.type = FW_CDEV_ISO_CONTEXT_RECEIVE;
    create.header_size = craw->header_size;
    create.channel = craw->iso_channel;
    create.speed = SCODE_400;
    err = DC1394_IOCTL_FAILURE;
    if (ioctl(craw->iso_fd, FW_CDEV_IOC_CREATE_ISO_CONTEXT, &create) < 0) {
        dc1394_log_error("failed to create iso context");
        goto error_fd;
    }

    craw->iso_handle = create.handle;

    craw->num_frames = num_dma_buffers;
    craw->current = -1;
    craw->buffer_size = proto.total_bytes * num_dma_buffers;
    craw->buffer =
        mmap(NULL, craw->buffer_size, PROT_READ | PROT_WRITE , MAP_SHARED, craw->iso_fd, 0);
    err = DC1394_IOCTL_FAILURE;
    if (craw->buffer == MAP_FAILED)
        goto error_fd;

    err = DC1394_MEMORY_ALLOCATION_FAILURE;
    craw->frames = malloc (num_dma_buffers * sizeof *craw->frames);
    if (craw->frames == NULL)
        goto error_mmap;

    for (i = 0; i < num_dma_buffers; i++) {
        err = init_frame(craw, i, &proto);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error initing frames");
            break;
        }
    }
    if (err != DC1394_SUCCESS) {
        for (j = 0; j < i; j++)
            release_frame(craw, j);
        goto error_mmap;
    }

    for (i = 0; i < num_dma_buffers; i++) {
        err = queue_frame(craw, i);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error queuing");
            goto error_frames;
        }
    }

    // starting from here we use the ISO channel so we set the flag in
    // the camera struct:
    craw->capture_is_set = 1;

    start_iso.cycle   = -1;
    start_iso.tags = FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS;
    start_iso.sync = 1;
    start_iso.handle = craw->iso_handle;
    retval = ioctl(craw->iso_fd, FW_CDEV_IOC_START_ISO, &start_iso);
    err = DC1394_IOCTL_FAILURE;
    if (retval < 0) {
        dc1394_log_error("error starting iso");
        goto error_frames;
    }

    // if auto iso is requested, start ISO
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        err=dc1394_video_set_transmission(camera, DC1394_ON);
        DC1394_ERR_RTN(err,"Could not start ISO!");
        craw->iso_auto_started=1;
    }

    return DC1394_SUCCESS;

error_frames:
    for (i = 0; i < num_dma_buffers; i++)
        release_frame(craw, i);
error_mmap:
    munmap(craw->buffer, craw->buffer_size);
error_fd:
    close(craw->iso_fd);

    return err;
}
コード例 #9
0
ファイル: firewire.cpp プロジェクト: WooYoungChoi/Pangolin
// Note:
// the following was tested on a IIDC camera over USB therefore might not work as
// well on a camera over proper firewire transport
void FirewireVideo::init_format7_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    float framerate,
    uint32_t width, uint32_t height,
    uint32_t left, uint32_t top, bool reset_at_boot
    ) {

    if(video_mode< DC1394_VIDEO_MODE_FORMAT7_0)
        throw VideoException("roi can be specified only for format7 modes");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }

    cout << "Using camera with GUID " << camera->guid << endl;

    if(reset_at_boot){
      dc1394_camera_reset(camera);
    }

    //-----------------------------------------------------------------------
    //  setup mode and roi
    //-----------------------------------------------------------------------

    if(iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
           throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    // check that the required mode is actually supported
    dc1394format7mode_t format7_info;

    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // safely set the video mode
    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 video mode");

    // set position to 0,0 so that setting any size within min and max is a valid command
    err = dc1394_format7_set_image_position(camera, video_mode,0,0);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 image position");

    // work out the desired image size
    width = nearest_value(width, format7_info.unit_pos_x, 0, format7_info.max_size_x - left);
    height = nearest_value(height, format7_info.unit_pos_y, 0, format7_info.max_size_y - top);

    // set size
    err = dc1394_format7_set_image_size(camera,video_mode,width,height);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    // get the info again since many parameters depend on image size
    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // work out position of roi
    left = nearest_value(left, format7_info.unit_size_x, format7_info.unit_size_x, format7_info.max_size_x - width);
    top = nearest_value(top, format7_info.unit_size_y, format7_info.unit_size_y, format7_info.max_size_y - height);

    // set roi position
    err = dc1394_format7_set_image_position(camera,video_mode,left,top);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    this->width = width;
    this->height = height;
    this->top = top;
    this->left = left;

    cout<<"roi: "<<left<<" "<<top<<" "<<width<<" "<<height<<"  ";


    //-----------------------------------------------------------------------
    //  setup frame rate
    //-----------------------------------------------------------------------

    err=dc1394_format7_set_packet_size(camera,video_mode, format7_info.max_packet_size);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 packet size");

    if((framerate != MAX_FR) && (framerate != EXT_TRIG)){
      //set the framerate by using the absolute feature as suggested by the
      //folks at PointGrey
      err = dc1394_feature_set_absolute_control(camera,DC1394_FEATURE_FRAME_RATE,DC1394_ON);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not turn on absolute frame rate control");

      err = dc1394_feature_set_mode(camera,DC1394_FEATURE_FRAME_RATE,DC1394_FEATURE_MODE_MANUAL);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not make frame rate manual ");

      err=dc1394_feature_set_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,framerate);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not set format7 framerate ");
    }

    // ask the camera what is the resulting framerate (this assume that such a rate is actually
    // allowed by the shutter time)
    float value;
    err=dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,&value);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not get framerate");

    cout<<" framerate(shutter permitting):"<<value<<endl;

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

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    Start();

}
コード例 #10
0
ファイル: capture.c プロジェクト: dscho/libdc1394
dc1394error_t
dc1394_windows_capture_setup(platform_camera_t * craw, uint32_t num_dma_buffers,
                             uint32_t flags)
{
    dc1394camera_t * camera = craw->camera;
    dc1394error_t err;

    if (flags & DC1394_CAPTURE_FLAGS_DEFAULT) {
        flags = DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
            DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC;
    }

    // if capture is already set, abort
    if (craw->capture_is_set > 0) {
        return DC1394_CAPTURE_IS_RUNNING;
    }

    craw->capture.flags = flags;
    craw->allocated_channel = -1;

    // if auto iso is requested, stop ISO (if necessary)
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        dc1394switch_t is_iso_on;
        dc1394_video_get_transmission(camera, &is_iso_on);
        if (is_iso_on == DC1394_ON) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
        }
    }

    craw->capture.frames =
        malloc (num_dma_buffers * sizeof (dc1394video_frame_t));
    if (!craw->capture.frames) {
        goto fail;
    }

    err = capture_basic_setup(camera, craw->capture.frames);
    if (err != DC1394_SUCCESS) {
        goto fail;
    }

    err = windows_capture_setup (craw, num_dma_buffers, flags);
    if (err != DC1394_SUCCESS) {
        goto fail;
    }

    // if auto iso is requested, start ISO
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        err=dc1394_video_set_transmission(camera, DC1394_ON);
        DC1394_ERR_RTN(err,"Could not start ISO!");
        craw->iso_auto_started = 1;
    }

    craw->capture.num_dma_buffers = num_dma_buffers;
    return DC1394_SUCCESS;

 fail:
    // free resources if they were allocated
    if (craw->allocated_channel >= 0) {
        if (dc1394_iso_release_channel (camera, craw->allocated_channel)
            != DC1394_SUCCESS)
            dc1394_log_warning("Warning: Could not free ISO channel");
    }
    if (craw->allocated_bandwidth) {
        if (dc1394_iso_release_bandwidth (camera, craw->allocated_bandwidth)
            != DC1394_SUCCESS)
            dc1394_log_warning("Warning: Could not free bandwidth");
    }
    craw->allocated_channel = -1;
    craw->allocated_bandwidth = 0;

    free (craw->capture.frames);
    craw->capture.frames = NULL;
    dc1394_log_error ("Error: Failed to setup DMA capture");

    return DC1394_FAILURE;
}
コード例 #11
0
ファイル: firewire.cpp プロジェクト: asimay/ScaViSLAM_ros
// Note:
// the following was tested on a IIDC camera over USB therefore might not work as
// well on a camera over proper firewire transport
void FirewireVideo::init_format7_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    int framerate,
    uint32_t width, uint32_t height,
    uint32_t left, uint32_t top, bool reset_at_boot
    ) {

    if(video_mode< DC1394_VIDEO_MODE_FORMAT7_0)
        throw VideoException("roi can be specified only for format7 modes");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }

    cout << "Using camera with GUID " << camera->guid << endl;

    if(reset_at_boot){
      dc1394_camera_reset(camera);
    }

    //-----------------------------------------------------------------------
    //  setup mode and roi
    //-----------------------------------------------------------------------

    if(iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
           throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    // check that the required mode is actually supported
    dc1394format7mode_t format7_info;

    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // safely set the video mode
    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 video mode");

    // set position to 0,0 so that setting any size within min and max is a valid command
    err = dc1394_format7_set_image_position(camera, video_mode,0,0);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 image position");

    // work out the desired image size
    width = nearest_value(width, format7_info.unit_pos_x, 0, format7_info.max_size_x - left);
    height = nearest_value(height, format7_info.unit_pos_y, 0, format7_info.max_size_y - top);

    // set size
    err = dc1394_format7_set_image_size(camera,video_mode,width,height);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    // get the info again since many parameters depend on image size
    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // work out position of roi
    left = nearest_value(left, format7_info.unit_size_x, format7_info.unit_size_x, format7_info.max_size_x - width);
    top = nearest_value(top, format7_info.unit_size_y, format7_info.unit_size_y, format7_info.max_size_y - height);

    // set roi position
    err = dc1394_format7_set_image_position(camera,video_mode,left,top);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    this->width = width;
    this->height = height;
    this->top = top;
    this->left = left;

    cout<<"roi: "<<left<<" "<<top<<" "<<width<<" "<<height<<"  ";


    //-----------------------------------------------------------------------
    //  setup frame rate
    //-----------------------------------------------------------------------

    if((framerate == MAX_FR)||(framerate == EXT_TRIG)){

      err=dc1394_format7_set_packet_size(camera,video_mode, format7_info.max_packet_size);
      if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 packet size");

    } else {

      // setting packet size to get the desired frame rate according to the libdc docs
      // does not do the trick, so for now we support only max frame rate

        throw VideoException("In format 7 only max frame rate is currently supported");
      //      uint32_t depth;
      //      err = dc1394_format7_get_data_depth(camera, video_mode, &depth);
      //      if( err != DC1394_SUCCESS )
      //        throw VideoException("Could not get format7 depth");
      //
      //      // the following is straight from the libdc docs
      //      double bus_period = bus_period_from_iso_speed(iso_speed);
      //
      //      // work out the max number of packets that the bus can deliver
      //      int num_packets = (int) (1.0/(bus_period*framerate) + 0.5);
      //
      //      if((num_packets > 4095)||(num_packets < 0))
      //        throw VideoException("number of format7 packets out of range");
      //
      //      // work out what the packet size should be for the requested size and framerate
      //      uint32_t packet_size = (width*964*depth + (num_packets*8) - 1)/(num_packets*8);
      //      packet_size = nearest_value(packet_size,format7_info.unit_packet_size,format7_info.unit_packet_size,format7_info.max_packet_size);
      //
      //      if(packet_size > format7_info.max_packet_size){
      //        throw VideoException("format7 requested frame rate and size exceed bus bandwidth");
      //      }
      //
      //      err=dc1394_format7_set_packet_size(camera,video_mode, packet_size);
      //      if( err != DC1394_SUCCESS ){
      //        throw VideoException("Could not set format7 packet size");
      //      }
    }

    // ask the camera what is the resulting framerate (this assume that such a rate is actually
    // allowed by the shutter time)
    err = dc1394_feature_set_power(camera,DC1394_FEATURE_FRAME_RATE,DC1394_OFF);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not turn off frame rate");

    float value;
    err=dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,&value);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not get framerate");

    cout<<" framerate(shutter permitting):"<<value<<endl;

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

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    Start();

}
コード例 #12
0
ファイル: pgr.c プロジェクト: jbmulligan/quip
int start_firewire_transmission(QSP_ARG_DECL  PGR_Cam * pgcp, int _ring_buffer_size )
{
	int i;
	dc1394error_t err;
	Data_Obj *dp;

//advise("start_firewire_transmission BEGIN");
	/* older version had third flags arg... */
//advise("calling dc1394_capture_setup");
	if( (err=dc1394_capture_setup(pgcp->pc_cam_p,_ring_buffer_size ,DC1394_CAPTURE_FLAGS_DEFAULT ))
		!= DC1394_SUCCESS ) {

		WARN("dc1394_capture_setup failed!?");
		describe_dc1394_error( QSP_ARG  err );

		if( err == DC1394_IOCTL_FAILURE ){
			advise("Try decreasing the number of ring buffer frames requested?");
			return -1;
		}

		fprintf( stderr,"unable to setup camera-\n"
			"check line %d of %s to make sure\n"
			"that the video mode and framerate are\n"
			"supported by your camera\n",
			__LINE__,__FILE__ );

		/*
		fprintf( stderr,
			"video_mode = %d, framerate = %d\n"
			"Check dc1394_control.h for the meanings of these values\n",
			pgcp->pc_video_mode, pgcp->pc_framerate );
			*/
		fprintf( stderr,
			"video_mode = %s (%d), framerate = %s (%d)\n",
			name_for_video_mode(pgcp->pc_video_mode),
			pgcp->pc_video_mode,
			name_for_framerate(pgcp->pc_framerate),
			pgcp->pc_framerate );

		NERROR1("error starting capture");

		return(-1);
	}

	pgcp->pc_ring_buffer_size = _ring_buffer_size;
	pgcp->pc_n_avail = _ring_buffer_size;

	pgcp->pc_flags |= PGR_CAM_IS_CAPTURING;

#ifdef FOOBAR	// we set this in the script already!?
	sprintf(msg_str,"%d",ring_buffer_size);		/* tell the scripting language */
	assign_var("ring_buffer_size",msg_str);
#endif // FOOBAR

	// have the camera start sending us data
//advise("calling dc1394_video_set_transmission");
	if( (err=dc1394_video_set_transmission( pgcp->pc_cam_p, DC1394_ON ))
			!= DC1394_SUCCESS ) {
		WARN("Unable to start camera iso transmission");
		describe_dc1394_error( QSP_ARG  err );

		// do we need to undo capture_setup?
		dc1394_capture_stop( pgcp->pc_cam_p );
		pgcp->pc_flags &= ~PGR_CAM_IS_CAPTURING;

		return(-1);
	}
	pgcp->pc_flags |= PGR_CAM_IS_TRANSMITTING;

	//  Sleep untill the camera has a transmission
	dc1394switch_t status = DC1394_OFF;

	for ( i = 0; i <= 5; i++ ) {
		usleep(50000);
//advise("calling dc1394_video_get_transmission");
		if ( dc1394_video_get_transmission( pgcp->pc_cam_p, &status )
				!= DC1394_SUCCESS ) {
			fprintf( stderr, "Unable to get transmision status\n" );
			return(-1);
		}
		if ( status != DC1394_OFF )
			break;

		if( i == 5 ) {
			fprintf(stderr,"Camera doesn't seem to want to turn on!\n");
			return(-1);
		}
	}
//advise("start_firewire_transmission DONE");

	// Now make sure that we have the frame objects...
	dp = dobj_of("_frame1");
	if( dp == NULL ) init_buffer_objects(QSP_ARG  pgcp);

	return(0);
}