Beispiel #1
0
/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    demux_t     *p_demux = (demux_t*)p_this;
    demux_sys_t *p_sys = p_demux->p_sys;
    int result = 0;

    /* Stop data transmission */
    result = dc1394_stop_iso_transmission( p_sys->fd_video,
                                           p_sys->camera.node );
    if( result != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "couldn't stop the camera" );
    }

    /* Close camera */
    if( p_sys->dma_capture )
    {
        dc1394_dma_unlisten( p_sys->fd_video, &p_sys->camera );
        dc1394_dma_release_camera( p_sys->fd_video, &p_sys->camera );
    }
    else
    {
        dc1394_release_camera( p_sys->fd_video, &p_sys->camera );
    }

    if( p_sys->fd_video )
        dc1394_destroy_handle( p_sys->fd_video );
    CloseAudioDev( p_demux );

    free( p_sys->camera_nodes );
    free( p_sys->audio_device );

    free( p_sys );
}
Beispiel #2
0
void dc1394_close(void)
{
	fprintf( stderr, "closing down..." );
	dc1394_dma_unlisten( handle, &camera );
	dc1394_dma_release_camera( handle, &camera );
	dc1394_destroy_handle( handle );
	fprintf( stderr, "done!\n" );
}
bool linuxfwCamera::startCamera() {
	
	if (dc1394_start_iso_transmission(handle,camera.node) !=DC1394_SUCCESS)  {
		fprintf( stderr, "unable to start camera iso transmission\n");
		dc1394_dma_release_camera(handle,&camera);
		dc1394_destroy_handle(handle);
		return false;
	}
	return true;
}
  //---------------------------------------------------------------
  void 
  Device1394::cleanupDevice()
  {
    MIRO_DBG(VIDEO, LL_DEBUG, "Device1394::cleanupDevice()");

    if (handle_) {
      dc1394_destroy_handle(handle_);
      handle_ = 0;
    }
  }
