Esempio n. 1
0
int discoverAVC( int* port, octlet_t guid )
{
	rom1394_directory rom_dir;
	raw1394handle_t handle;
	int device = -1;
	int i, j = 0;
	int m = raw1394_get_num_ports();

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

	for ( ; j < m && device == -1; j++ )
	{
		handle = raw1394_open( j );
		for ( i = 0; i < raw1394_get_nodecount( handle ); ++i )
		{
			if ( guid != 0 )
			{
				/* select explicitly by GUID */
				if ( guid == rom1394_get_guid( handle, i ) )
				{
					device = i;
					*port = j;
					break;
				}
			}
			else
			{
				/* select first AV/C Tape Reccorder Player node */
				if ( rom1394_get_directory( handle, i, &rom_dir ) < 0 )
				{
					fprintf( stderr, "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 ) )
				{
					device = i;
					*port = j;
					break;
				}
			}
		}
		raw1394_close( handle );
	}

	return device;
}
static void
gst_hdv1394src_update_device_name (GstHDV1394Src * src)
{
    raw1394handle_t handle;
    gint portcount, port, nodecount, node;
    rom1394_directory directory;

    g_free (src->device_name);
    src->device_name = NULL;

    GST_LOG_OBJECT (src, "updating device name for current GUID");

    handle = raw1394_new_handle ();

    if (handle == NULL)
        goto gethandle_failed;

    portcount = raw1394_get_port_info (handle, NULL, 0);
    for (port = 0; port < portcount; port++) {
        if (raw1394_set_port (handle, port) >= 0) {
            nodecount = raw1394_get_nodecount (handle);
            for (node = 0; node < nodecount; node++) {
                if (src->guid == rom1394_get_guid (handle, node)) {
                    if (rom1394_get_directory (handle, node, &directory) >= 0) {
                        g_free (src->device_name);
                        src->device_name = g_strdup (directory.label);
                        rom1394_free_directory (&directory);
                        goto done;
                    } else {
                        GST_WARNING ("error reading rom directory for node %d", node);
                    }
                }
            }
        }
    }

    src->device_name = g_strdup ("Unknown");      /* FIXME: translate? */

done:

    raw1394_destroy_handle (handle);
    return;

    /* ERRORS */
gethandle_failed:
    {
        GST_WARNING ("failed to get raw1394 handle: %s", g_strerror (errno));
        src->device_name = g_strdup ("Unknown");    /* FIXME: translate? */
        return;
    }
}
/*
 * When an ieee1394 bus reset happens, usually a device has been removed
 * or added.  We send a message on the message bus with the node count
 * and whether the capture device used in this element connected, disconnected
 * or was unchanged
 * Message structure:
 * nodecount - integer with number of nodes on bus
 * current-device-change - integer (1 if device connected, 0 if no change to
 *                         current device status, -1 if device disconnected)
 */
static int
gst_hdv1394src_bus_reset (raw1394handle_t handle, unsigned int generation)
{
    GstHDV1394Src *src;
    gint nodecount;
    GstMessage *message;
    GstStructure *structure;
    gint current_device_change;
    gint i;

    src = gst_hdv1394src_from_raw1394handle (handle);

    GST_INFO_OBJECT (src, "have bus reset");

    /* update generation - told to do so by docs */
    raw1394_update_generation (handle, generation);
    nodecount = raw1394_get_nodecount (handle);
    /* allocate memory for portinfo */

    /* current_device_change is -1 if camera disconnected, 0 if other device
     * connected or 1 if camera has now connected */
    current_device_change = -1;
    for (i = 0; i < nodecount; i++) {
        if (src->guid == rom1394_get_guid (handle, i)) {
            /* Camera is with us */
            GST_DEBUG ("Camera is with us");
            if (!src->connected) {
                current_device_change = 1;
                src->connected = TRUE;
            } else
                current_device_change = 0;
        }
    }
    if (src->connected && current_device_change == -1) {
        GST_DEBUG ("Camera has disconnected");
        src->connected = FALSE;
    } else if (!src->connected && current_device_change == -1) {
        GST_DEBUG ("Camera is still not with us");
        current_device_change = 0;
    }

    structure = gst_structure_new ("ieee1394-bus-reset", "nodecount", G_TYPE_INT,
                                   nodecount, "current-device-change", G_TYPE_INT, current_device_change,
                                   NULL);
    message = gst_message_new_element (GST_OBJECT (src), structure);
    gst_element_post_message (GST_ELEMENT (src), message);

    return 0;
}
Esempio n. 4
0
static GValueArray *
gst_1394_get_guid_array (void)
{
  GValueArray *result = NULL;
  raw1394handle_t handle = NULL;
  int num_ports = 0;
  int port = 0;
  int num_nodes = 0;
  int node = 0;
  rom1394_directory directory;
  GValue value = { 0, };

  handle = raw1394_new_handle ();

  if (handle == NULL)
    return NULL;

  num_ports = raw1394_get_port_info (handle, NULL, 0);
  for (port = 0; port < num_ports; port++) {
    if (raw1394_set_port (handle, port) >= 0) {
      num_nodes = raw1394_get_nodecount (handle);
      for (node = 0; node < num_nodes; node++) {
        rom1394_get_directory (handle, node, &directory);
        if (rom1394_get_node_type (&directory) == ROM1394_NODE_TYPE_AVC &&
            avc1394_check_subunit_type (handle, node,
                AVC1394_SUBUNIT_TYPE_VCR)) {
          if (result == NULL)
            result = g_value_array_new (3);     /* looks like a sensible default */
          g_value_init (&value, G_TYPE_UINT64);
          g_value_set_uint64 (&value, rom1394_get_guid (handle, node));
          g_value_array_append (result, &value);
          g_value_unset (&value);
        }
      }
    }
  }

  return result;
}
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;
}