Example #1
0
iec61883_dv_t
iec61883_dv_recv_init (raw1394handle_t handle, 
		iec61883_dv_recv_t put_data,
		void *callback_data)
{
	struct iec61883_dv *dv;

	assert (handle != NULL);
	dv = malloc (sizeof (struct iec61883_dv));
	if (!dv) {
		errno = ENOMEM;
		return NULL;
	}
	
	dv->channel = -1;
	dv->handle = handle;
	dv->put_data = put_data;
	dv->get_data = NULL;
	dv->callback_data = callback_data;
	dv->buffer_packets = 1000;
	dv->irq_interval = 250;
	dv->synch = 0;
	dv->speed = RAW1394_ISO_SPEED_100;

	raw1394_set_userdata (handle, dv);
	
	return dv;
}
Example #2
0
iec61883_dv_t
iec61883_dv_xmit_init (raw1394handle_t handle, 
		int is_pal,
		iec61883_dv_xmit_t get_data,
		void *callback_data)
{
	/* DV is composed of DIF blocks, each 480 bytes */
	int dbs = DIF_BLOCK_SIZE / sizeof (quadlet_t);
	int fdf = is_pal ? 0x80 : 0x00;
	int syt_interval = is_pal ? 300 : 250;
	int rate = syt_interval * (is_pal ? 25 : 30000.0/1001.0);
	struct iec61883_dv *dv;

	assert (handle != NULL);
	dv = malloc (sizeof (struct iec61883_dv));
	if (!dv) {
		errno = ENOMEM;
		return NULL;
	}
	
	dv->channel = -1;
	dv->handle = handle;
	dv->put_data = NULL;
	dv->get_data = get_data;
	dv->callback_data = callback_data;
	dv->buffer_packets = 1000;
	dv->prebuffer_packets = 1000;
	dv->irq_interval = 250;
	dv->synch = 0;
	dv->speed = RAW1394_ISO_SPEED_100;

	iec61883_cip_init (&dv->cip, IEC61883_FMT_DV, fdf, rate, dbs, syt_interval);

	iec61883_cip_set_transmission_mode (&dv->cip, IEC61883_MODE_NON_BLOCKING);

	raw1394_set_userdata (handle, dv);
	
	return dv;
}
Example #3
0
/** Open the raw1394 device and get a handle.
 *  
 * \param port A 0-based number indicating which host adapter to use.
 * \return a raw1394 handle.
 */
