static int dc1394_setup( struct dc1394_input *conf ) { raw1394handle_t raw_handle; nodeid_t *camera_nodes = NULL; int numPorts; int actual_count = 0, c, i; struct raw1394_portinfo ports[16]; raw_handle = raw1394_new_handle(); if( ! raw_handle ) { spook_log( SL_ERR, "dc1394: unable to acquire a raw1394 handle" ); return -1; } numPorts = raw1394_get_port_info( raw_handle, ports, 16 ); raw1394_destroy_handle( raw_handle ); for( i = 0; i < numPorts; ++i ) { int camCount = 0; raw_handle = raw1394_new_handle(); raw1394_set_port( raw_handle, i ); camera_nodes = dc1394_get_camera_nodes( raw_handle, &camCount, 1 ); raw1394_destroy_handle( raw_handle ); spook_log( SL_INFO, "dc1394: found %d cams on port %d", camCount, i ); for( c = 0; c < camCount; ++c ) { if( cam_setup( conf, actual_count, i, camera_nodes[c], c ) < 0 ) return -1; if( ++actual_count == conf->cam_count ) return 0; } // this doesn't work, fix later (just a li'l memory leak...) //dc1394_free_camera_nodes( camera_nodes ); } if( actual_count == 0 ) { spook_log( SL_ERR, "dc1394: did not find any IIDC cameras" ); return -1; } if( actual_count < conf->cam_count ) spook_log( SL_WARN, "dc1394: only found %d cameras, some outputs will be inactive", actual_count ); return 0; }
bool FirewirePort::Init(void) { // create firewire port handle handle = raw1394_new_handle(); handle_bc = raw1394_new_handle(); if (!handle || !handle_bc) { outStr << "FirewirePort: could not create handle" << std::endl; return false; } PortListType::const_iterator it; for (it = PortList.begin(); it != PortList.end(); it++) { if ((*it)->PortNum == PortNum) outStr << "WARNING: Firewire port " << PortNum << " is already used (be careful about thread safety)" << std::endl; if ((*it)->handle == handle) // should never happen outStr << "WARNING: Firewire handle is already used" << std::endl; } PortList.push_back(this); memset(Node2Board, BoardIO::MAX_BOARDS, sizeof(Node2Board)); // set the bus reset handler old_reset_handler = raw1394_set_bus_reset_handler(handle, reset_handler); old_reset_handler = raw1394_set_bus_reset_handler(handle_bc, reset_handler); // get number of ports int nports = raw1394_get_port_info(handle, NULL, 0); outStr << "FirewirePort: number of ports = " << nports << std::endl; if (nports < PortNum) { outStr << "FirewirePort: port " << PortNum << " does not exist" << std::endl; raw1394_destroy_handle(handle); handle = NULL; return false; } if (raw1394_set_port(handle, PortNum) || raw1394_set_port(handle_bc, PortNum)) { outStr << "FirewirePort: error setting port to " << PortNum << std::endl; raw1394_destroy_handle(handle); raw1394_destroy_handle(handle_bc); handle = NULL; handle_bc = NULL; return false; } outStr << "FirewirePort: successfully initialized port " << PortNum << std::endl; // stop cycle start packet StopCycleStartPacket(); return ScanNodes(); }
int CameraDcam::getFirewirePortnum(void) { /* * handling of ports not yet correct. * variable not used as intended. */ raw1394handle_t handle; //handle to raw 1394 bus struct raw1394_portinfo ports[MAX_PORTS]; //try to open raw 1394 handle handle = raw1394_new_handle(); if ( handle == NULL) { GDOS_ERROR("error: No raw1394 handle found.\n"); return -DC1394_SUCCESS; } //get number of available ports firewireNumPorts = raw1394_get_port_info(handle, ports, firewireNumPorts); GDOS_DBG_INFO( "got portnum from 1394 bus.\n"); raw1394_destroy_handle(handle); handle = NULL; return DC1394_SUCCESS; }
void icvInitCapture_DC1394(){ int p; _V_MW_ fprintf(stderr,"icvInitCapture_DC1394\n"); raw1394handle_t raw_handle = raw1394_new_handle(); if( raw_handle == 0 ) { numPorts = 0; return; } numPorts = raw1394_get_port_info(raw_handle, ports, MAX_PORTS); raw1394_destroy_handle(raw_handle); for (p = 0; p < numPorts; p++) { handles[p] = dc1394_create_handle(p); if (handles[p]==NULL) { numPorts=-1; return; /*ERROR_CLEANUP_EXIT*/ } /* get the camera nodes and describe them as we find them */ camera_nodes = dc1394_get_camera_nodes(handles[p], &camCount[p], 0); for (int i=0;i<camCount[p];i++) { cameras[numCameras].cam.node = camera_nodes[i]; cameras[numCameras].portnum = p; dc1394_stop_iso_transmission(handles[p], camera_nodes[i]); numCameras++; } } };
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; } }
static void resetBus() { //cleanup primitive resources. required if the last user abruptly //terminated. this method isn't ideal since it just resets the first bus, //even though there might be more (there aren't on our robot, though). raw1394handle_t handle = raw1394_new_handle(); if(!handle) { CV_Error(CV_StsError, "unable to open raw1394 handle (is there a bus available on this computer?)"); } const int numPorts = raw1394_get_port_info(handle, NULL, 0); if(numPorts < 1) { raw1394_destroy_handle(handle); CV_Error(CV_StsError, "no raw1394 ports"); } raw1394_set_port(handle, 0); raw1394_reset_bus(handle); raw1394_destroy_handle(handle); }
int main(int argc, char **argv) { raw1394handle_t handle; parse_args(argc, argv); fprintf(stderr, "port: %ld\nloops: %ld\nfile: %s\n", which_port, loopcount, filename); handle = raw1394_new_handle(); if (!handle) { if (!errno) fprintf(stderr, "No working kernel driver found.\n"); else perror("raw1394_get_handle"); exit(1); } do { if (raw1394_get_port_info(handle, NULL, 0) <= which_port) { fprintf(stderr, "Port %ld does not exist.\n", which_port); exit(1); } raw1394_set_port(handle, which_port); } while (errno == ESTALE); if (errno) { perror("raw1394_set_port"); exit(1); } if (filename) send_iso_file(handle); fprintf(stderr, "\n"); raw1394_iso_shutdown(handle); raw1394_destroy_handle(handle); return 0; }
bool linuxfwCamera::findCamera() { // get the number of ports raw1394handle_t phandle = raw1394_new_handle(); if (phandle==NULL) { printf( "no firewire ports found\n"); return false; } struct raw1394_portinfo pinf; int ports = raw1394_get_port_info(phandle, &pinf, 0); dc1394_destroy_handle(phandle); //printf("firewire ports: %d\n",ports); if (ports<1) { printf("no firewire ports found\n"); return false; } // open ohci and asign handle to it for (int i=0;i<ports;i++) { //printf("trying port %d\n",i); handle = dc1394_create_handle(i); // get the camera nodes and describe them as we find them numNodes = raw1394_get_nodecount(handle); camera_nodes = dc1394_get_camera_nodes(handle,&numCameras,0); //fflush(stdout); //printf("found %d cameras\n",numCameras); if (numCameras<1) { dc1394_destroy_handle(handle); continue; } else { cameraID = 0; return true; } } fprintf( stderr, "no firewire camera found\n"); return false; }
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; }
/** 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; }
/** Open the raw1394 device and get a handle. * * \param port A 0-based number indicating which host adapter to use. * \return a raw1394 handle. */ int raw1394_get_num_ports( void ) { int n_ports; struct raw1394_portinfo pinf[ 16 ]; raw1394handle_t handle; /* get a raw1394 handle */ if ( !( handle = raw1394_new_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 ); } raw1394_destroy_handle( handle ); return n_ports; }
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; }
void AVC1394Control::initialize() { int i; current_command = COMMAND_NONE; device = -1; device_lock = new Mutex("AVC1394Control::device_lock"); #ifdef RAW1394_V_0_8 handle = raw1394_get_handle(); #else handle = raw1394_new_handle(); #endif //printf("AVC1394Control::initialize(): 1\n"); if(!handle) { //printf("AVC1394Control::initialize(): 2\n"); if(!errno) { //printf("AVC1394Control::initialize(): 3\n"); fprintf(stderr, "AVC1394Control::initialize(): Not Compatable!\n"); } else { //printf("AVC1394Control::initialize(): 4\n"); fprintf(stderr, "AVC1394Control::initialize(): couldn't get handle\n"); } return; } if(raw1394_set_port(handle, 0) < 0) { //printf("AVC1394Control::initialize(): 5\n"); perror("AVC1394Control::initialize(): couldn't set port"); // raw1394_destroy_handle(handle); return; } for(i = 0; i < raw1394_get_nodecount(handle); i++) { if(rom1394_get_directory(handle, i, &rom_dir) < 0) { //printf("AVC1394Control::initialize(): 6\n"); fprintf(stderr, "AVC1394Control::initialize(): node %d\n", i); // raw1394_destroy_handle(handle); return; } if((rom1394_get_node_type(&rom_dir) == ROM1394_NODE_TYPE_AVC) && avc1394_check_subunit_type(handle, i, AVC1394_SUBUNIT_TYPE_VCR)) { //printf("AVC1394Control::initialize(): 7\n"); device = i; break; } } if(device == -1) { //printf("AVC1394Control::initialize(): 8\n"); fprintf(stderr, "AVC1394Control::initialize(): No AV/C Devices\n"); // raw1394_destroy_handle(handle); return; } }
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; }
/***************************************************************************** * 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) { raw1394handle_t handle; int retval; quadlet_t rom[0x100]; size_t rom_size; unsigned char rom_version; rom1394_directory dir; char *(leaf[2]); handle = raw1394_new_handle(); if (!handle) { if (!errno) { printf(not_compatible); } else { perror("couldn't get handle"); printf(not_loaded); } exit(EXIT_FAILURE); } if (raw1394_set_port(handle, 0) < 0) { perror("couldn't set port"); exit(EXIT_FAILURE); } /* get the current rom image */ retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); rom_size = rom1394_get_size(rom); printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); /* get the local directory */ rom1394_get_directory( handle, raw1394_get_local_id(handle) & 0x3f, &dir); /* free the allocated mem for the textual leaves */ rom1394_free_directory( &dir); /* add an RFC 2734 unit directory */ dir.unit_spec_id = 0x0000005e; dir.unit_sw_version = 0x00000001; leaf[0] = "IANA"; leaf[1] = "IPv4"; dir.nr_textual_leafs = 2; dir.textual_leafs = leaf; /* manipulate the rom */ retval = rom1394_add_unit( rom, &dir); /* get the computed size of the rom image */ rom_size = rom1394_get_size(rom); printf("rom1394_add_unit_directory returned %d, romsize %d:",retval,rom_size); /* convert computed rom size from quadlets to bytes before update */ rom_size *= sizeof(quadlet_t); retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version); printf("update_config_rom returned %d\n",retval); printf("You need to reload your ieee1394 modules to reset the rom.\n"); raw1394_reset_bus(handle); exit(EXIT_SUCCESS); }
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; }
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 6 isochronous send // ---------------------------------------------------------------------------- /** * raw1394_iso_xmit_init - initialize isochronous transmission * @handle: libraw1394 handle * @handler: handler function for queueing packets * @buf_packets: number of isochronous packets to buffer * @max_packet_size: largest packet you need to handle, in bytes * (not including the isochronous header) * @channel: isochronous channel on which to transmit * @speed: speed at which to transmit * @irq_interval: maximum latency of wake-ups, in packets (-1 if you don't care) * * Allocates all user and kernel resources necessary for isochronous transmission. * Channel and bandwidth allocation at the IRM is not performed. * * Returns: 0 on success or -1 on failure (sets errno) **/ size_t length; unsigned char channel, tag, sy; unsigned char buffer[BUF_SIZE + BUF_HEAD]; channel = 5; tag = 6; sy = 7; // ----- transmitting end ------------- rc = raw1394_iso_xmit_init(handle, // 1394 handle NULL, // xmit handler BUFFER, // iso packets to buffer MAX_PACKET, // max packet size channel, // just pick 5 for fun RAW1394_ISO_SPEED_400, -1); // irq_interval if (rc) { perror("raw1394_iso_xmit_init"); exit(1); } rc = raw1394_iso_xmit_start(handle, -1, -1); if (rc) { perror("raw1394_iso_xmit_start"); exit(1); } quadlet_t data = 0x0; while (true) { rc = raw1394_iso_xmit_write(handle, (unsigned char *)&data, 4, tag, sy); if (rc) { perror("\nraw1394_iso_xmit_write"); break; } // data++; // std::cout << "data = " << data << std::endl; } // stop, clean up & exit raw1394_iso_stop(handle); raw1394_iso_shutdown(handle); raw1394_destroy_handle(handle); return EXIT_SUCCESS; }
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; } }
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; }
/***************************************************************************** * 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; }
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; }
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); }