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);
}
Example #2
0
static dc1394error_t adaptBufferStereoLocal(dc1394video_frame_t *in, dc1394video_frame_t *out)
{
    uint32_t bpp;

    // buffer position is not changed. Size is boubled in Y
    out->size[0] = in->size[0];
    out->size[1] = in->size[1] * 2;
    out->position[0] = in->position[0];
    out->position[1] = in->position[1];

    // color coding is set to mono8 or raw8.
    switch (in->color_coding)
    {
    case DC1394_COLOR_CODING_RAW16:
        out->color_coding = DC1394_COLOR_CODING_RAW8;
        break;
    case DC1394_COLOR_CODING_MONO16:
    case DC1394_COLOR_CODING_YUV422:
        out->color_coding = DC1394_COLOR_CODING_MONO8;
        break;
    default:
        return DC1394_INVALID_COLOR_CODING;
    }

    // keep the color filter value in all cases. if the format is not raw it will not be further used anyway
    out->color_filter = in->color_filter;

    // the output YUV byte order must be already set if the buffer is YUV422 at the output
    // if the output is not YUV we don't care about this field.
    // Hence nothing to do.
    // we always convert to 8bits (at this point) we can safely set this value to 8.
    out->data_depth = 8;

    // don't know what to do with stride... >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<
    // out->stride=??
    // the video mode should not change. Color coding and other stuff can be accessed in specific fields of this struct
    out->video_mode = in->video_mode;

    // padding is kept:
    out->padding_bytes = in->padding_bytes;

    // image bytes changes:    >>>> TODO: STRIDE SHOULD BE TAKEN INTO ACCOUNT... <<<<
    dc1394_get_color_coding_bit_size(out->color_coding, &bpp);
    out->image_bytes = (out->size[0] * out->size[1] * bpp) / 8;

    // total is image_bytes + padding_bytes
    out->total_bytes = out->image_bytes + out->padding_bytes;

    // bytes-per-packet and packets_per_frame are internal data that can be kept as is.
    out->packet_size  = in->packet_size;
    out->packets_per_frame = in->packets_per_frame;

    // timestamp, frame_behind, id and camera are copied too:
    out->timestamp = in->timestamp;
    out->frames_behind = in->frames_behind;
    out->camera = in->camera;
    out->id = in->id;

    // verify memory allocation:
    if (out->total_bytes > out->allocated_image_bytes)
    {
        free(out->image);
        out->image = (uint8_t*)malloc(out->total_bytes * sizeof(uint8_t));
        out->allocated_image_bytes = out->total_bytes;
    }

    // Copy padding bytes:
    memcpy(&(out->image[out->image_bytes]), &(in->image[in->image_bytes]), out->padding_bytes);
    out->little_endian = DC1394_FALSE; // not used before 1.32 is out.
    out->data_in_padding = DC1394_FALSE; // not used before 1.32 is out.
    return DC1394_SUCCESS;
}