Ejemplo n.º 1
0
int
iec61883_dv_recv_start (struct iec61883_dv *dv, int channel)
{
	int result = 0;
	
	assert (dv != NULL);
	result = raw1394_iso_recv_init (dv->handle, 
		dv_recv_handler,
		dv->buffer_packets, 
		DIF_BLOCK_SIZE + 8,
		channel,
		RAW1394_DMA_PACKET_PER_BUFFER,
		dv->irq_interval);
	
	if (result == 0) {
		dv->total_dropped = 0;
		dv->channel = channel;
		result = raw1394_iso_recv_start (dv->handle, -1, -1, 0);
	}
	return result;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
Archivo: dv.c Proyecto: 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;
}
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;
}