int main(int argc, char** argv)
{
    int rc; /**< return code */
    int port = 0;  /*!< fw handle port number */

    // parse command line (port number)
    opterr = 0;  // getopt no err output
    const char short_options[] = "p:";
    int next_opt;
    do {
        next_opt = getopt(argc, argv, short_options);
        switch(next_opt)
        {
        case 'p':
            port = atoi(optarg);
            break;
        case '?':
            std::cerr << "Invalid argument" << std::endl;
            break;
        default:
            break;
        }
    }
    while(next_opt != -1);


    // Setup signal handler to exit on Ctrl-C
    signal(SIGINT, signal_handler);


    // ----- Get handle and set port for the handle -------
    // create handle
    handle = raw1394_new_handle();
    if (handle == NULL) {
        std::cerr << "**** Error: could not create 1394 handle " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // get port number & sanity check
    int numPorts = raw1394_get_port_info(handle, NULL, 0);
    if (port < 0 || port >= numPorts) {
        std::cerr << "Invalid port number" << std::endl;
        return EXIT_FAILURE;
    }

    // let user to choose which port to use
    rc = raw1394_set_port(handle, 0);
    if (rc) {
        std::cerr << "**** Error: failed to set port " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }


    // -------- Set FireWire bus reset handler --------
    // set bus reset handler
    bus_reset_handler_t old_bus_reset_handler;
    old_bus_reset_handler = raw1394_set_bus_reset_handler(handle, my_bus_reset_handler);



    // ----------------------------------------------------------------------------
    // Start tutorial 2 arm server
    // ----------------------------------------------------------------------------


    // -------- Register arm register to handle arm request --------
    const nodeaddr_t arm_start_addr = 0xffffff000000;  // arm start address
    const size_t arm_length = 4;  // arm length to register

    // arm initial buffer
    byte_t arm_init_buffer[arm_length];
    memset(arm_init_buffer, 0x02, arm_length);  // set inital value to all 0x02

    // setup arm request handle
    raw1394_arm_reqhandle arm_reqhandle;
    char my_arm_callback_context[] = "my_arm_callback_context";
    arm_reqhandle.pcontext = my_arm_callback_context;
    arm_reqhandle.arm_callback = my_arm_req_callback;

    int access_mode = RAW1394_ARM_WRITE|RAW1394_ARM_READ;   // allow read and write transaction

    rc = raw1394_arm_register(handle,  // fw handle
                              arm_start_addr, // arm start address
			      arm_length * 4, // arm_length quadlet * 4 to bytes
			      arm_init_buffer,  // arm init buffer value
                              (octlet_t) &arm_reqhandle,  // arm request handler
                              access_mode,   // access permission
                              access_mode,   // client handler will be notified
                              0);            // client handler will need to handle these transactions

    if (rc) {
        std::cerr << "**** Error: failed to setup arm register, error " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // -------- Read from this arm buffer ---------
    // NOTE: this is a simple way to test if
    const size_t arm_read_size = 4;
    byte_t arm_read_buffer[arm_read_size];

    rc = raw1394_arm_get_buf(handle, arm_start_addr, arm_read_size, arm_read_buffer);
    if (rc) {
        std::cerr << "**** Error: failed to read arm register, error " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    } else {
        // if success then print value
        std::cout << "ARM buffer read value: \n";
        for (size_t i = 0; i < arm_read_size; i++) {
            std::cout << std::hex << " " << (int)arm_read_buffer[i];
        }
        std::cout << std::endl;
    }

    // -------- Set value to this arm buffer ---------
    const size_t arm_write_size = 4;
    byte_t arm_write_buffer[arm_write_size] = {0x11, 0x22, 0x33, 0x44};
    rc = raw1394_arm_set_buf(handle, arm_start_addr, arm_write_size, arm_write_buffer);
    if (rc) {
        std::cerr << "**** Error: failed to set arm register, error " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }


    // --------- Now read the value back from buffer ------
    rc = raw1394_arm_get_buf(handle, arm_start_addr, arm_read_size, arm_read_buffer);
    if (rc) {
        std::cerr << "**** Error: failed to read arm register, error " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    } else {
        // if success then print value
        std::cout << "ARM buffer read value: \n";
        for (size_t i = 0; i < arm_read_size; i++) {
            std::cout << std::hex << " " << (int)arm_read_buffer[i];
        }
        std::cout << std::endl;
    }


    // --------- Infinite raw1394 event loop ----------

    std::cout << "--------- Now start arm server -----------" << std::endl;
    std::cout << " node id = " << raw1394_get_local_id(handle) << std::endl;

    while (true)
    {
        raw1394_loop_iterate(handle);
    }

    // clean up & exit
    raw1394_destroy_handle(handle);

    return EXIT_SUCCESS;
}
Example #2
0
int
main(int argc, char *argv[])
{
  XGCValues                 xgcv;
  long                      background = 0x010203;
  unsigned int              channel;
  unsigned int              speed;
  int                       i, p, cn;
  raw1394handle_t           raw_handle;
  struct raw1394_portinfo   ports[MAX_PORTS];

  get_options(argc, argv);
  /* process options */
  switch (fps) {
  case 1:
    fps = FRAMERATE_1_875;
    break;
  case 3:
    fps = FRAMERATE_3_75;
    break;
  case 15:
    fps = FRAMERATE_15;
    break;
  case 30:
    fps = FRAMERATE_30;
    break;
  case 60:
    fps = FRAMERATE_60;
    break;
  default:
    fps = FRAMERATE_7_5;
    break;
  }
  switch (res) {
  case 1:
    res = MODE_640x480_YUV411;
    device_width = 640;
    device_height = 480;
    format = XV_YUY2;
    break;
  case 2:
    res = MODE_640x480_RGB;
    device_width = 640;
    device_height = 480;
    format = XV_YUY2;
    break;
  default:
    res = MODE_320x240_YUV422;
    device_width = 320;
    device_height = 240;
    format = XV_UYVY;
    break;
  }

  /* get the number of ports (cards) */
  raw_handle = raw1394_new_handle();
  if (raw_handle == NULL) {
    perror("Unable to aquire a raw1394 handle\n");
    perror("did you load the drivers?\n");
    exit(-1);
  }

  numPorts = raw1394_get_port_info(raw_handle, ports, numPorts);
  raw1394_destroy_handle(raw_handle);
  if (verbose) printf("number of ports = %d\n", numPorts);

  /* get dc1394 handle to each port */
  for (p = 0; p < numPorts; p++) {
    int                       camCount;

    handles[p] = dc1394_create_handle(p);
    if (handles[p] == NULL) {
      perror("Unable to aquire a raw1394 handle\n");
      perror("did you load the drivers?\n");
      cleanup();
      exit(-1);
    }

    /* get the camera nodes and describe them as we find them */
    camera_nodes = dc1394_get_camera_nodes(handles[p], &camCount, verbose);

    /* setup cameras for capture */
    for (i = 0; i < camCount; i++) {
      cameras[numCameras].node = camera_nodes[i];

      if (dc1394_get_camera_feature_set
          (handles[p], cameras[numCameras].node,
           &features) != DC1394_SUCCESS) {
        printf("unable to get feature set\n");
      } else if (verbose) {
        dc1394_print_feature_set(&features);
      }

      if (dc1394_get_iso_channel_and_speed
          (handles[p], cameras[numCameras].node, &channel,
           &speed) != DC1394_SUCCESS) {
        printf("unable to get the iso channel number\n");
        cleanup();
        exit(-1);
      }

      if (dc1394_dma_setup_capture
          (handles[p], cameras[numCameras].node, i + 1 /*channel */ ,
           FORMAT_VGA_NONCOMPRESSED, res, SPEED_400, fps, NUM_BUFFERS,
           DROP_FRAMES, device_name,
           &cameras[numCameras]) != DC1394_SUCCESS) {
        fprintf(stderr,
                "unable to setup camera - check line %d of %s to make sure\n",
                __LINE__, __FILE__);
        perror("that the video mode, framerate and format are supported\n");
        printf("by your camera(s)\n");
        cleanup();
        exit(-1);
      }


      /*have the camera start sending us data */
      if (dc1394_start_iso_transmission
          (handles[p], cameras[numCameras].node) != DC1394_SUCCESS) {
        perror("unable to start camera iso transmission\n");
        cleanup();
        exit(-1);
      }
      numCameras++;
    }
  }

  fflush(stdout);
  if (numCameras < 1) {
    perror("no cameras found :(\n");
    cleanup();
    exit(-1);
  }


  //set_manual_exposure_gain(0, 440, 30);

  switch (format) {
  case XV_YV12:
    set_frame_length(device_width * device_height * 3 / 2, numCameras);
    break;
  case XV_YUY2:
  case XV_UYVY:
    set_frame_length(device_width * device_height * 2, numCameras);
    break;
  default:
    fprintf(stderr, "Unknown format set (internal error)\n");
    exit(255);
  }

  /* create OpenCV image wrappers */
  for (cn = 0; cn < MAX_CAMERAS; cn++) {
    if (cn < numCameras) {
      iplImages[cn] =
        cvCreateImage(cvSize(device_width, device_height),
		      IPL_DEPTH_8U, 3);
      readOnlyImg =
        cvCreateImageHeader(cvSize(device_width, device_height),
                            IPL_DEPTH_8U, 3);
    } else {
      iplImages[cn] = NULL;
    }
  }

  /* initialize handvu */
  hvInitialize(device_width, device_height);
  hvLoadConductor(string(conductor_fname));
  hvStartRecognition();
  hvSetOverlayLevel(3);
  if (async_processing) {
    hvAsyncSetup(num_async_bufs, displayCallback);
    hvAsyncGetImageBuffer(&m_async_image, &m_async_bufID);
    if (sync_display) async_display_image = cvCloneImage(iplImages[0]);
  }  

  /* make the window */
  display = XOpenDisplay(getenv("DISPLAY"));
  if (display == NULL) {
    fprintf(stderr, "Could not open display \"%s\"\n", getenv("DISPLAY"));
    cleanup();
    exit(-1);
  }

  QueryXv();

  if (adaptor < 0) {
    cleanup();
    exit(-1);
  }

  width = device_width;
  height = device_height * numCameras;

  window =
    XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
                        width, height, 0, WhitePixel(display,
                                                     DefaultScreen
                                                     (display)), background);

  XSelectInput(display, window, StructureNotifyMask | KeyPressMask);
  XMapWindow(display, window);
  connection = ConnectionNumber(display);

  gc = XCreateGC(display, window, 0, &xgcv);

  /* local main event loop */
  while (1) {

    if (async_processing) {
      // asynchronous processing in HandVu

      capture_frame();
      process_frame();
      if (sync_display) display_frame();
      handle_events();
      
    } else {
      // synchronous processing in HandVu
      capture_frame();
      process_frame();
      display_frame();
      handle_events();
    }

    /* XPending */

  }                             /* while not interrupted */

  exit(0);
}
/* signal handler cleans up and exits the program */
void signal_handler(int sig) {
    signal(SIGINT, SIG_DFL);
    raw1394_destroy_handle(handle);
    exit(0);
}
static gboolean
gst_hdv1394src_start (GstBaseSrc * bsrc)
{
    GstHDV1394Src *src = GST_HDV1394SRC (bsrc);
    int control_sock[2];

    src->connected = FALSE;

    if (socketpair (PF_UNIX, SOCK_STREAM, 0, control_sock) < 0)
        goto socket_pair;

    READ_SOCKET (src) = control_sock[0];
    WRITE_SOCKET (src) = control_sock[1];

    if (fcntl (READ_SOCKET (src), F_SETFL, O_NONBLOCK) < 0)
        GST_ERROR_OBJECT (src, "failed to make read socket non-blocking: %s",
                          g_strerror (errno));
    if (fcntl (WRITE_SOCKET (src), F_SETFL, O_NONBLOCK) < 0)
        GST_ERROR_OBJECT (src, "failed to make write socket non-blocking: %s",
                          g_strerror (errno));

    src->handle = raw1394_new_handle ();

    if (!src->handle) {
        if (errno == EACCES)
            goto permission_denied;
        else if (errno == ENOENT)
            goto not_found;
        else
            goto no_handle;
    }

    src->num_ports = raw1394_get_port_info (src->handle, src->pinfo, 16);

    if (src->num_ports == 0)
        goto no_ports;

    if (src->use_avc || src->port == -1)
        src->avc_node = gst_hdv1394src_discover_avc_node (src);

    /* lets destroy handle and create one on port
       this is more reliable than setting port on
       the existing handle */
    raw1394_destroy_handle (src->handle);
    src->handle = raw1394_new_handle_on_port (src->port);
    if (!src->handle)
        goto cannot_set_port;

    raw1394_set_userdata (src->handle, src);
    raw1394_set_bus_reset_handler (src->handle, gst_hdv1394src_bus_reset);

    {
        nodeid_t m_node = (src->avc_node | 0xffc0);
        int m_channel = -1;
        int m_bandwidth = 0;
        int m_outputPort = -1;
        int m_inputPort = -1;

        m_channel = iec61883_cmp_connect (src->handle, m_node, &m_outputPort,
                                          raw1394_get_local_id (src->handle), &m_inputPort, &m_bandwidth);

        if (m_channel >= 0) {
            src->channel = m_channel;
        }
    }


    if ((src->iec61883mpeg2 =
                iec61883_mpeg2_recv_init (src->handle,
                                          gst_hdv1394src_iec61883_receive, src)) == NULL)
        goto cannot_initialise_dv;

#if 0
    raw1394_set_iso_handler (src->handle, src->channel,
                             gst_hdv1394src_iso_receive);
#endif

    GST_DEBUG_OBJECT (src, "successfully opened up 1394 connection");
    src->connected = TRUE;

    if (iec61883_mpeg2_recv_start (src->iec61883mpeg2, src->channel) != 0)
        goto cannot_start;
#if 0
    if (raw1394_start_iso_rcv (src->handle, src->channel) < 0)
        goto cannot_start;
#endif

    if (src->use_avc) {
        raw1394handle_t avc_handle = raw1394_new_handle_on_port (src->port);

        GST_LOG ("We have an avc_handle");

        /* start the VCR */
        if (avc_handle) {
            if (!avc1394_vcr_is_recording (avc_handle, src->avc_node)
                    && avc1394_vcr_is_playing (avc_handle, src->avc_node)
                    != AVC1394_VCR_OPERAND_PLAY_FORWARD) {
                GST_LOG ("Calling avc1394_vcr_play()");
                avc1394_vcr_play (avc_handle, src->avc_node);
            }
            raw1394_destroy_handle (avc_handle);
        } else {
            GST_WARNING_OBJECT (src, "Starting VCR via avc1394 failed: %s",
                                g_strerror (errno));
        }
    }

    return TRUE;

socket_pair:
    {
        GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
                           GST_ERROR_SYSTEM);
        return FALSE;
    }
permission_denied:
    {
        GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM);
        return FALSE;
    }
