libdc1394_video_set_mode doesn’t change the mode – A solution!

Posted by Benjamin Close on May 6, 2011 under OpenSource, Programming | Be the First to Comment

This article details a reason libdc1394_video_set_mode/libdc1394_video_set_framerate  may not work.

Whilst working on an application that makes use of a 1394a/firewire camera I found a strange bug/feature with libdc1394. The problem was dc1394 was being used to the mode of the camera to 800×600 resolution. However, when querying the frame size after dequeuing the frame, the size was only 640×480. Ie: See the below snippits:

dc1394error_t result = dc1394_video_set_mode( this->camera, DC1394_VIDEO_MODE_800x600_RGB8);
if( result != DC1394_SUCCESS )
dc1394video_frame_t *frame=NULL;
dc1394error_t result;
// capture one frame
result = dc1394_capture_dequeue( this->camera, DC1394_CAPTURE_POLICY_WAIT, &frame );
if( result != DC1394_SUCCESS )
// Allocate image memory if required
if( this->lastFrame.image == NULL ){
memcpy(this->lastFrame,frame, sizeof(dc1394video_frame_t));
this->lastFrame.image = (uint8_t *)malloc(frame->total_bytes * sizeof(uint8_t));

At this point total_bytes was 921600 which works out to be 640x480x3 (RGB);

I was stumped. I asked for one mode and got another back. All with no errors what so ever from libdc1394.

After over an hour of debugging, google searching and more,  I eventually found the reason.  The comment that ended up in the code explains the cause:

// Shutdown any isotransports that are setup for the camera.
// It turns out that libDC1394 will quite happily let you set modes,
// framerates, etc but if there is an iso stream running none of them
// will actually take affect. Hence you can set a 800x600 res and get
// back 640x480 video frame - really nice libdc1394. It could at least
// indicate there was a active stream when setting the mode!
// Anyway to deal with this we force the camera to stop capturing
// before we change the settings, if the camera was capturing prior to
// setConfiguration being called, we restart the capture

So the solution is to make sure the iso transmission stream has been shutdown. this can be achieved using:

dc1394_video_set_transmission( this->camera, DC1394_OFF );
dc1394_capture_stop( this->camera );

An easy fix but certainly an annoying setup. I’ve not tested it but I’m guessing many of the other functions:

  • dc1394_video_set_framerate
  • dc1394_video_set_iso_speed
  • dc1394_feature_set_mode
  • dc1394_video_set_one_shot

are also affected.

Donations keep this site alive

Add A Comment