int cpi_open( void **cpi_data, unicap_device_t *device ) { dcam_handle_t dcamhandle; unicap_status_t status; int port, node, directory; int i_tmp; char *env; int is_initializing; struct timeval init_timeout; *cpi_data = malloc( sizeof( struct _dcam_handle ) ); if( !*cpi_data ) { return STATUS_NO_MEM; } dcamhandle = (dcam_handle_t) *cpi_data; memset( dcamhandle, 0x0, sizeof( struct _dcam_handle ) ); TIME("dcam_find_device", { status = _dcam_find_device( device, &port, &node, &directory ); if( !SUCCESS( status ) ) { TRACE( "cpi_open: Could not find device\n" ); free( *cpi_data ); return status; } }
/* bus reset handler checks if device is still on the bus. if it is removed -> set device_present to 0 . bandwidth and channel are remotely freed on bus reset if device still present -> reallocate bw and channel -> channel is not guarranted to be the same after reallocation -> set new channel to camera if changed */ int dcam_busreset_handler( raw1394handle_t raw1394handle, unsigned int generation ) { dcam_handle_t dcamhandle = ( dcam_handle_t ) raw1394_get_userdata( raw1394handle ); int port; int channel; raw1394_update_generation( raw1394handle, generation ); // check if the device is still there or if it has changed if( _dcam_find_device( &dcamhandle->unicap_device, &port, &dcamhandle->node, &dcamhandle->directory ) != STATUS_SUCCESS ) { dcamhandle->device_present = 0; dcam_device_removed_event( dcamhandle ); return 0; } // what happens if a PC-Card is removed ? does this change the port??? if( port != dcamhandle->port ) { if( raw1394_set_port( raw1394handle, port ) < 0 ) { dcamhandle->device_present = 0; dcam_device_removed_event( dcamhandle ); return 0; } dcamhandle->port = port; } // reallocate bandwidth // ( reallocation should always succeed ) if( dcamhandle->allocate_bandwidth ) { if( !SUCCESS(_1394util_allocate_bandwidth( dcamhandle->raw1394handle, dcam_isoch_table[dcamhandle->current_iso_index].bytes_per_packet ) ) ) { TRACE( "dcam.cpi: failed to reallocate bandwidth\n" ); dcam_capture_stop( dcamhandle ); return 0; } } // channel is freed on busreset // -> reallocate channel // check if newly allocated channel matches previous channel // -> conditionaly set new channel on the camera if( !SUCCESS(_1394util_allocate_channel(dcamhandle->raw1394handle, dcamhandle->channel_allocated ) ) ) { if( ( channel = _1394util_find_free_channel( dcamhandle->raw1394handle ) ) < 0 ) { TRACE( "dcam.cpi: failed to allocate channel\n"); _1394util_free_bandwidth( dcamhandle->raw1394handle, dcam_isoch_table[dcamhandle->current_iso_index].bytes_per_packet ); dcam_capture_stop( dcamhandle ); return 0; } if( channel != dcamhandle->channel_allocated ) { quadlet_t quad = 0; if( dcam_isoch_table[dcamhandle->current_iso_index].min_speed <= S400 ) { quad = ( channel << 28 ) | ( S400 << 24 ); } else { quad = ( channel << 28 ) | ( dcam_isoch_table[dcamhandle->current_iso_index].min_speed << 24 ); } if( _dcam_write_register( dcamhandle->raw1394handle, dcamhandle->node, dcamhandle->command_regs_base + 0x60c, quad ) < 0 ) { _1394util_free_channel( dcamhandle->raw1394handle, channel ); _1394util_free_bandwidth( dcamhandle->raw1394handle, dcam_isoch_table[dcamhandle->current_iso_index].bytes_per_packet ); return 0; } } } return 0; }