bool linuxfwCamera::findCamera() {
	
	// get the number of ports
	raw1394handle_t phandle = raw1394_new_handle();
	
	if (phandle==NULL) {
		printf( "no firewire ports found\n");
		return false;
	}
	
	struct raw1394_portinfo pinf;
	int ports = raw1394_get_port_info(phandle, &pinf, 0);
	dc1394_destroy_handle(phandle);
	
	//printf("firewire ports: %d\n",ports);
	if (ports<1) {
		printf("no firewire ports found\n");
		return false;
	}
	// open ohci and asign handle to it
	for (int i=0;i<ports;i++)  {
		//printf("trying port %d\n",i);
		handle = dc1394_create_handle(i);
	
		// get the camera nodes and describe them as we find them
		numNodes = raw1394_get_nodecount(handle);
		camera_nodes = dc1394_get_camera_nodes(handle,&numCameras,0);
		//fflush(stdout);
	
		//printf("found %d cameras\n",numCameras);
		if (numCameras<1) {
			dc1394_destroy_handle(handle);
			continue;
		} else {
			cameraID = 0;
			return true;
		}
	}
	
	fprintf( stderr, "no firewire camera found\n");
	return false;
}
static int dc1394_close(AVFormatContext * context)
{
    struct dc1394_data *dc1394 = context->priv_data;

    dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node);
    dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
    dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
    dc1394_destroy_handle(dc1394->handle);

    return 0;
}
Beispiel #7
0
static void *AcquireFrames(void *arg) {
  struct timeval tv;
  int    start_sec;
  int cam = (int)arg;
  pthread_cleanup_push(dc1394Done, (void *)cam);
  printf("in acquire\n");
  gettimeofday(&tv, NULL);
  start_sec = tv.tv_sec;
  printf("start sec is %d\n", start_sec);
  for (Cams[cam].next_frame=0; Cams[cam].next_frame < Cams[cam].max_frames; Cams[cam].next_frame++) {
    if (dc1394_dma_single_capture(&Cams[cam].camera)!=DC1394_SUCCESS) {
      fprintf( stderr, "unable to capture a frame\n");
      dc1394_stop_iso_transmission(Cams[cam].handle,Cams[cam].camera.node);
      Cams[cam].running = 0;
      dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
      Cams[cam].dma_active = 0;
      dc1394_destroy_handle(Cams[cam].handle);
      Cams[cam].handle = 0;
      Cams[cam].thread_id =0;
      return;
    }
    gettimeofday(&tv, NULL);
    Cams[cam].times[Cams[cam].next_frame] = tv.tv_sec-start_sec+(double)tv.tv_usec*1E-6;
    printf("The time for frame %d is %g\n", Cams[cam].next_frame, Cams[cam].times[Cams[cam].next_frame]);
    memcpy((void *)Cams[cam].frames+Cams[cam].next_frame*Cams[cam].width*Cams[cam].height, Cams[cam].camera.capture_buffer, Cams[cam].width*Cams[cam].height);
    dc1394_dma_done_with_buffer(&Cams[cam].camera);
    printf("got frame %d\n", Cams[cam].next_frame);
  }
  /* clean up active daq */
  dc1394_stop_iso_transmission(Cams[cam].handle,Cams[cam].camera.node);
  Cams[cam].running = 0;
  dc1394_dma_unlisten(Cams[cam].handle, &Cams[cam].camera);
  dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
  Cams[cam].dma_active = 0;
  dc1394_destroy_handle(Cams[cam].handle);
  Cams[cam].handle = 0;

  Cams[cam].thread_id =0;
  pthread_cleanup_pop(0);
  return;
}
Beispiel #8
0
static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
    dc1394_data* dc1394 = c->priv_data;
    AVStream* vst;
    nodeid_t* camera_nodes;
    int res;
    struct dc1394_frame_format *fmt = NULL;
    struct dc1394_frame_rate *fps = NULL;

    if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
        return -1;

    /* Now let us prep the hardware. */
    dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
    if (!dc1394->handle) {
        av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */);
        goto out;
    }
    camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
    if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) {
        av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel);
        goto out_handle;
    }
    res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel],
                                   0,
                                   FORMAT_VGA_NONCOMPRESSED,
                                   fmt->frame_size_id,
                                   SPEED_400,
                                   fps->frame_rate_id, 8, 1,
                                   c->filename,
                                   &dc1394->camera);
    dc1394_free_camera_nodes(camera_nodes);
    if (res != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n");
        goto out_handle;
    }

    res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node);
    if (res != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n");
        goto out_handle_dma;
    }

    return 0;

out_handle_dma:
    dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
    dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
out_handle:
    dc1394_destroy_handle(dc1394->handle);