raw1394handle_t raw1394_open( int port )
{
	int n_ports;
	struct raw1394_portinfo pinf[ 16 ];
	raw1394handle_t handle;

	/* get a raw1394 handle */
#ifdef RAW1394_V_0_8

	handle = raw1394_get_handle();
#else

	handle = raw1394_new_handle();
#endif

	if ( !handle )
	{
		fprintf( stderr, "raw1394 - failed to get handle: %s.\n", strerror( errno ) );
		exit( EXIT_FAILURE );
	}

	if ( ( n_ports = raw1394_get_port_info( handle, pinf, 16 ) ) < 0 )
	{
		fprintf( stderr, "raw1394 - failed to get port info: %s.\n", strerror( errno ) );
		raw1394_destroy_handle( handle );
		exit( EXIT_FAILURE );
	}

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

	raw1394_set_userdata( handle, ( void* ) port );
	return handle;
}
Example #4
0
File: dv.c Project: 0xheart0/vlc
/*****************************************************************************
 * Open: open the file
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    access_t     *p_access = (access_t*)p_this;
    access_sys_t *p_sys;

    struct raw1394_portinfo port_inf[ 16 ];

    msg_Dbg( p_access, "opening device" );

    /* Set up p_access */
    access_InitFields( p_access );
    ACCESS_SET_CALLBACKS( NULL, Block, Control, NULL );

    p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
    if( !p_sys )
        return VLC_EGENERIC;

    p_sys->i_cards = 0;
    p_sys->i_node = 0;
    p_sys->i_port = 0;
    p_sys->i_guid = 0;
    p_sys->i_channel = 63;
    p_sys->p_raw1394 = NULL;
    p_sys->p_avc1394 = NULL;
    p_sys->p_frame = NULL;
    p_sys->p_ev = NULL;

    vlc_mutex_init( &p_sys->lock );

    p_sys->i_node = DiscoverAVC( p_access, &p_sys->i_port, p_sys->i_guid );
    if( p_sys->i_node < 0 )
    {
        msg_Err( p_access, "failed to open a Firewire (IEEE1394) connection" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    p_sys->p_avc1394 = AVCOpen( p_access, p_sys->i_port );
    if( !p_sys->p_avc1394 )
    {
        msg_Err( p_access, "no Digital Video Control device found" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    p_sys->p_raw1394 = raw1394_new_handle();
    if( !p_sys->p_raw1394 )
    {
        msg_Err( p_access, "no Digital Video device found" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    p_sys->i_cards = raw1394_get_port_info( p_sys->p_raw1394, port_inf, 16 );
    if( p_sys->i_cards < 0 )
    {
        msg_Err( p_access, "failed to get port info" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    if( raw1394_set_port( p_sys->p_raw1394, p_sys->i_port ) < 0 )
    {
        msg_Err( p_access, "failed to set port info" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    if ( raw1394_iso_recv_init( p_sys->p_raw1394, Raw1394Handler,
                ISOCHRONOUS_QUEUE_LENGTH, ISOCHRONOUS_MAX_PACKET_SIZE,
                p_sys->i_channel, RAW1394_DMA_PACKET_PER_BUFFER, -1 ) < 0 )
    {
        msg_Err( p_access, "failed to init isochronous recv" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    raw1394_set_userdata( p_sys->p_raw1394, p_access );
    raw1394_iso_recv_start( p_sys->p_raw1394, -1, -1, 0 );

    p_sys->raw1394_poll.fd = raw1394_get_fd( p_sys->p_raw1394 );
    p_sys->raw1394_poll.events = POLLIN | POLLPRI;

    /* Now create our event thread catcher */
    p_sys->p_ev = calloc( 1, sizeof( *p_sys->p_ev ) );
    if( !p_sys->p_ev )
    {
        msg_Err( p_access, "failed to create event thread struct" );
        Close( p_this );
        return VLC_ENOMEM;
    }

    p_sys->p_ev->p_frame = NULL;
    p_sys->p_ev->pp_last = &p_sys->p_ev->p_frame;
    p_sys->p_ev->p_access = p_access;
    vlc_mutex_init( &p_sys->p_ev->lock );
    if( vlc_clone( &p_sys->p_ev->thread, Raw1394EventThread,
               p_sys->p_ev, VLC_THREAD_PRIORITY_OUTPUT ) )
    {
        msg_Err( p_access, "failed to clone event thread" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    return VLC_SUCCESS;
}
Example #5
0
bool firewire_source::try_open()
{
    auto_raw1394 handle(raw1394_new_handle());
    if (!handle.get())
	return false;
    raw1394_set_userdata(handle.get(), this);

    int n_ports = raw1394_get_port_info(handle.get(), NULL, 0);
    std::vector<raw1394_portinfo> ports(n_ports);
    if (n_ports > 0)
    {
	int n_ports_again =
	    raw1394_get_port_info(handle.get(), &ports[0], n_ports);
	if (n_ports > n_ports_again)
	{
	    n_ports = n_ports_again;
	    ports.resize(n_ports);
	}
    }
    if (n_ports == 0)
    {
	fprintf(stderr, "ERROR: No Firewire ports accessible\n");
	return false;
    }

    // Try converting name to an integer
    char * end;
    int i = strtoul(port_name_.c_str(), &end, 10);

    // If we didn't convert the whole string, assume it really is a name
    if (*end)
	for (i = 0; i != n_ports; ++i)
	    if (port_name_ == ports[i].name)
		break;

    if (i >= n_ports)
    {
	fprintf(stderr, "ERROR: %s: not found\n", port_name_.c_str());
	return false;
    }

    if (verbose)
	printf("INFO: Reading from Firewire port %s\n", ports[i].name);

    if (raw1394_set_port(handle.get(), i))
    {
	perror("raw1394_set_port");
	return false;
    }

    if (raw1394_iso_recv_init(handle.get(), raw_receive, /*buf_packets=*/ 600,
			      /*max_packet_size=*/
			      CIF_HEADER_SIZE + CIF_PACKET_SIZE + 8,
			      /*channel=*/ 63,
			      /*mode=*/ RAW1394_DMA_DEFAULT,
			      /*irq_interval=*/ 100))
    {
	perror("raw1394_iso_recv_init");
	return false;
    }

    if (raw1394_iso_recv_start(handle.get(), -1, -1, -1))
    {
	perror("raw1394_iso_recv_start");
	raw1394_iso_shutdown(handle.get()); // see comment on destructor
	return false;
    }

    handle_ = handle;
    return true;
}
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 #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;
}