not_found:
    {
        GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), GST_ERROR_SYSTEM);
        return FALSE;
    }
no_handle:
    {
        GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
                           ("can't get raw1394 handle (%s)", g_strerror (errno)));
        return FALSE;
    }
no_ports:
    {
        raw1394_destroy_handle (src->handle);
        src->handle = NULL;
        GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
                           ("no ports available for raw1394"));
        return FALSE;
    }
cannot_set_port:
    {
        GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
                           ("can't set 1394 port %d", src->port));
        return FALSE;
    }
cannot_start:
    {
        raw1394_destroy_handle (src->handle);
        src->handle = NULL;
        iec61883_mpeg2_close (src->iec61883mpeg2);
        src->iec61883mpeg2 = NULL;
        GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
                           ("can't start 1394 iso receive"));
        return FALSE;
    }
cannot_initialise_dv:
    {
        raw1394_destroy_handle (src->handle);
        src->handle = NULL;
        GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
                           ("can't initialise iec61883 hdv"));
        return FALSE;
    }
}
Example #5
0
    void operator()(raw1394handle_t handle) const
    {
	if (handle)
	    raw1394_destroy_handle(handle);
    }
static int
gst_hdv1394src_discover_avc_node (GstHDV1394Src * src)
{
    int node = -1;
    int i, j = 0;
    int m = src->num_ports;

    if (src->port >= 0) {
        /* search on explicit port */
        j = src->port;
        m = j + 1;
    }

    /* loop over all our ports */
    for (; j < m && node == -1; j++) {
        raw1394handle_t handle;
        struct raw1394_portinfo pinf[16];

        /* open the port */
        handle = raw1394_new_handle ();
        if (!handle) {
            GST_WARNING ("raw1394 - failed to get handle: %s.\n", strerror (errno));
            continue;
        }
        if (raw1394_get_port_info (handle, pinf, 16) < 0) {
            GST_WARNING ("raw1394 - failed to get port info: %s.\n",
                         strerror (errno));
            goto next;
        }

        /* tell raw1394 which host adapter to use */
        if (raw1394_set_port (handle, j) < 0) {
            GST_WARNING ("raw1394 - failed to set set port: %s.\n", strerror (errno));
            goto next;
        }

        /* now loop over all the nodes */
        for (i = 0; i < raw1394_get_nodecount (handle); i++) {
            /* are we looking for an explicit GUID ? */
            if (src->guid != 0) {
                if (src->guid == rom1394_get_guid (handle, i)) {
                    node = i;
                    src->port = j;
                    g_free (src->uri);
                    src->uri = g_strdup_printf ("dv://%d", src->port);
                    break;
                }
            } else {
                rom1394_directory rom_dir;

                /* select first AV/C Tape Recorder Player node */
                if (rom1394_get_directory (handle, i, &rom_dir) < 0) {
                    GST_WARNING ("error reading config rom directory for node %d\n", i);
                    continue;
                }
                if ((rom1394_get_node_type (&rom_dir) == ROM1394_NODE_TYPE_AVC) &&
                        avc1394_check_subunit_type (handle, i, AVC1394_SUBUNIT_TYPE_VCR)) {
                    node = i;
                    src->port = j;
                    src->guid = rom1394_get_guid (handle, i);
                    g_free (src->uri);
                    src->uri = g_strdup_printf ("dv://%d", src->port);
                    g_free (src->device_name);
                    src->device_name = g_strdup (rom_dir.label);
                    break;
                }
                rom1394_free_directory (&rom_dir);
            }
        }
next:
        raw1394_destroy_handle (handle);
    }
    return node;
}
Example #7
0
int cpi_enumerate_devices( unicap_device_t *device, int index )
{
    raw1394handle_t raw1394handle;
    int numcards;
    struct raw1394_portinfo portinfo[16];
    int current_index = 0;
    int card = 0;

    /* 	TRACE( "dcam_enumerate_devices ( i = %d ) \n", index ); */

    raw1394handle = raw1394_new_handle();
    if( !raw1394handle )
    {
        if( !errno )
        {
            TRACE( "dcam: no kernel support\n" );
            return STATUS_NO_DEVICE;
        }
        else
        {
            TRACE( "dcam: can' t get handle\n" );
            return STATUS_NO_DEVICE;
        }
    }

    numcards = raw1394_get_port_info( raw1394handle, portinfo, 16 );
    if( !numcards )
    {
        TRACE( "dcam: no 1394 cards!\n" );

        raw1394_destroy_handle( raw1394handle );
        return STATUS_NO_DEVICE;
    }
    else if( numcards < 0 )
    {
        raw1394_destroy_handle( raw1394handle );
        return STATUS_NO_DEVICE;
    }

    raw1394_destroy_handle( raw1394handle );

    // go through all present cards, search for cameras
    for( card = 0; card < numcards; card++ )
    {
        int nodecount;
        int node = 0;
        if( ( raw1394handle = raw1394_new_handle_on_port( card ) ) == 0 )
        {
            return STATUS_NO_DEVICE;
        }

        raw1394_set_userdata( raw1394handle, 0 );

        TRACE( "dcam: probing card %d\n", card );

        nodecount = raw1394_get_nodecount( raw1394handle );
        for( node = 0; node < nodecount; node++ )
        {
            int unit_directory_count;
            int directory;

            TRACE( "dcam: probing node %d\n", node );

            // shortcut since most devices only have 1 unit directory
            if( _dcam_is_compatible( raw1394handle, node, 0 ) )
            {
                if( index == current_index )
                {
                    unicap_status_t status;
                    status = _dcam_get_device_info( raw1394handle, node, 0, device );
                    if( status == STATUS_SUCCESS )
                    {
                        TRACE( "found dcam\n" );
                        // got the device with the index we want
                        raw1394_destroy_handle( raw1394handle );
                        return status;
                    }
                    else
                    {
                        TRACE( "can not get device info!\n" );
                    }
                }
                current_index++;
                continue;
            }

            unit_directory_count = _dcam_get_directory_count( raw1394handle, node );
            if( unit_directory_count <= 1 )
            {
                TRACE( "directory count <= 1 for node: %d\n", node );
                continue; // try next device
            }

            // scan through all directories of this device
            for( directory = 1; directory < unit_directory_count; directory++ )
            {
                if( _dcam_is_compatible( raw1394handle, node, directory ) )
                {
                    if( index == current_index )
                    {
                        unicap_status_t status;
                        status = _dcam_get_device_info( raw1394handle, node, directory, device );
                        if( status == STATUS_SUCCESS )
                        {
                            // got the device with the index we want
                            raw1394_destroy_handle( raw1394handle );
                            return status;
                        }
                    }
                    current_index++;
                }
            }// for( directory..
        }// for( node..
        raw1394_destroy_handle( raw1394handle );
    }// for( card..

    return STATUS_NO_DEVICE;
}
Example #8
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;
}
Example #9
0
dc1394error_t
platform_capture_stop(platform_camera_t *craw)
{
    dc1394camera_t * camera = craw->camera;
    int err;

    if (craw->capture_is_set>0) {
        // unlisten
        if (ioctl(craw->capture.dma_fd, VIDEO1394_IOC_UNLISTEN_CHANNEL,
                    &(craw->iso_channel)) < 0)
            return DC1394_IOCTL_FAILURE;

        // release
        if (craw->capture.dma_ring_buffer) {
            munmap((void*)craw->capture.dma_ring_buffer,craw->capture.dma_buffer_size);
        }


        while (close(craw->capture.dma_fd) != 0) {
            dc1394_log_debug("waiting for dma_fd to close");
            sleep (1);
        }
        craw->capture.dma_fd = -1;

        free (craw->capture.frames);
        craw->capture.frames = NULL;

        // this dma_device file is allocated by the strdup() function and can be freed here without problems.
        free(craw->capture.dma_device_file);
        craw->capture.dma_device_file=NULL;

        // capture is not set anymore
        craw->capture_is_set=0;

        // free ressources 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;

        // stop ISO if it was started automatically
        if (craw->iso_auto_started>0) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
            craw->iso_auto_started=0;
        }

        // free the additional capture handle
        raw1394_destroy_handle(craw->capture.handle);
    }
    else {
        return DC1394_CAPTURE_IS_NOT_SET;
    }

    return DC1394_SUCCESS;
}
int main(int argc, char** argv)
{
    int rc; /**< return code */
    int port = 0;  /*!< fw handle port number */
    int nodeid = 0;   /*!< arm server node id */

    // parse command line (port number)
    opterr = 0;  // getopt no err output
    const char short_options[] = "hp:n:";
    int next_opt;
    do {
        next_opt = getopt(argc, argv, short_options);
        switch(next_opt)
        {
        case 'h':
            print_usage();
            return EXIT_SUCCESS;
            break;
        case 'p':
            port = atoi(optarg);
            break;
        case 'n':
            nodeid = atoi(optarg);
            break;
        case '?':
            std::cerr << "Invalid argument" << std::endl;
            break;
        default:
            break;
        }
    }
    while(next_opt != -1);


    // ----- Get handle and set port for the handle -------
    // create handle
    handle = raw1394_new_handle();
    if (handle == NULL) {
        std::cerr << "**** Error: could not create 1394 handle " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // get port number & sanity check
    int numPorts = raw1394_get_port_info(handle, NULL, 0);
    if (port < 0 || port >= numPorts) {
        std::cerr << "Invalid port number" << std::endl;
        return EXIT_FAILURE;
    }

    // let user to choose which port to use
    rc = raw1394_set_port(handle, port);
    if (rc) {
        std::cerr << "**** Error: failed to set port " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }


    // -------- Set FireWire bus reset handler --------

    // set bus reset handler
    raw1394_set_bus_reset_handler(handle, my_bus_reset_handler);



    // ----------------------------------------------------------------------------
    // Start tutorial 4 async broadcast
    // ----------------------------------------------------------------------------

    /**
     *
     */
    // ----- receving end -------------
    unsigned char channel = 0x5;
    raw1394_iso_dma_recv_mode mode = RAW1394_DMA_DEFAULT;

    raw1394_iso_recv_init(handle,
                          my_iso_recv_handler,
                          BUFFER,      // buf_packets
                          PACKET_MAX,  // max_packet_size
                          channel,     // channel
                          mode,        // dma mode
                          -1);         // irq_interval

    // start receiving
    raw1394_iso_recv_start(handle, -1, -1, 0);
    while (true)
    {
        rc = raw1394_loop_iterate(handle);
        if (rc) break;
    }

    // stop, clean up & exit
    raw1394_iso_stop(handle);
    raw1394_iso_shutdown(handle);
    raw1394_destroy_handle(handle);

    return EXIT_SUCCESS;
}