out:
    return -1;
}
bool linuxfwCamera::closeCamera() {
	
	if (use_dma) {
		dc1394_dma_unlisten(handle, &camera);
		dc1394_dma_release_camera(handle, &camera);
	}
	else { 
		dc1394_release_camera(handle,&camera);
	}
	dc1394_camera_off(handle, cameraID);
	dc1394_destroy_handle(handle);
	return true;
}
Beispiel #10
0
void  dc1394Done(void *arg) {
  int cam = (int)arg;
  printf("here I am in done - %d %d\n", cam, Cams[cam].running);
  /* clean up any active daq */
  if (Cams[cam].running) {
    printf("stop the dma\n\n");
    dc1394_dma_unlisten(Cams[cam].handle, &Cams[cam].camera);
    dc1394_stop_iso_transmission(Cams[cam].handle,Cams[cam].camera.node);
    Cams[cam].running = 0;
  }
  if (Cams[cam].dma_active) {
    dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
    Cams[cam].dma_active = 0;
  }
  if (Cams[cam].handle != NULL) {
    dc1394_destroy_handle(Cams[cam].handle);
    Cams[cam].handle = 0;
  }

  printf("all done with Don\n");
}
static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
    dc1394_data* dc1394 = c->priv_data;
    AVStream* vst;
    nodeid_t* camera_nodes;
    int res;
    struct dc1394_frame_format *fmt;
    struct dc1394_frame_rate *fps;

    for (fmt = dc1394_frame_formats; fmt->width; fmt++)
         if (fmt->pix_fmt == ap->pix_fmt && fmt->width == ap->width && fmt->height == ap->height)
             break;

    for (fps = dc1394_frame_rates; fps->frame_rate; fps++)
         if (fps->frame_rate == av_rescale(1000, ap->time_base.den, ap->time_base.num))
             break;

    /* create a video stream */
    vst = av_new_stream(c, 0);
    if (!vst)
        return -1;
    av_set_pts_info(vst, 64, 1, 1000);
    vst->codec->codec_type = CODEC_TYPE_VIDEO;
    vst->codec->codec_id = CODEC_ID_RAWVIDEO;
    vst->codec->time_base.den = fps->frame_rate;
    vst->codec->time_base.num = 1000;
    vst->codec->width = fmt->width;
    vst->codec->height = fmt->height;
    vst->codec->pix_fmt = fmt->pix_fmt;

    /* packet init */
    av_init_packet(&dc1394->packet);
    dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height);
    dc1394->packet.stream_index = vst->index;
    dc1394->packet.flags |= PKT_FLAG_KEY;

    dc1394->current_frame = 0;
    dc1394->fps = fps->frame_rate;

    vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000);

    /* Now lets prep the hardware */
    dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
    if (!dc1394->handle) {
        av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */);
        goto out;
    }
    camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
    if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) {
        av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel);
        goto out_handle;
    }
    res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel],
                                   0,
                                   FORMAT_VGA_NONCOMPRESSED,
                                   fmt->frame_size_id,
                                   SPEED_400,
                                   fps->frame_rate_id, 8, 1,
                                   c->filename,
                                   &dc1394->camera);
    dc1394_free_camera_nodes(camera_nodes);
    if (res != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n");
        goto out_handle;
    }

    res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node);
    if (res != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n");
        goto out_handle_dma;
    }

    return 0;

out_handle_dma:
    dc1394_dma_unlisten(dc1394->handle, &dc1394->camera);
    dc1394_dma_release_camera(dc1394->handle, &dc1394->camera);
out_handle:
    dc1394_destroy_handle(dc1394->handle);
out:
    return -1;
}
bool linuxfwCamera::initCamera(int width, int height, bool colour) {
	
	if (cameraID < 0) return false;
	this->width = width;
	this->height = height;
	this->colour = colour;
	bytes = (colour?3:1);
	
	quadlet_t format;
	if (dc1394_query_supported_modes(handle, cameraID,FORMAT_VGA_NONCOMPRESSED,&format) !=DC1394_SUCCESS) {
		fprintf( stderr,"unable to query format\n");
	}
	
	image_mode_ = 0;
	if (colour) {	
		int yuv411 = 29;
		int rgb = 27;
		if	(format & (0x1<<yuv411)) image_mode_=MODE_640x480_YUV411;
		else if (format & (0x1<<rgb)) 	 image_mode_=MODE_640x480_RGB;
	} else {
		int mono = 26;
		int yuv411 = 29;
		if (format & (0x1<<mono))        image_mode_=MODE_640x480_MONO;
		else if	(format & (0x1<<yuv411)) image_mode_=MODE_640x480_YUV411;
	}
	if(!image_mode_) return false;
	quadlet_t frames;
	if (dc1394_query_supported_framerates(handle, cameraID,FORMAT_VGA_NONCOMPRESSED, image_mode_, &frames) !=DC1394_SUCCESS) {
		fprintf( stderr,"unable query frame rate\n");
	}
	
	fps = 60;
	while (fps>=15) {
		frame_rate_ = 0;
		int test_rate = 0;
		
		if (fps == 60)
		test_rate = FRAMERATE_60;
		else if (fps == 30)
		test_rate = FRAMERATE_30;
		else if (fps == 15)
		test_rate = FRAMERATE_15;    
		
		if ((frames & (0x1<<(31-(test_rate-FRAMERATE_MIN)))))
			frame_rate_=test_rate;
		
		if(!frame_rate_) {
			fps=fps/2;
		} else break;
	}
	if(!frame_rate_) return false;
	printf("framerate\n");  
	
	char videoDevice[24] = "";
	sprintf(videoDevice,"/dev/video1394/%d",dc1394_get_camera_port(handle));
	
	// setup capture
	if (dc1394_dma_setup_capture(handle,camera_nodes[cameraID],
				0, /* channel */ 
				FORMAT_VGA_NONCOMPRESSED,
				image_mode_,
				SPEED_400,
				frame_rate_,
				4,
				0,
				videoDevice,
				&camera)==DC1394_SUCCESS) {
		use_dma=true;
	} else if (dc1394_setup_capture(handle,camera_nodes[cameraID],
				0, /* channel */ 
				FORMAT_VGA_NONCOMPRESSED,
				image_mode_,
				SPEED_400,
				frame_rate_,
				&camera)==DC1394_SUCCESS) {
		use_dma=false;
	} else {
		fprintf( stderr,"unable to setup camera -\n"
			"make sure that the video mode,framerate and format are supported by your camera\n");
		dc1394_release_camera(handle,&camera);
		dc1394_destroy_handle(handle);
		dc1394_free_camera_nodes(camera_nodes);
		return false;
	}
	
	
	dc1394_camerainfo info;
	if (dc1394_get_camera_info(handle, cameraID, &info) !=DC1394_SUCCESS ) {
		//printf("could not read camera info\n");
		sprintf(cameraName,"unknown camera");
	} else {
		sprintf(cameraName,"%s, %s", info.vendor, info.model);
	}
	
	/*if (dc1394_set_video_framerate(handle,cameraID,frame_rate)!=DC1394_SUCCESS) {
		fprintf( stderr,"%i nope\n");
		dc1394_release_camera(handle,&camera);
		//dc1394_destroy_handle(handle);
		//sdc1394_free_camera_nodes(camera_nodes);
		return false;
	}*/
	
	dc1394_free_camera_nodes(camera_nodes);
	
	// set trigger mode
	/*if( dc1394_set_trigger_mode(handle, camera.node, TRIGGER_MODE_0)
	!= DC1394_SUCCESS)
	{
	//fprintf( stderr, "unable to set camera trigger mode\n");
	}*/
	
	buffer = new unsigned char[width*height*bytes];	
	return true;
}
unsigned char* linuxfwCamera::getFrame()  {

	if (handle==NULL) return NULL;
	
	if (use_dma) {
		if (dc1394_dma_single_capture(&camera)!=DC1394_SUCCESS) 
		{
			fprintf( stderr, "unable to capture a frame\n");
			dc1394_dma_release_camera(handle,&camera);
			dc1394_destroy_handle(handle);
			return NULL;
		} dc1394_dma_done_with_buffer(&camera);
	} else {
		if (dc1394_single_capture(handle,&camera)!=DC1394_SUCCESS) 
		{
			fprintf( stderr, "unable to capture a frame\n");
			dc1394_dma_release_camera(handle,&camera);
			dc1394_destroy_handle(handle);
			return NULL;
		}
	}
	
	switch (colour) {
		case false: {
			if (image_mode_==MODE_640x480_YUV411) {
				unsigned char *src = (unsigned char*)camera.capture_buffer;
				unsigned char *dest = buffer;
				for(int y=0;y<height;y++) {
					for(int x=0;x<width/4;++x) {
						src++;
						*dest++ = *src++;
						*dest++ = *src++;
						src++;
						*dest++ = *src++;
						*dest++ = *src++;
					}
				}
			} else {
				if (buffer!=NULL)
					memcpy(buffer,(unsigned char*)camera.capture_buffer,width*height*bytes);
			}
			break;
		}
		case true: {
			if (image_mode_==MODE_640x480_YUV411) {
				int R,G,B;
				int Y[4];
				int U,V;
				
				unsigned char *src = (unsigned char*)camera.capture_buffer;
				unsigned char *dest = buffer;
				for(int y=0;y<height;y++) {
					for(int x=0;x<width/4;++x) {
						U    = *src++;
						Y[0] = *src++;
						Y[1] = *src++;
						V    = *src++;
						Y[2] = *src++;
						Y[3] = *src++;
	
						// U and V are +-0.5
						U -= 128;
						V -= 128;
						
						// conversion
						for (int i=0;i<4;i++) {
							R = (int)(Y[i] + 1.370705f * V); 			//R
							G = (int)(Y[i] - 0.698001f * V - 0.337633f * U);	//G
							B = (int)(Y[i] + 1.732446f * U); 			//B
							
							if (R < 0) R=0;
							if (G < 0) G=0;
							if (B < 0) B=0;
							if (R > 255) R=255;
							if (G > 255) G=255;
							if (B > 255) B=255;
		
							*dest++ = B;
							*dest++ = G;
							*dest++ = R;
						}
					}
				}			
			} else {
				if (buffer!=NULL)
					memcpy(buffer,(unsigned char*)camera.capture_buffer,width*height*bytes);
			}
			break;
		}
		
	}
	
	return buffer;
}
Beispiel #14
0
/*****************************************************************************
 * ScanCameras
 *****************************************************************************/
static void ScanCameras( dc1394_sys *sys, demux_t *p_demux )
{
    struct raw1394_portinfo portinfo[MAX_IEEE1394_HOSTS];
    raw1394handle_t tempFd;
    dc1394_camerainfo  info;
    dc_camera *node_list = NULL;
    nodeid_t  *nodes = NULL;
    int num_ports = 0;
    int num_cameras = 0;
    int nodecount;
    int i, n;

    memset( &portinfo, 0, sizeof(portinfo) );

    msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." );

    tempFd = raw1394_new_handle();
    if( !tempFd )
        return VLC_EGENERIC;
    raw1394_get_port_info( tempFd, portinfo, MAX_IEEE1394_HOSTS);
    raw1394_destroy_handle( tempFd );

    for( i=0; i < MAX_IEEE1394_HOSTS; i++ )
    {
        /* check if port exists and has at least one node*/
        if( !portinfo[i].nodes )
            continue;
        nodes = NULL;
        nodecount = 0;
        tempFd = dc1394_create_handle( i );

        /* skip this port if we can't obtain a valid handle */
        if( !tempFd )
            continue;
        msg_Dbg( p_demux, "Found ieee1394 port %d (%s) ... "
                          "checking for camera nodes",
                          i, portinfo[i].name );
        num_ports++;

        nodes = dc1394_get_camera_nodes( tempFd, &nodecount, 0 );
        if( nodecount )
        {
            msg_Dbg( p_demux, "Found %d dc1394 cameras on port %d (%s)",
                     nodecount, i, portinfo[i].name );

            if( node_list )
                node_list = realloc( node_list, sizeof(dc_camera) * (num_cameras+nodecount) );
            else
                node_list = malloc( sizeof(dc_camera) * nodecount);

            for( n = 0; n < nodecount; n++ )
            {
                int result = 0;

                result = dc1394_get_camera_info( tempFd, nodes[n], &info );
                if( result == DC1394_SUCCESS )
                {
                    node_list[num_cameras+n].uid = info.euid_64;
                }
                node_list[num_cameras+n].node = nodes[n];
                node_list[num_cameras+n].port = i;
            }
            num_cameras += nodecount;
        }
        else
            msg_Dbg( p_demux, "no cameras found  on port %d (%s)",
                     i, portinfo[i].name );

        if( tempFd )
            dc1394_destroy_handle( tempFd );
    }
    sys->num_ports = num_ports;
    sys->num_cameras = num_cameras;
    sys->camera_nodes = node_list;
}
Beispiel #15
0
int dc1394Init(int cam, int width, int height, int max_frames, int trigger_mode, int shutter, int gain, int trig_on, int iso_speed, int frame_rate)
{
  int numNodes;
  nodeid_t * camera_nodes;
  int numCameras;

  if (first) {
    bzero(Cams, sizeof(Cams));
    first = 0;
  }
    printf("now is the time\n");
  if ((cam < 0) || (cam >= MAX_CAMERAS)) {
    fprintf(stderr, "Camera out of range, cam = %d must be between 0 and %d\n", cam, MAX_CAMERAS);
    return 0;
  }

  /* clean up any active daq */
  if (Cams[cam].thread_id != 0) {
    void *status;
    pthread_cancel(Cams[cam].thread_id);
    pthread_join(Cams[cam].thread_id, &status);
    Cams[cam].thread_id = 0;
  }

  /* now find the camera choke if not there or not correct */
  Cams[cam].handle = dc1394_create_handle(0);
  if (Cams[cam].handle==NULL)
  {
    fprintf( stderr, "Unable to aquire a raw1394 handle\n\n"
             "Please check \n"
	     "  - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n"
	     "  - if you have read/write access to /dev/raw1394\n\n");
    return(0);
  }

  /*-----------------------------------------------------------------------
   *  get the camera nodes and describe them as we find them
   *-----------------------------------------------------------------------*/
  numNodes = raw1394_get_nodecount(Cams[cam].handle);
  camera_nodes = dc1394_get_camera_nodes(Cams[cam].handle,&numCameras,1);
  if (numCameras<1)
  {
    fprintf( stderr, "no cameras found :(\n");
    dc1394_destroy_handle(Cams[cam].handle);
    Cams[cam].handle = 0;
    return(0);
  }

  /*-----------------------------------------------------------------------
   *  to prevent the iso-transfer bug from raw1394 system, check if
   *  camera is highest node. For details see 
   *  http://linux1394.sourceforge.net/faq.html#DCbusmgmt
   *  and
   *  http://sourceforge.net/tracker/index.php?func=detail&aid=435107&group_id=8157&atid=108157
   *-----------------------------------------------------------------------*/
  if( camera_nodes[0] == numNodes-1)
  {
    fprintf( stderr, "\n"
             "Sorry, your camera is the highest numbered node\n"
             "of the bus, and has therefore become the root node.\n"
             "The root node is responsible for maintaining \n"
             "the timing of isochronous transactions on the IEEE \n"
             "1394 bus.  However, if the root node is not cycle master \n"
             "capable (it doesn't have to be), then isochronous \n"
             "transactions will not work.  The host controller card is \n"
             "cycle master capable, however, most cameras are not.\n"
             "\n"
             "The quick solution is to add the parameter \n"
             "attempt_root=1 when loading the OHCI driver as a \n"
             "module.  So please do (as root):\n"
             "\n"
             "   rmmod ohci1394\n"
             "   insmod ohci1394 attempt_root=1\n"
             "\n"
             "for more information see the FAQ at \n"
             "http://linux1394.sourceforge.net/faq.html#DCbusmgmt\n"
             "\n");
    dc1394_destroy_handle(Cams[cam].handle);
    dc1394_free_camera_nodes(camera_nodes);
    return(0);
  }
  
  /*-----------------------------------------------------------------------
   *  setup capture
   *-----------------------------------------------------------------------*/
   if (dc1394_dma_setup_capture(Cams[cam].handle,camera_nodes[0],
                           0, /* channel */ 
                           FORMAT_VGA_NONCOMPRESSED,
                           MODE_640x480_MONO,
                           SPEED_400,
                           FRAMERATE_30,
				3, /* frames */
			    1,
			    "/dev/video1394/0", 
                           &Cams[cam].camera)!=DC1394_SUCCESS) 
 {
    fprintf( stderr,"unable to setup camera-\n"
             "check line %d of %s to make sure\n"
             "that the video mode,framerate and format are\n"
             "supported by your camera\n",
             __LINE__,__FILE__);
    dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
    Cams[cam].dma_active = 0;
    dc1394_destroy_handle(Cams[cam].handle);
    Cams[cam].handle = 0;
    dc1394_free_camera_nodes(camera_nodes);
    return(0);
  }
  dc1394_free_camera_nodes(camera_nodes);
  
  /* set trigger mode */
  if( dc1394_set_trigger_mode(Cams[cam].handle, Cams[cam].camera.node, trigger_mode)
      != DC1394_SUCCESS)
  {
    fprintf( stderr, "unable to set camera trigger mode\n");
    /*    
    dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
    Cams[cam].dma_active = 0;
    dc1394_destroy_handle(Cams[cam].handle);
    Cams[cam].handle = 0;
    return(0);
    */
  }

  /* eventually the same for the shutter and gain */

  if (dc1394_set_trigger_on_off(Cams[cam].handle, Cams[cam].camera.node,
				trig_on) != DC1394_SUCCESS)
    {
      fprintf(stderr, "unable to set trigger on to %d\n", trig_on);
    }


  /*-----------------------------------------------------------------------
   *  have the camera start sending us data
   *-----------------------------------------------------------------------*/
  if (dc1394_start_iso_transmission(Cams[cam].handle,Cams[cam].camera.node) !=DC1394_SUCCESS) 
  {
    fprintf( stderr, "unable to start camera iso transmission\n");
    dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
    Cams[cam].dma_active = 0;
    dc1394_destroy_handle(Cams[cam].handle);
    Cams[cam].handle = 0;
    return(0);
  }
  Cams[cam].running = 1;

  /* make room for the answers and write down all of the knobs for later use */
  if ( (width != Cams[cam].width) ||
       (height != Cams[cam].height) ||
       (max_frames != Cams[cam].max_frames) ){
    if (Cams[cam].frames != NULL)
      free(Cams[cam].frames);
    Cams[cam].frames = (unsigned char *)malloc(width*height*max_frames);
    if (Cams[cam].frames == NULL) {
      fprintf(stderr, "Could not allocate memory for %d frames (%d x %d)\n", max_frames, width, height);
      dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
      Cams[cam].dma_active = 0;
      dc1394_destroy_handle(Cams[cam].handle);
      Cams[cam].handle = 0;
      Cams[cam].max_frames = 0;
      return(0);
    }
    Cams[cam].times = (double *)malloc(max_frames * sizeof(double));
    if (Cams[cam].times == NULL) {
      fprintf(stderr, "Could not allocate memory for %d times\n", max_frames);
      dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
      free( Cams[cam].frames );
      Cams[cam].dma_active = 0;
      dc1394_destroy_handle(Cams[cam].handle);
      Cams[cam].handle = 0;
      Cams[cam].max_frames = 0;
     return(0);
    }

    Cams[cam].width = width;
    Cams[cam].height = height;
    Cams[cam].max_frames = max_frames;
  }
  Cams[cam].next_frame = 0;
  Cams[cam].trigger_mode = trigger_mode;
  Cams[cam].shutter = shutter;
  Cams[cam].gain = gain;
  if (pthread_create(&Cams[cam].thread_id,  NULL, AcquireFrames, (void *)cam) != 0) {
      fprintf(stderr, "Could not create thread to handle camera daq\n");
      dc1394_stop_iso_transmission(Cams[cam].handle,Cams[cam].camera.node);
      Cams[cam].running = 0;
      dc1394_dma_release_camera(Cams[cam].handle,&Cams[cam].camera);
      Cams[cam].dma_active = 0;
      dc1394_destroy_handle(Cams[cam].handle);
      Cams[cam].handle = 0;
      return(0);
  }
  return(1);
}