Index: /trunk/libffado/src/libieee1394/ieee1394service.h =================================================================== --- /trunk/libffado/src/libieee1394/ieee1394service.h (revision 677) +++ /trunk/libffado/src/libieee1394/ieee1394service.h (revision 739) @@ -37,4 +37,5 @@ #include +#include class ARMHandler; @@ -47,6 +48,27 @@ bool initialize( int port ); + /** + * @brief get number of ports (firewire adapters) in this machine + * + * @return the number of ports + */ + static unsigned int detectNbPorts(); + + /** + * @brief get port (adapter) id + * + * @return get port (adapter) id + */ int getPort() - { return m_port; } + { return m_port; } + + /** + * @brief get port (adapter) name + * + * @return get port (adapter) name + */ + std::string getPortName() + { return m_portName; }; + /** * @brief get number of nodes on the bus @@ -238,4 +260,5 @@ raw1394handle_t m_resetHandle; int m_port; + std::string m_portName; pthread_t m_thread; @@ -256,4 +279,5 @@ public: void setVerboseLevel(int l); + void show(); private: DECLARE_DEBUG_MODULE; Index: /trunk/libffado/src/libieee1394/configrom.cpp =================================================================== --- /trunk/libffado/src/libieee1394/configrom.cpp (revision 736) +++ /trunk/libffado/src/libieee1394/configrom.cpp (revision 739) @@ -62,5 +62,5 @@ ConfigRom::ConfigRom( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId ) : Control::Element("ConfigRom") - , m_1394Service( &ieee1394service ) + , m_1394Service( ieee1394service ) , m_nodeId( nodeId ) , m_avcDevice( false ) // FIXME: this does not seem veryu @@ -89,5 +89,5 @@ ConfigRom::ConfigRom() : Control::Element("ConfigRom") - , m_1394Service( 0 ) + , m_1394Service( *(new Ieee1394Service()) ) , m_nodeId( -1 ) , m_avcDevice( false ) // FIXME: this does not seem veryu @@ -114,6 +114,8 @@ } -ConfigRom::~ConfigRom() -{ +Ieee1394Service& +ConfigRom::get1394Service() +{ + return m_1394Service; } @@ -133,5 +135,5 @@ { struct config_csr_info csr_info; - csr_info.service = m_1394Service; + csr_info.service = &m_1394Service; csr_info.nodeId = 0xffc0 | m_nodeId; @@ -140,5 +142,5 @@ &csr_info ); if (!m_csr || csr1212_parse_csr( m_csr ) != CSR1212_SUCCESS) { - debugError( "Could not parse config rom of node %d on port %d\n", m_nodeId, m_1394Service->getPort() ); + debugError( "Could not parse config rom of node %d on port %d\n", m_nodeId, m_1394Service.getPort() ); if (m_csr) { csr1212_destroy_csr(m_csr); @@ -451,9 +453,9 @@ struct csr1212_csr* csr = NULL; for ( fb_nodeid_t nodeId = 0; - nodeId < m_1394Service->getNodeCount(); + nodeId < m_1394Service.getNodeCount(); ++nodeId ) { struct config_csr_info csr_info; - csr_info.service = m_1394Service; + csr_info.service = &m_1394Service; csr_info.nodeId = 0xffc0 | nodeId; debugOutput( DEBUG_LEVEL_VERBOSE, "Looking at node %d...\n", nodeId); @@ -577,5 +579,5 @@ } - pConfigRom->m_1394Service = &ieee1394Service; + pConfigRom->m_1394Service = ieee1394Service; bool result; Index: /trunk/libffado/src/libieee1394/configrom.h =================================================================== --- /trunk/libffado/src/libieee1394/configrom.h (revision 673) +++ /trunk/libffado/src/libieee1394/configrom.h (revision 739) @@ -44,5 +44,7 @@ public: ConfigRom( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId ); - virtual ~ConfigRom(); + virtual ~ConfigRom() {}; + + Ieee1394Service& get1394Service(); bool initialize(); @@ -98,6 +100,4 @@ static bool compareGUID( const ConfigRom& a, const ConfigRom& b ); - void printConfigRom() const; - bool serialize( Glib::ustring path, Util::IOSerialize& ser ); static ConfigRom* deserialize( Glib::ustring path, @@ -105,4 +105,5 @@ Ieee1394Service& ieee1394Service ); + void printConfigRom() const; void setVerboseLevel(int level) { setDebugLevel(level); @@ -117,5 +118,5 @@ void processRootDirectory( struct csr1212_csr* csr ); - Ieee1394Service* m_1394Service; + Ieee1394Service& m_1394Service; fb_nodeid_t m_nodeId; bool m_avcDevice; Index: /trunk/libffado/src/libieee1394/ieee1394service.cpp =================================================================== --- /trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 677) +++ /trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 739) @@ -37,4 +37,6 @@ #include #include + +#define FFADO_MAX_FIREWIRE_PORTS 8 IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL ); @@ -83,4 +85,23 @@ } +unsigned int +Ieee1394Service::detectNbPorts( ) +{ + raw1394handle_t tmp_handle = raw1394_new_handle(); + if ( tmp_handle == NULL ) { + debugError("Could not get libraw1394 handle.\n"); + return 0; + } + struct raw1394_portinfo pinf[FFADO_MAX_FIREWIRE_PORTS]; + int nb_detected_ports = raw1394_get_port_info(tmp_handle, pinf, FFADO_MAX_FIREWIRE_PORTS); + raw1394_destroy_handle(tmp_handle); + + if (nb_detected_ports < 0) { + debugError("Failed to detect number of ports\n"); + return 0; + } + return nb_detected_ports; +} + bool Ieee1394Service::initialize( int port ) @@ -113,4 +134,17 @@ m_port = port; + + // obtain port name + struct raw1394_portinfo pinf[FFADO_MAX_FIREWIRE_PORTS]; + int nb_detected_ports = raw1394_get_port_info(m_handle, pinf, FFADO_MAX_FIREWIRE_PORTS); + + if(nb_detected_ports && port < FFADO_MAX_FIREWIRE_PORTS) { + m_portName = pinf[port].name; + } else { + m_portName = "Unknown"; + } + if (m_portName == "") { + m_portName = "Unknown"; + } raw1394_set_userdata( m_handle, this ); @@ -840,2 +874,9 @@ setDebugLevel(l); } + +void +Ieee1394Service::show() +{ + debugOutput( DEBUG_LEVEL_VERBOSE, "Port: %d\n", getPort() ); + debugOutput( DEBUG_LEVEL_VERBOSE, " Name: %s\n", getPortName().c_str() ); +} Index: /trunk/libffado/src/ffadodevice.cpp =================================================================== --- /trunk/libffado/src/ffadodevice.cpp (revision 734) +++ /trunk/libffado/src/ffadodevice.cpp (revision 739) @@ -33,11 +33,9 @@ #include -IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_VERBOSE ); +IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_NORMAL ); -FFADODevice::FFADODevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) +FFADODevice::FFADODevice( std::auto_ptr( configRom )) : Control::Container() , m_pConfigRom( configRom ) - , m_p1394Service( &ieee1394Service ) { addOption(Util::OptionContainer::Option("id",std::string("dev?"))); @@ -59,6 +57,5 @@ FFADODevice * -FFADODevice::createDevice( Ieee1394Service& , - std::auto_ptr( x )) +FFADODevice::createDevice(std::auto_ptr( x )) { // re-implement this!! @@ -89,4 +86,10 @@ { return *m_pConfigRom; +} + +Ieee1394Service& +FFADODevice::get1394Service() +{ + return getConfigRom().get1394Service(); } @@ -144,10 +147,14 @@ FFADODevice::showDevice() { - debugOutput(DEBUG_LEVEL_NORMAL, "Node...........: %d\n", getNodeId()); - debugOutput(DEBUG_LEVEL_NORMAL, "GUID...........: %s\n", getConfigRom().getGuidString().c_str()); - + Ieee1394Service& s = getConfigRom().get1394Service(); + debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n", + s.getPort(), s.getPortName().c_str()); + debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId()); + debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n", + getConfigRom().getGuidString().c_str()); + std::string id=std::string("dev? [none]"); getOption("id", id); - + debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str()); Index: /trunk/libffado/src/devicemanager.h =================================================================== --- /trunk/libffado/src/devicemanager.h (revision 734) +++ /trunk/libffado/src/devicemanager.h (revision 739) @@ -37,4 +37,5 @@ #include +#include class Ieee1394Service; @@ -47,4 +48,10 @@ typedef std::vector< FFADODevice* >::iterator FFADODeviceVectorIterator; +typedef std::vector< Ieee1394Service* > Ieee1394ServiceVector; +typedef std::vector< Ieee1394Service* >::iterator Ieee1394ServiceVectorIterator; + +typedef std::vector< Functor* > FunctorVector; +typedef std::vector< Functor* >::iterator FunctorVectorIterator; + class DeviceManager : public Util::OptionContainer, @@ -55,8 +62,11 @@ ~DeviceManager(); - bool initialize( int port ); + bool initialize(); bool deinitialize(); - bool discover( ); + bool addSpecString(char *); + bool isSpecStringValid(std::string s); + + bool discover(); bool isValidNode( int node ); @@ -80,5 +90,5 @@ protected: FFADODevice* getDriverForDevice( std::auto_ptr( configRom ), - int id ); + int id ); FFADODevice* getSlaveDriver( std::auto_ptr( configRom ) ); @@ -86,7 +96,11 @@ protected: - Ieee1394Service* m_1394Service; - FFADODeviceVector m_avDevices; - Functor* m_busreset_functor; + // we have one service for each port + // found on the system. We don't allow dynamic addition of ports (yet) + Ieee1394ServiceVector m_1394Services; + FFADODeviceVector m_avDevices; + FunctorVector m_busreset_functors; + + std::vector m_SpecStrings; // debug stuff Index: /trunk/libffado/src/libstreaming/util/IsoHandlerManager.cpp =================================================================== --- /trunk/libffado/src/libstreaming/util/IsoHandlerManager.cpp (revision 729) +++ /trunk/libffado/src/libstreaming/util/IsoHandlerManager.cpp (revision 739) @@ -69,5 +69,5 @@ // propagate the debug level -// m_isoManagerThread->setVerboseLevel(getDebugLevel()); + m_isoManagerThread->setVerboseLevel(getDebugLevel()); return true; @@ -705,4 +705,9 @@ setDebugLevel(i); + // propagate the debug level + if(m_isoManagerThread) { + m_isoManagerThread->setVerboseLevel(getDebugLevel()); + } + for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); it != m_IsoHandlers.end(); Index: /trunk/libffado/src/motu/motu_avdevice.h =================================================================== --- /trunk/libffado/src/motu/motu_avdevice.h (revision 734) +++ /trunk/libffado/src/motu/motu_avdevice.h (revision 739) @@ -125,11 +125,9 @@ public: - MotuDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + MotuDevice(std::auto_ptr( configRom )); virtual ~MotuDevice(); static bool probe( ConfigRom& configRom ); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice(std::auto_ptr( configRom )); static int getConfigurationId( ); virtual bool discover(); Index: /trunk/libffado/src/motu/motu_avdevice.cpp =================================================================== --- /trunk/libffado/src/motu/motu_avdevice.cpp (revision 734) +++ /trunk/libffado/src/motu/motu_avdevice.cpp (revision 739) @@ -186,7 +186,6 @@ }; -MotuDevice::MotuDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FFADODevice( ieee1394Service, configRom ) +MotuDevice::MotuDevice( std::auto_ptr( configRom )) + : FFADODevice( configRom ) , m_motu_model( MOTUFW_MODEL_NONE ) , m_iso_recv_channel ( -1 ) @@ -206,11 +205,9 @@ { // Free ieee1394 bus resources if they have been allocated - if (m_p1394Service != NULL) { - if (m_iso_recv_channel>=0 && !m_p1394Service->freeIsoChannel(m_iso_recv_channel)) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free recv iso channel %d\n", m_iso_recv_channel); - } - if (m_iso_send_channel>=0 && !m_p1394Service->freeIsoChannel(m_iso_send_channel)) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free send iso channel %d\n", m_iso_send_channel); - } + if (m_iso_recv_channel>=0 && !get1394Service().freeIsoChannel(m_iso_recv_channel)) { + debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free recv iso channel %d\n", m_iso_recv_channel); + } + if (m_iso_send_channel>=0 && !get1394Service().freeIsoChannel(m_iso_send_channel)) { + debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free send iso channel %d\n", m_iso_send_channel); } } @@ -242,8 +239,7 @@ FFADODevice * -MotuDevice::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) -{ - return new MotuDevice(ieee1394Service, configRom ); +MotuDevice::createDevice(std::auto_ptr( configRom )) +{ + return new MotuDevice(configRom); } @@ -251,8 +247,8 @@ MotuDevice::discover() { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); -// unsigned int modelId = m_pConfigRom->getModelId(); - unsigned int unitVersion = m_pConfigRom->getUnitVersion(); - unsigned int unitSpecifierId = m_pConfigRom->getUnitSpecifierId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); +// unsigned int modelId = getConfigRom().getModelId(); + unsigned int unitVersion = getConfigRom().getUnitVersion(); + unsigned int unitSpecifierId = getConfigRom().getUnitSpecifierId(); for ( unsigned int i = 0; @@ -504,8 +500,8 @@ // Assign iso channels if not already done if (m_iso_recv_channel < 0) - m_iso_recv_channel = m_p1394Service->allocateIsoChannelGeneric(m_rx_bandwidth); + m_iso_recv_channel = get1394Service().allocateIsoChannelGeneric(m_rx_bandwidth); if (m_iso_send_channel < 0) - m_iso_send_channel = m_p1394Service->allocateIsoChannelGeneric(m_tx_bandwidth); + m_iso_send_channel = get1394Service().allocateIsoChannelGeneric(m_tx_bandwidth); debugOutput(DEBUG_LEVEL_VERBOSE, "recv channel = %d, send channel = %d\n", @@ -515,7 +511,7 @@ // be nice and deallocate if (m_iso_recv_channel >= 0) - m_p1394Service->freeIsoChannel(m_iso_recv_channel); + get1394Service().freeIsoChannel(m_iso_recv_channel); if (m_iso_send_channel >= 0) - m_p1394Service->freeIsoChannel(m_iso_send_channel); + get1394Service().freeIsoChannel(m_iso_send_channel); debugFatal("Could not allocate iso channels!\n"); @@ -524,5 +520,5 @@ m_receiveProcessor=new Streaming::MotuReceiveStreamProcessor( - m_p1394Service->getPort(), event_size_in); + get1394Service().getPort(), event_size_in); // The first thing is to initialize the processor. This creates the @@ -594,5 +590,5 @@ // Do the same for the transmit processor m_transmitProcessor=new Streaming::MotuTransmitStreamProcessor( - m_p1394Service->getPort(), event_size_out); + get1394Service().getPort(), event_size_out); m_transmitProcessor->setVerboseLevel(getDebugLevel()); @@ -940,10 +936,9 @@ */ -quadlet_t quadlet; -assert(m_p1394Service); + quadlet_t quadlet; quadlet = 0; // Note: 1394Service::read() expects a physical ID, not the node id - if (m_p1394Service->read(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &quadlet) < 0) { + if (get1394Service().read(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &quadlet) < 0) { debugError("Error doing motu read from register 0x%06x\n",reg); } @@ -961,5 +956,5 @@ // Note: 1394Service::write() expects a physical ID, not the node id - if (m_p1394Service->write(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &data) < 0) { + if (get1394Service().write(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &data) < 0) { err = 1; debugError("Error doing motu write to register 0x%06x\n",reg); Index: /trunk/libffado/src/ffadodevice.h =================================================================== --- /trunk/libffado/src/ffadodevice.h (revision 674) +++ /trunk/libffado/src/ffadodevice.h (revision 739) @@ -53,10 +53,8 @@ { public: - FFADODevice( Ieee1394Service& ieee1394service, - std::auto_ptr< ConfigRom >( configRom ) ); + FFADODevice( std::auto_ptr< ConfigRom >( configRom ) ); virtual ~FFADODevice(); - /** * @brief Compares the GUID of two FFADODevices @@ -76,9 +74,8 @@ /// Returns the 1394 service of the FFADO device - virtual Ieee1394Service& get1394Service() - { return *m_p1394Service; }; + virtual Ieee1394Service& get1394Service(); /// Returns the ConfigRom object of the device node. virtual ConfigRom& getConfigRom() const; - + /** * @brief Called by DeviceManager to load device model from cache. @@ -114,6 +111,5 @@ * @return a new instance of the AvDevice type, NULL when unsuccessful */ - static FFADODevice * createDevice( Ieee1394Service& , - std::auto_ptr( x )); + static FFADODevice * createDevice( std::auto_ptr( x )); /** @@ -417,8 +413,7 @@ +private: + std::auto_ptr( m_pConfigRom ); protected: - std::auto_ptr( m_pConfigRom ); - Ieee1394Service* m_p1394Service; - DECLARE_DEBUG_MODULE; }; Index: /trunk/libffado/src/SConscript =================================================================== --- /trunk/libffado/src/SConscript (revision 734) +++ /trunk/libffado/src/SConscript (revision 739) @@ -12,5 +12,4 @@ devicemanager.cpp \ ffado.cpp \ - ffado_streaming.cpp \ ffadodevice.cpp \ debugmodule/debugmodule.cpp \ Index: /trunk/libffado/src/ffado.cpp =================================================================== --- /trunk/libffado/src/ffado.cpp (revision 554) +++ /trunk/libffado/src/ffado.cpp (revision 739) @@ -23,4 +23,8 @@ */ +/* + * Implementation of the FFADO external C API + */ + #include "config.h" @@ -31,8 +35,11 @@ #include "devicemanager.h" #include "ffadodevice.h" +#include "libstreaming/StreamProcessorManager.h" #include #include #include +#include +#include DECLARE_GLOBAL_DEBUG_MODULE; @@ -63,79 +70,7 @@ } - int ffado_get_api_version() { return FFADO_API_VERSION; -} - -ffado_handle_t -ffado_new_handle( int port ) -{ - ffado_handle_t handle = new struct ffado_handle; - if (! handle ) { - debugFatal( "Could not allocate memory for new handle\n" ); - return 0; - } - - handle->m_deviceManager = new DeviceManager(); - if ( !handle->m_deviceManager ) { - debugFatal( "Could not allocate device manager\n" ); - delete handle; - return 0; - } - if ( !handle->m_deviceManager->initialize( port ) ) { - debugFatal( "Could not initialize device manager\n" ); - delete handle->m_deviceManager; - delete handle; - return 0; - } - return handle; -} - -int -ffado_destroy_handle( ffado_handle_t ffado_handle ) -{ - delete ffado_handle->m_deviceManager; - delete ffado_handle; - return 0; -} - -int -ffado_discover_devices( ffado_handle_t ffado_handle, int verbose ) -{ - if (verbose) { - ffado_handle->m_deviceManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - } - return ffado_handle->m_deviceManager->discover()? 0 : -1; -} - -int -ffado_node_is_valid_ffado_device( ffado_handle_t ffado_handle, int node_id ) -{ - return ffado_handle->m_deviceManager->isValidNode( node_id ); -} - -int -ffado_get_nb_devices_on_bus( ffado_handle_t ffado_handle ) -{ - return ffado_handle->m_deviceManager->getNbDevices(); -} - -int -ffado_get_device_node_id( ffado_handle_t ffado_handle, int device_nr ) -{ - return ffado_handle->m_deviceManager->getDeviceNodeId(device_nr); -} - -int -ffado_set_samplerate( ffado_handle_t ffado_handle, int node_id, int samplerate ) -{ - FFADODevice* avDevice = ffado_handle->m_deviceManager->getAvDevice( node_id ); - if ( avDevice ) { - if ( avDevice->setSamplingFrequency( samplerate ) ) { - return ffado_handle->m_deviceManager->discover()? 0 : -1; - } - } - return -1; } @@ -146,2 +81,517 @@ AVC::AVCCommand::setSleepAfterAVCCommand( time ); } + + +using namespace Streaming; + +struct _ffado_device +{ + DeviceManager * m_deviceManager; + StreamProcessorManager *processorManager; + + ffado_options_t options; + ffado_device_info_t device_info; +}; + +ffado_device_t *ffado_streaming_init (ffado_device_info_t device_info, ffado_options_t options) { + unsigned int i=0; + setDebugLevel(options.verbose); + + struct _ffado_device *dev = new struct _ffado_device; + + debugWarning("%s built %s %s\n", ffado_get_version(), __DATE__, __TIME__); + + if(!dev) { + debugFatal( "Could not allocate streaming device\n" ); + return 0; + } + + memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); + + dev->m_deviceManager = new DeviceManager(); + if ( !dev->m_deviceManager ) { + debugFatal( "Could not allocate device manager\n" ); + delete dev; + return 0; + } + + dev->m_deviceManager->setVerboseLevel(dev->options.verbose); + if ( !dev->m_deviceManager->initialize() ) { + debugFatal( "Could not initialize device manager\n" ); + delete dev->m_deviceManager; + delete dev; + return 0; + } + + for (i = 0; i < device_info.nb_device_spec_strings; i++) { + char *s = device_info.device_spec_strings[i]; + if ( !dev->m_deviceManager->addSpecString(s) ) { + debugFatal( "Could not add spec string %s to device manager\n", s ); + delete dev->m_deviceManager; + delete dev; + return 0; + } + } + + + // create a processor manager to manage the actual stream + // processors + dev->processorManager = new StreamProcessorManager( dev->options.period_size, + dev->options.sample_rate, + dev->options.nb_buffers); + if(!dev->processorManager) { + debugFatal("Could not create StreamProcessorManager\n"); + delete dev->m_deviceManager; + delete dev; + return 0; + } + + dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); + + dev->processorManager->setVerboseLevel(dev->options.verbose); + if(!dev->processorManager->init()) { + debugFatal("Could not init StreamProcessorManager\n"); + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + return 0; + } + + // set slave mode option + bool slaveMode=(dev->options.slave_mode != 0); + debugOutput(DEBUG_LEVEL_VERBOSE, "setting slave mode to %d\n", slaveMode); + if(!dev->m_deviceManager->setOption("slaveMode", slaveMode)) { + debugWarning("Failed to set slave mode option\n"); + } + // set snoop mode option + bool snoopMode=(dev->options.snoop_mode != 0); + debugOutput(DEBUG_LEVEL_VERBOSE, "setting snoop mode to %d\n", snoopMode); + if(!dev->m_deviceManager->setOption("snoopMode", snoopMode)) { + debugWarning("Failed to set snoop mode option\n"); + } + + // discover the devices on the bus + if(!dev->m_deviceManager->discover()) { + debugFatal("Could not discover devices\n"); + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + return 0; + } + + // are there devices on the bus? + if(dev->m_deviceManager->getAvDeviceCount()==0) { + debugFatal("There are no devices on the bus\n"); + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + return 0; + } + + // iterate over the found devices + // add the stream processors of the devices to the managers + for(i=0;im_deviceManager->getAvDeviceCount();i++) { + FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); + assert(device); + + debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); + + if (!device->lock()) { + debugWarning("Could not lock device, skipping device (%p)!\n", device); + continue; + } + + debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", + dev->options.sample_rate, device); + + // Set the device's sampling rate to that requested + // FIXME: does this really belong here? If so we need to handle errors. + if (!device->setSamplingFrequency(dev->options.sample_rate)) { + debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", + dev->options.sample_rate, device); + + // try again: + if (!device->setSamplingFrequency(dev->options.sample_rate)) { + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); + return 0; + } + } + + // prepare the device + device->prepare(); + int j=0; + for(j=0; jgetStreamCount();j++) { + StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); + debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); + if (!dev->processorManager->registerProcessor(streamproc)) { + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + debugFatal("Could not register stream processor (%p) with the Processor manager\n", streamproc); + return 0; + } + } + } + + // set the sync source + if (!dev->processorManager->setSyncSource(dev->m_deviceManager->getSyncSource())) { + debugWarning("Could not set processorManager sync source (%p)\n", + dev->m_deviceManager->getSyncSource()); + } + + // we are ready! + debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); + return dev; + +} + +int ffado_streaming_prepare(ffado_device_t *dev) { + debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); + + if (!dev->processorManager->prepare()) { + debugFatal("Could not prepare streaming...\n"); + return false; + } + + return true; +} + +void ffado_streaming_finish(ffado_device_t *dev) { + unsigned int i=0; + + assert(dev); + + // iterate over the found devices + for(i=0;im_deviceManager->getAvDeviceCount();i++) { + FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); + assert(device); + + debugOutput(DEBUG_LEVEL_VERBOSE, "Unlocking device (%p)\n", device); + + if (!device->unlock()) { + debugWarning("Could not unlock device (%p)!\n", device); + } + } + + delete dev->processorManager; + delete dev->m_deviceManager; + delete dev; + + return; +} + +int ffado_streaming_start(ffado_device_t *dev) { + unsigned int i=0; + debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Start -------------\n"); + + // create the connections for all devices + // iterate over the found devices + // add the stream processors of the devices to the managers + for(i=0;im_deviceManager->getAvDeviceCount();i++) { + FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); + assert(device); + + int j=0; + for(j=0; jgetStreamCount();j++) { + debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %d\n",j,i); + // start the stream + if (!device->startStreamByIndex(j)) { + debugWarning("Could not start stream %d of device %d\n",j,i); + continue; + } + } + + if (!device->enableStreaming()) { + debugWarning("Could not enable streaming on device %d!\n",i); + } + } + + if(dev->processorManager->start()) { + return 0; + } else { + ffado_streaming_stop(dev); + return -1; + } +} + +int ffado_streaming_stop(ffado_device_t *dev) { + unsigned int i; + debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); + + dev->processorManager->stop(); + + // create the connections for all devices + // iterate over the found devices + // add the stream processors of the devices to the managers + for(i=0;im_deviceManager->getAvDeviceCount();i++) { + FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); + assert(device); + + if (!device->disableStreaming()) { + debugWarning("Could not disable streaming on device %d!\n",i); + } + + int j=0; + for(j=0; jgetStreamCount();j++) { + debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); + // stop the stream + // start the stream + if (!device->stopStreamByIndex(j)) { + debugWarning("Could not stop stream %d of device %d\n",j,i); + continue; + } + } + } + + return 0; +} + +int ffado_streaming_reset(ffado_device_t *dev) { + debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); + + // dev->processorManager->reset(); + + return 0; +} + +int ffado_streaming_wait(ffado_device_t *dev) { + static int periods=0; + static int periods_print=0; + static int xruns=0; + + periods++; + if(periods>periods_print) { + debugOutputShort(DEBUG_LEVEL_VERBOSE, "\nffado_streaming_wait\n"); + debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); + debugOutputShort(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); + debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); + dev->processorManager->dumpInfo(); + debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); + periods_print+=100; + } + + if(dev->processorManager->waitForPeriod()) { + return dev->options.period_size; + } else { + debugWarning("XRUN detected\n"); + + // do xrun recovery + dev->processorManager->handleXrun(); + xruns++; + return -1; + } +} + +int ffado_streaming_transfer_capture_buffers(ffado_device_t *dev) { + return dev->processorManager->transfer(StreamProcessor::ePT_Receive); +} + +int ffado_streaming_transfer_playback_buffers(ffado_device_t *dev) { + return dev->processorManager->transfer(StreamProcessor::ePT_Transmit); +} + +int ffado_streaming_transfer_buffers(ffado_device_t *dev) { + return dev->processorManager->transfer(); +} + + +int ffado_streaming_write(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); + // use an assert here performancewise, + // it should already have failed before, if not correct + assert(p); + + return p->writeEvents((void *)buffer, nsamples); +} + +int ffado_streaming_read(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); + // use an assert here performancewise, + // it should already have failed before, if not correct + assert(p); + + return p->readEvents((void *)buffer, nsamples); +} + +int ffado_streaming_get_nb_capture_streams(ffado_device_t *dev) { + return dev->processorManager->getPortCount(Port::E_Capture); +} + +int ffado_streaming_get_nb_playback_streams(ffado_device_t *dev) { + return dev->processorManager->getPortCount(Port::E_Playback); +} + +int ffado_streaming_get_capture_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); + if(!p) { + debugWarning("Could not get capture port at index %d\n",i); + return -1; + } + + std::string name=p->getName(); + if (!strncpy(buffer, name.c_str(), buffersize)) { + debugWarning("Could not copy name\n"); + return -1; + } else return 0; +} + +int ffado_streaming_get_playback_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); + if(!p) { + debugWarning("Could not get playback port at index %d\n",i); + return -1; + } + + std::string name=p->getName(); + if (!strncpy(buffer, name.c_str(), buffersize)) { + debugWarning("Could not copy name\n"); + return -1; + } else return 0; +} + +ffado_streaming_stream_type ffado_streaming_get_capture_stream_type(ffado_device_t *dev, int i) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); + if(!p) { + debugWarning("Could not get capture port at index %d\n",i); + return ffado_stream_type_invalid; + } + switch(p->getPortType()) { + case Port::E_Audio: + return ffado_stream_type_audio; + case Port::E_Midi: + return ffado_stream_type_midi; + case Port::E_Control: + return ffado_stream_type_control; + default: + return ffado_stream_type_unknown; + } +} + +ffado_streaming_stream_type ffado_streaming_get_playback_stream_type(ffado_device_t *dev, int i) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); + if(!p) { + debugWarning("Could not get playback port at index %d\n",i); + return ffado_stream_type_invalid; + } + switch(p->getPortType()) { + case Port::E_Audio: + return ffado_stream_type_audio; + case Port::E_Midi: + return ffado_stream_type_midi; + case Port::E_Control: + return ffado_stream_type_control; + default: + return ffado_stream_type_unknown; + } +} + +int ffado_streaming_set_stream_buffer_type(ffado_device_t *dev, int i, + ffado_streaming_buffer_type t, enum Port::E_Direction direction) { + + Port *p=dev->processorManager->getPortByIndex(i, direction); + if(!p) { + debugWarning("Could not get %s port at index %d\n", + (direction==Port::E_Playback?"Playback":"Capture"),i); + return -1; + } + + switch(t) { + case ffado_buffer_type_int24: + if (!p->setDataType(Port::E_Int24)) { + debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); + return -1; + } + if (!p->setBufferType(Port::E_PointerBuffer)) { + debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); + return -1; + } + break; + case ffado_buffer_type_float: + if (!p->setDataType(Port::E_Float)) { + debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); + return -1; + } + if (!p->setBufferType(Port::E_PointerBuffer)) { + debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); + return -1; + } + break; + case ffado_buffer_type_midi: + if (!p->setDataType(Port::E_MidiEvent)) { + debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); + return -1; + } + if (!p->setBufferType(Port::E_RingBuffer)) { + debugWarning("%s: Could not set buffer type to Ringbuffer\n",p->getName().c_str()); + return -1; + } + break; + default: + debugWarning("%s: Unsupported buffer type\n",p->getName().c_str()); + return -1; + } + return 0; + +} + +int ffado_streaming_set_playback_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { + return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Playback); +} + +int ffado_streaming_set_capture_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { + return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Capture); +} + +int ffado_streaming_stream_onoff(ffado_device_t *dev, int i, + int on, enum Port::E_Direction direction) { + Port *p=dev->processorManager->getPortByIndex(i, direction); + if(!p) { + debugWarning("Could not get %s port at index %d\n", + (direction==Port::E_Playback?"Playback":"Capture"),i); + return -1; + } + if(on) { + p->enable(); + } else { + p->disable(); + } + return 0; +} + +int ffado_streaming_playback_stream_onoff(ffado_device_t *dev, int number, int on) { + return ffado_streaming_stream_onoff(dev, number, on, Port::E_Playback); +} + +int ffado_streaming_capture_stream_onoff(ffado_device_t *dev, int number, int on) { + return ffado_streaming_stream_onoff(dev, number, on, Port::E_Capture); +} + +// TODO: the way port buffers are set in the C api doesn't satisfy me +int ffado_streaming_set_capture_stream_buffer(ffado_device_t *dev, int i, char *buff) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); + + // use an assert here performancewise, + // it should already have failed before, if not correct + assert(p); + + p->useExternalBuffer(true); + p->setExternalBufferAddress((void *)buff); + + return 0; + +} + +int ffado_streaming_set_playback_stream_buffer(ffado_device_t *dev, int i, char *buff) { + Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); + // use an assert here performancewise, + // it should already have failed before, if not correct + assert(p); + + p->useExternalBuffer(true); + p->setExternalBufferAddress((void *)buff); + + return 0; +} Index: /trunk/libffado/src/dice/dice_avdevice.h =================================================================== --- /trunk/libffado/src/dice/dice_avdevice.h (revision 734) +++ /trunk/libffado/src/dice/dice_avdevice.h (revision 739) @@ -57,11 +57,9 @@ class DiceNotifier; public: - DiceAvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + DiceAvDevice( std::auto_ptr( configRom )); ~DiceAvDevice(); static bool probe( ConfigRom& configRom ); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice( std::auto_ptr( configRom )); virtual bool discover(); Index: /trunk/libffado/src/dice/dice_avdevice.cpp =================================================================== --- /trunk/libffado/src/dice/dice_avdevice.cpp (revision 734) +++ /trunk/libffado/src/dice/dice_avdevice.cpp (revision 739) @@ -52,7 +52,6 @@ }; -DiceAvDevice::DiceAvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FFADODevice( ieee1394Service, configRom ) +DiceAvDevice::DiceAvDevice( std::auto_ptr( configRom )) + : FFADODevice( configRom ) , m_model( NULL ) , m_global_reg_offset (0xFFFFFFFFLU) @@ -108,8 +107,7 @@ FFADODevice * -DiceAvDevice::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) +DiceAvDevice::createDevice( std::auto_ptr( configRom )) { - return new DiceAvDevice(ieee1394Service, configRom ); + return new DiceAvDevice( configRom ); } @@ -117,6 +115,6 @@ DiceAvDevice::discover() { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); - unsigned int modelId = m_pConfigRom->getModelId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); + unsigned int modelId = getConfigRom().getModelId(); for ( unsigned int i = 0; @@ -490,5 +488,5 @@ Streaming::AmdtpReceiveStreamProcessor *p; p=new Streaming::AmdtpReceiveStreamProcessor( - m_p1394Service->getPort(), + get1394Service().getPort(), nb_channels); @@ -576,5 +574,5 @@ Streaming::AmdtpTransmitStreamProcessor *p; p=new Streaming::AmdtpTransmitStreamProcessor( - m_p1394Service->getPort(), + get1394Service().getPort(), nb_channels); @@ -690,5 +688,5 @@ // get a notifier to handle device notifications nodeaddr_t notify_address; - notify_address = m_p1394Service->findFreeARMBlock( + notify_address = get1394Service().findFreeARMBlock( DICE_NOTIFIER_BASE_ADDRESS, DICE_NOTIFIER_BLOCK_LENGTH, @@ -707,5 +705,5 @@ } - if (!m_p1394Service->registerARMHandler(m_notifier)) { + if (!get1394Service().registerARMHandler(m_notifier)) { debugError("Could not register notifier\n"); delete m_notifier; @@ -726,9 +724,9 @@ } - fb_nodeaddr_t swap_value = ((0xFFC0) | m_p1394Service->getLocalNodeId()); + fb_nodeaddr_t swap_value = ((0xFFC0) | get1394Service().getLocalNodeId()); swap_value = swap_value << 48; swap_value |= m_notifier->getStart(); - if (!m_p1394Service->lockCompareSwap64( getNodeId() | 0xFFC0, addr, DICE_OWNER_NO_OWNER, + if (!get1394Service().lockCompareSwap64( getNodeId() | 0xFFC0, addr, DICE_OWNER_NO_OWNER, swap_value, &result )) { debugWarning("Could not register ourselves as device owner\n"); @@ -765,9 +763,9 @@ } - fb_nodeaddr_t compare_value = ((0xFFC0) | m_p1394Service->getLocalNodeId()); + fb_nodeaddr_t compare_value = ((0xFFC0) | get1394Service().getLocalNodeId()); compare_value <<= 48; compare_value |= m_notifier->getStart(); - if (!m_p1394Service->lockCompareSwap64( getNodeId() | 0xFFC0, addr, compare_value, + if (!get1394Service().lockCompareSwap64( getNodeId() | 0xFFC0, addr, compare_value, DICE_OWNER_NO_OWNER, &result )) { debugWarning("Could not unregister ourselves as device owner\n"); @@ -775,5 +773,5 @@ } - m_p1394Service->unregisterARMHandler(m_notifier); + get1394Service().unregisterARMHandler(m_notifier); delete m_notifier; m_notifier=NULL; @@ -984,5 +982,5 @@ unsigned int bandwidth=8+packet_size; - int ch=m_p1394Service->allocateIsoChannelGeneric(bandwidth); + int ch=get1394Service().allocateIsoChannelGeneric(bandwidth); debugOutput(DEBUG_LEVEL_VERBOSE, "allocated channel %d, bandwidth %d\n", @@ -994,5 +992,5 @@ bool DiceAvDevice::deallocateIsoChannel(int channel) { debugOutput(DEBUG_LEVEL_VERBOSE, "freeing channel %d\n",channel); - return m_p1394Service->freeIsoChannel(channel); + return get1394Service().freeIsoChannel(channel); } @@ -1227,5 +1225,5 @@ fb_nodeid_t nodeId=getNodeId() | 0xFFC0; - if(!m_p1394Service->read_quadlet( nodeId, addr, result ) ) { + if(!get1394Service().read_quadlet( nodeId, addr, result ) ) { debugError("Could not read from node 0x%04X addr 0x%012X\n", nodeId, addr); return false; @@ -1252,5 +1250,5 @@ fb_nodeid_t nodeId=getNodeId() | 0xFFC0; - if(!m_p1394Service->write_quadlet( nodeId, addr, htonl(data) ) ) { + if(!get1394Service().write_quadlet( nodeId, addr, htonl(data) ) ) { debugError("Could not write to node 0x%04X addr 0x%012X\n", nodeId, addr); return false; @@ -1272,5 +1270,5 @@ fb_nodeid_t nodeId=getNodeId() | 0xFFC0; - if(!m_p1394Service->read( nodeId, addr, length/4, data ) ) { + if(!get1394Service().read( nodeId, addr, length/4, data ) ) { debugError("Could not read from node 0x%04X addr 0x%012llX\n", nodeId, addr); return false; @@ -1303,5 +1301,5 @@ } - if(!m_p1394Service->write( nodeId, addr, length/4, data_out ) ) { + if(!get1394Service().write( nodeId, addr, length/4, data_out ) ) { debugError("Could not write to node 0x%04X addr 0x%012llX\n", nodeId, addr); return false; Index: /trunk/libffado/src/libutil/Thread.h =================================================================== --- /trunk/libffado/src/libutil/Thread.h (revision 445) +++ /trunk/libffado/src/libutil/Thread.h (revision 739) @@ -88,4 +88,6 @@ virtual pthread_t GetThreadID() = 0; + virtual void setVerboseLevel(int l) + {setDebugLevel(l);}; protected: DECLARE_DEBUG_MODULE; Index: /trunk/libffado/src/genericavc/avc_avdevice.cpp =================================================================== --- /trunk/libffado/src/genericavc/avc_avdevice.cpp (revision 736) +++ /trunk/libffado/src/genericavc/avc_avdevice.cpp (revision 739) @@ -49,10 +49,8 @@ namespace GenericAVC { -IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); - - -AvDevice::AvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FFADODevice( ieee1394Service, configRom ) +IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_NORMAL ); + +AvDevice::AvDevice(std::auto_ptr( configRom )) + : FFADODevice( configRom ) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created GenericAVC::AvDevice (NodeID %d)\n", @@ -61,9 +59,4 @@ } -AvDevice::~AvDevice() -{ - -} - bool AvDevice::probe( ConfigRom& configRom ) @@ -81,8 +74,7 @@ FFADODevice * -AvDevice::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) -{ - return new AvDevice(ieee1394Service, configRom ); +AvDevice::createDevice(std::auto_ptr( configRom )) +{ + return new AvDevice(configRom ); } @@ -93,6 +85,6 @@ // e.g. because a subclass called this function if (!GenericAVC::VendorModel::isValid(m_model)) { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); - unsigned int modelId = m_pConfigRom->getModelId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); + unsigned int modelId = getConfigRom().getModelId(); GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_genericavc.txt" ); @@ -128,10 +120,9 @@ AvDevice::setVerboseLevel(int l) { - debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); - + setDebugLevel(l); m_pPlugManager->setVerboseLevel(l); - FFADODevice::setVerboseLevel(l); AVC::Unit::setVerboseLevel(l); + debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); } @@ -628,5 +619,5 @@ if (iec61883_get_oPCRX( get1394Service().getHandle(), - m_pConfigRom->getNodeId() | 0xffc0, + getConfigRom().getNodeId() | 0xffc0, (quadlet_t *)&opcr, n)) { @@ -639,5 +630,5 @@ } else { iso_channel=get1394Service().allocateIsoChannelCMP( - m_pConfigRom->getNodeId() | 0xffc0, n, + getConfigRom().getNodeId() | 0xffc0, n, get1394Service().getLocalNodeId()| 0xffc0, -1); } @@ -662,5 +653,5 @@ if (iec61883_get_iPCRX( get1394Service().getHandle(), - m_pConfigRom->getNodeId() | 0xffc0, + getConfigRom().getNodeId() | 0xffc0, (quadlet_t *)&ipcr, n)) { @@ -675,5 +666,5 @@ iso_channel=get1394Service().allocateIsoChannelCMP( get1394Service().getLocalNodeId()| 0xffc0, -1, - m_pConfigRom->getNodeId() | 0xffc0, n); + getConfigRom().getNodeId() | 0xffc0, n); } Index: /trunk/libffado/src/genericavc/avc_avdevice.h =================================================================== --- /trunk/libffado/src/genericavc/avc_avdevice.h (revision 734) +++ /trunk/libffado/src/genericavc/avc_avdevice.h (revision 739) @@ -48,12 +48,10 @@ class AvDevice : public FFADODevice, public AVC::Unit { public: - AvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); - virtual ~AvDevice(); + AvDevice( std::auto_ptr( configRom )); + virtual ~AvDevice() {}; static bool probe( ConfigRom& configRom ); virtual bool discover(); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice( std::auto_ptr( configRom )); virtual bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; Index: /trunk/libffado/src/bebob/bebob_avdevice.cpp =================================================================== --- /trunk/libffado/src/bebob/bebob_avdevice.cpp (revision 728) +++ /trunk/libffado/src/bebob/bebob_avdevice.cpp (revision 739) @@ -55,7 +55,6 @@ namespace BeBoB { -AvDevice::AvDevice( Ieee1394Service& ieee1394service, - std::auto_ptr< ConfigRom >( configRom ) ) - : GenericAVC::AvDevice( ieee1394service, configRom ) +AvDevice::AvDevice(std::auto_ptr< ConfigRom >( configRom ) ) + : GenericAVC::AvDevice( configRom ) , m_Mixer ( 0 ) { @@ -91,6 +90,5 @@ FFADODevice * -AvDevice::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) +AvDevice::createDevice(std::auto_ptr( configRom )) { unsigned int vendorId = configRom->getNodeVendorId(); @@ -99,17 +97,17 @@ switch (vendorId) { case FW_VENDORID_TERRATEC: - return new Terratec::PhaseSeriesDevice(ieee1394Service, configRom); + return new Terratec::PhaseSeriesDevice(configRom); case FW_VENDORID_FOCUSRITE: switch(modelId) { case 0x00000003: case 0x00000006: - return new Focusrite::SaffireProDevice(ieee1394Service, configRom); + return new Focusrite::SaffireProDevice(configRom); case 0x00000000: - return new Focusrite::SaffireDevice(ieee1394Service, configRom); + return new Focusrite::SaffireDevice(configRom); default: // return a plain BeBoB device - return new AvDevice(ieee1394Service, configRom); + return new AvDevice(configRom); } default: - return new AvDevice(ieee1394Service, configRom); + return new AvDevice(configRom); } return NULL; @@ -119,6 +117,6 @@ AvDevice::discover() { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); - unsigned int modelId = m_pConfigRom->getModelId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); + unsigned int modelId = getConfigRom().getModelId(); GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_bebob.txt" ); @@ -242,5 +240,5 @@ AvDevice::getConfigurationIdSampleRate() { - ExtendedStreamFormatCmd extStreamFormatCmd( *m_p1394Service ); + ExtendedStreamFormatCmd extStreamFormatCmd( get1394Service() ); UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); extStreamFormatCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, @@ -275,5 +273,5 @@ AvDevice::getConfigurationIdNumberOfChannel( PlugAddress::EPlugDirection ePlugDirection ) { - ExtendedPlugInfoCmd extPlugInfoCmd( *m_p1394Service ); + ExtendedPlugInfoCmd extPlugInfoCmd( get1394Service() ); UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, getNodeId() ); @@ -310,5 +308,5 @@ AvDevice::getConfigurationIdSyncMode() { - SignalSourceCmd signalSourceCmd( *m_p1394Service ); + SignalSourceCmd signalSourceCmd( get1394Service() ); SignalUnitAddress signalUnitAddr; signalUnitAddr.m_plugId = 0x01; @@ -409,5 +407,5 @@ AvDevice::loadFromCache() { - Glib::ustring sDevicePath = getCachePath() + m_pConfigRom->getGuidString(); + Glib::ustring sDevicePath = getCachePath() + getConfigRom().getGuidString(); char* configId; @@ -449,5 +447,5 @@ // the path looks like this: // PATH_TO_CACHE + GUID + CONFIGURATION_ID - string tmp_path = getCachePath() + m_pConfigRom->getGuidString(); + string tmp_path = getCachePath() + getConfigRom().getGuidString(); // the following piece should do something like Index: /trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp (revision 680) +++ /trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp (revision 739) @@ -30,7 +30,6 @@ namespace Focusrite { -FocusriteDevice::FocusriteDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : BeBoB::AvDevice( ieee1394Service, configRom) +FocusriteDevice::FocusriteDevice( std::auto_ptr( configRom )) + : BeBoB::AvDevice( configRom) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::FocusriteDevice (NodeID %d)\n", @@ -141,5 +140,5 @@ fb_nodeid_t nodeId = getNodeId() | 0xFFC0; - if(!m_p1394Service->write_quadlet( nodeId, addr, htonl(data) ) ) { + if(!get1394Service().write_quadlet( nodeId, addr, htonl(data) ) ) { debugError("Could not write to node 0x%04X addr 0x%012X\n", nodeId, addr); return false; @@ -157,5 +156,5 @@ fb_nodeid_t nodeId = getNodeId() | 0xFFC0; - if(!m_p1394Service->read_quadlet( nodeId, addr, &result ) ) { + if(!get1394Service().read_quadlet( nodeId, addr, &result ) ) { debugError("Could not read from node 0x%04llX addr 0x%012llX\n", nodeId, addr); return false; Index: /trunk/libffado/src/bebob/focusrite/focusrite_saffire.cpp =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_saffire.cpp (revision 664) +++ /trunk/libffado/src/bebob/focusrite/focusrite_saffire.cpp (revision 739) @@ -28,7 +28,6 @@ namespace Focusrite { -SaffireDevice::SaffireDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FocusriteDevice( ieee1394Service, configRom) +SaffireDevice::SaffireDevice( std::auto_ptr( configRom )) + : FocusriteDevice( configRom) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::SaffireDevice (NodeID %d)\n", @@ -39,9 +38,4 @@ AVC::AVCCommand::setSleepAfterAVCCommand( 1000 ); } - -} - -SaffireDevice::~SaffireDevice() -{ } Index: /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp (revision 684) +++ /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp (revision 739) @@ -28,9 +28,8 @@ namespace Focusrite { -SaffireProDevice::SaffireProDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FocusriteDevice( ieee1394Service, configRom) - , m_MixerContainer ( NULL ) - , m_ControlContainer ( NULL ) +SaffireProDevice::SaffireProDevice(std::auto_ptr( configRom )) + : FocusriteDevice( configRom ) + , m_MixerContainer( NULL ) + , m_ControlContainer( NULL ) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::SaffireProDevice (NodeID %d)\n", Index: /trunk/libffado/src/bebob/focusrite/focusrite_generic.h =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_generic.h (revision 676) +++ /trunk/libffado/src/bebob/focusrite/focusrite_generic.h (revision 739) @@ -136,6 +136,5 @@ class FocusriteDevice : public BeBoB::AvDevice { public: - FocusriteDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + FocusriteDevice(std::auto_ptr( configRom )); virtual ~FocusriteDevice() {}; Index: /trunk/libffado/src/bebob/focusrite/focusrite_saffire.h =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_saffire.h (revision 662) +++ /trunk/libffado/src/bebob/focusrite/focusrite_saffire.h (revision 739) @@ -142,7 +142,6 @@ class SaffireDevice : public FocusriteDevice { public: - SaffireDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); - virtual ~SaffireDevice(); + SaffireDevice(std::auto_ptr( configRom )); + virtual ~SaffireDevice() {}; virtual void showDevice(); Index: /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.h =================================================================== --- /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.h (revision 684) +++ /trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.h (revision 739) @@ -302,6 +302,5 @@ public: - SaffireProDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + SaffireProDevice(std::auto_ptr( configRom )); virtual ~SaffireProDevice(); Index: /trunk/libffado/src/bebob/bebob_avdevice.h =================================================================== --- /trunk/libffado/src/bebob/bebob_avdevice.h (revision 734) +++ /trunk/libffado/src/bebob/bebob_avdevice.h (revision 739) @@ -60,6 +60,5 @@ class AvDevice : public GenericAVC::AvDevice { public: - AvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + AvDevice( std::auto_ptr( configRom )); virtual ~AvDevice(); @@ -69,6 +68,5 @@ virtual bool discover(); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice( std::auto_ptr( configRom )); virtual AVC::Subunit* createSubunit(AVC::Unit& unit, Index: /trunk/libffado/src/bebob/terratec/terratec_device.cpp =================================================================== --- /trunk/libffado/src/bebob/terratec/terratec_device.cpp (revision 584) +++ /trunk/libffado/src/bebob/terratec/terratec_device.cpp (revision 739) @@ -27,7 +27,6 @@ namespace Terratec { -PhaseSeriesDevice::PhaseSeriesDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : BeBoB::AvDevice( ieee1394Service, configRom) +PhaseSeriesDevice::PhaseSeriesDevice(std::auto_ptr( configRom )) + : BeBoB::AvDevice( configRom) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Terratec::PhaseSeriesDevice (NodeID %d)\n", Index: /trunk/libffado/src/bebob/terratec/terratec_device.h =================================================================== --- /trunk/libffado/src/bebob/terratec/terratec_device.h (revision 584) +++ /trunk/libffado/src/bebob/terratec/terratec_device.h (revision 739) @@ -34,6 +34,5 @@ class PhaseSeriesDevice : public BeBoB::AvDevice { public: - PhaseSeriesDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + PhaseSeriesDevice( std::auto_ptr( configRom )); virtual ~PhaseSeriesDevice(); Index: /trunk/libffado/src/fireworks/fireworks_device.h =================================================================== --- /trunk/libffado/src/fireworks/fireworks_device.h (revision 664) +++ /trunk/libffado/src/fireworks/fireworks_device.h (revision 739) @@ -42,11 +42,9 @@ class Device : public GenericAVC::AvDevice { public: - Device( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + Device(std::auto_ptr( configRom )); virtual ~Device(); static bool probe( ConfigRom& configRom ); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice( std::auto_ptr( configRom )); virtual bool discover(); Index: /trunk/libffado/src/fireworks/audiofire/audiofire_device.cpp =================================================================== --- /trunk/libffado/src/fireworks/audiofire/audiofire_device.cpp (revision 587) +++ /trunk/libffado/src/fireworks/audiofire/audiofire_device.cpp (revision 739) @@ -30,7 +30,6 @@ namespace ECHO { -AudioFire::AudioFire( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : FireWorks::Device( ieee1394Service, configRom) +AudioFire::AudioFire(std::auto_ptr( configRom )) + : FireWorks::Device(configRom) { debugOutput( DEBUG_LEVEL_VERBOSE, "Created FireWorks::ECHO::AudioFire (NodeID %d)\n", Index: /trunk/libffado/src/fireworks/audiofire/audiofire_device.h =================================================================== --- /trunk/libffado/src/fireworks/audiofire/audiofire_device.h (revision 639) +++ /trunk/libffado/src/fireworks/audiofire/audiofire_device.h (revision 739) @@ -35,6 +35,5 @@ public: - AudioFire( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + AudioFire(std::auto_ptr( configRom )); virtual ~AudioFire(); Index: /trunk/libffado/src/fireworks/fireworks_device.cpp =================================================================== --- /trunk/libffado/src/fireworks/fireworks_device.cpp (revision 689) +++ /trunk/libffado/src/fireworks/fireworks_device.cpp (revision 739) @@ -43,7 +43,6 @@ namespace FireWorks { -Device::Device( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : GenericAVC::AvDevice( ieee1394Service, configRom) +Device::Device(std::auto_ptr( configRom )) + : GenericAVC::AvDevice(configRom) , m_efc_discovery_done ( false ) , m_MixerContainer ( NULL ) @@ -91,6 +90,6 @@ Device::discover() { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); - unsigned int modelId = m_pConfigRom->getModelId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); + unsigned int modelId = getConfigRom().getModelId(); GenericAVC::VendorModel vendorModel( SHAREDIR "/ffado_driver_fireworks.txt" ); @@ -128,4 +127,5 @@ { m_efc_discovery_done = false; + m_HwInfo.setVerboseLevel(getDebugLevel()); if (!doEfcOverAVC(m_HwInfo)) { @@ -148,6 +148,5 @@ FFADODevice * -Device::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) +Device::createDevice(std::auto_ptr( configRom )) { unsigned int vendorId = configRom->getNodeVendorId(); @@ -155,6 +154,6 @@ switch(vendorId) { - case FW_VENDORID_ECHO: return new ECHO::AudioFire(ieee1394Service, configRom ); - default: return new Device(ieee1394Service, configRom ); + case FW_VENDORID_ECHO: return new ECHO::AudioFire(configRom ); + default: return new Device(configRom ); } } @@ -169,9 +168,5 @@ cmd.setVerbose( getDebugLevel() ); -// cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); - cmd.m_cmd = &c; - -// c.showEfcCmd(); if ( !cmd.fire()) { @@ -180,5 +175,4 @@ return false; } -// c.showEfcCmd(); if ( cmd.getResponse() != AVC::AVCCommand::eR_Accepted) { Index: /trunk/libffado/src/fireworks/efc/efc_cmd.cpp =================================================================== --- /trunk/libffado/src/fireworks/efc/efc_cmd.cpp (revision 687) +++ /trunk/libffado/src/fireworks/efc/efc_cmd.cpp (revision 739) @@ -177,3 +177,9 @@ } +void +EfcCmd::setVerboseLevel(int l) +{ + setDebugLevel(l); +} + } // namespace FireWorks Index: /trunk/libffado/src/fireworks/efc/efc_cmd.h =================================================================== --- /trunk/libffado/src/fireworks/efc/efc_cmd.h (revision 687) +++ /trunk/libffado/src/fireworks/efc/efc_cmd.h (revision 739) @@ -219,4 +219,5 @@ virtual void showEfcCmd(); + virtual void setVerboseLevel(int l); uint32_t m_length; // in quadlets, including length field and header. Index: /trunk/libffado/src/devicemanager.cpp =================================================================== --- /trunk/libffado/src/devicemanager.cpp (revision 734) +++ /trunk/libffado/src/devicemanager.cpp (revision 739) @@ -80,5 +80,4 @@ DeviceManager::DeviceManager() : Control::Container("devicemanager") - , m_1394Service( 0 ) { addOption(Util::OptionContainer::Option("slaveMode",false)); @@ -98,5 +97,16 @@ } - delete m_1394Service; + for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); + it != m_1394Services.end(); + ++it ) + { + delete *it; + } + for ( FunctorVectorIterator it = m_busreset_functors.begin(); + it != m_busreset_functors.end(); + ++it ) + { + delete *it; + } } @@ -106,10 +116,13 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); setDebugLevel(l); - - if (m_1394Service) m_1394Service->setVerboseLevel(l); Control::Element::setVerboseLevel(l); - for ( FFADODeviceVectorIterator it = m_avDevices.begin(); it != m_avDevices.end(); + ++it ) + { + (*it)->setVerboseLevel(l); + } + for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); + it != m_1394Services.end(); ++it ) { @@ -122,8 +135,15 @@ debugOutput(DEBUG_LEVEL_NORMAL, "===== Device Manager =====\n"); Control::Element::show(); - - if (m_1394Service) debugOutput(DEBUG_LEVEL_NORMAL, "1394 port: %d\n", m_1394Service->getPort()); int i=0; + for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); + it != m_1394Services.end(); + ++it ) + { + debugOutput(DEBUG_LEVEL_NORMAL, "--- IEEE1394 Service %2d ---\n", i++); + (*it)->show(); + } + + i=0; for ( FFADODeviceVectorIterator it = m_avDevices.begin(); it != m_avDevices.end(); @@ -145,31 +165,62 @@ FFADODevice::ClockSourceTypeToString(c.type), c.id, c.valid, c.active, c.description.c_str()); } - } } bool -DeviceManager::initialize( int port ) -{ - m_1394Service = new Ieee1394Service(); - if ( !m_1394Service ) { - debugFatal( "Could not create Ieee1349Service object\n" ); +DeviceManager::initialize() +{ + assert(m_1394Services.size() == 0); + assert(m_busreset_functors.size() == 0); + + unsigned int nb_detected_ports = Ieee1394Service::detectNbPorts(); + if (nb_detected_ports == 0) { + debugFatal("No firewire ports found.\n"); return false; } - - if ( !m_1394Service->initialize( port ) ) { - debugFatal( "Could not initialize Ieee1349Service object\n" ); - delete m_1394Service; - m_1394Service = 0; + debugOutput( DEBUG_LEVEL_VERBOSE, "Found %d firewire adapters (ports)\n", nb_detected_ports); + for (unsigned int port = 0; port < nb_detected_ports; port++) { + Ieee1394Service* tmp1394Service = new Ieee1394Service(); + if ( !tmp1394Service ) { + debugFatal( "Could not create Ieee1349Service object for port %d\n", port ); + return false; + } + m_1394Services.push_back(tmp1394Service); + + if ( !tmp1394Service->initialize( port ) ) { + debugFatal( "Could not initialize Ieee1349Service object for port %d\n", port ); + return false; + } + // add the bus reset handler + Functor* tmp_busreset_functor = new MemberFunctor0< DeviceManager*, + void (DeviceManager::*)() > + ( this, &DeviceManager::busresetHandler, false ); + if ( !tmp_busreset_functor ) { + debugFatal( "Could not create busreset handler for port %d\n", port ); + return false; + } + m_busreset_functors.push_back(tmp_busreset_functor); + + tmp1394Service->addBusResetHandler( tmp_busreset_functor ); + tmp1394Service->setVerboseLevel( getDebugLevel() ); + } + return true; +} + +bool +DeviceManager::addSpecString(char *s) { + std::string spec = s; + if(isSpecStringValid(spec)) { + debugOutput(DEBUG_LEVEL_VERBOSE, "Adding spec string %s\n", spec.c_str()); + m_SpecStrings.push_back(spec); + return true; + } else { + debugError("Invalid spec string: %s\n", spec.c_str()); return false; } - - // add the bus reset handler - m_busreset_functor = new MemberFunctor0< DeviceManager*, - void (DeviceManager::*)() > - ( this, &DeviceManager::busresetHandler, false ); - m_1394Service->addBusResetHandler( m_busreset_functor ); - - setVerboseLevel(getDebugLevel()); +} + +bool +DeviceManager::isSpecStringValid(std::string s) { return true; } @@ -179,5 +230,5 @@ { debugOutput( DEBUG_LEVEL_VERBOSE, "Bus reset...\n" ); - + // FIXME: what port was the bus reset on? // propagate the bus reset to all avDevices for ( FFADODeviceVectorIterator it = m_avDevices.begin(); @@ -215,80 +266,104 @@ if (!slaveMode) { - for ( fb_nodeid_t nodeId = 0; - nodeId < m_1394Service->getNodeCount(); - ++nodeId ) + for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); + it != m_1394Services.end(); + ++it ) { - debugOutput( DEBUG_LEVEL_VERBOSE, "Probing node %d...\n", nodeId ); - - if (nodeId == m_1394Service->getLocalNodeId()) { - debugOutput( DEBUG_LEVEL_VERBOSE, "Skipping local node (%d)...\n", nodeId ); - continue; - } - - std::auto_ptr configRom = - std::auto_ptr( new ConfigRom( *m_1394Service, - nodeId ) ); - if ( !configRom->initialize() ) { - // \todo If a PHY on the bus is in power safe mode then - // the config rom is missing. So this might be just - // such this case and we can safely skip it. But it might - // be there is a real software problem on our side. - // This should be handlede more carefuly. - debugOutput( DEBUG_LEVEL_NORMAL, - "Could not read config rom from device (node id %d). " - "Skip device discovering for this node\n", - nodeId ); - continue; - } - - FFADODevice* avDevice = getDriverForDevice( configRom, - nodeId ); - - if ( avDevice ) { - debugOutput( DEBUG_LEVEL_NORMAL, - "driver found for device %d\n", - nodeId ); - - avDevice->setVerboseLevel( getDebugLevel() ); - bool isFromCache = false; - if ( avDevice->loadFromCache() ) { - debugOutput( DEBUG_LEVEL_VERBOSE, "could load from cache\n" ); - isFromCache = true; - } else if ( avDevice->discover() ) { - debugOutput( DEBUG_LEVEL_VERBOSE, "discovering successful\n" ); - } else { - debugError( "could not discover device\n" ); - delete avDevice; + Ieee1394Service *portService = *it; + for ( fb_nodeid_t nodeId = 0; + nodeId < portService->getNodeCount(); + ++nodeId ) + { + debugOutput( DEBUG_LEVEL_VERBOSE, "Probing node %d...\n", nodeId ); + + if (nodeId == portService->getLocalNodeId()) { + debugOutput( DEBUG_LEVEL_VERBOSE, "Skipping local node (%d)...\n", nodeId ); continue; } - - if (snoopMode) { - debugOutput( DEBUG_LEVEL_VERBOSE, - "Enabling snoop mode on node %d...\n", nodeId ); - - if(!avDevice->setOption("snoopMode", snoopMode)) { - debugWarning("Could not set snoop mode for device on node %d\n", nodeId); + + std::auto_ptr configRom = + std::auto_ptr( new ConfigRom( *portService, nodeId ) ); + if ( !configRom->initialize() ) { + // \todo If a PHY on the bus is in power safe mode then + // the config rom is missing. So this might be just + // such this case and we can safely skip it. But it might + // be there is a real software problem on our side. + // This should be handlede more carefuly. + debugOutput( DEBUG_LEVEL_NORMAL, + "Could not read config rom from device (node id %d). " + "Skip device discovering for this node\n", + nodeId ); + continue; + } + + bool already_in_vector = false; + for ( FFADODeviceVectorIterator it = m_avDevices.begin(); + it != m_avDevices.end(); + ++it ) + { + if ((*it)->getConfigRom().getGuid() == configRom->getGuid()) { + already_in_vector = true; + break; + } + } + if (already_in_vector) { + debugWarning("Device with GUID %s already discovered on other port, skipping device...\n", + configRom->getGuidString().c_str()); + continue; + } + + if( getDebugLevel() >= DEBUG_LEVEL_VERBOSE) { + configRom->printConfigRom(); + } + + FFADODevice* avDevice = getDriverForDevice( configRom, + nodeId ); + + if ( avDevice ) { + debugOutput( DEBUG_LEVEL_NORMAL, + "driver found for device %d\n", + nodeId ); + + avDevice->setVerboseLevel( getDebugLevel() ); + bool isFromCache = false; + if ( avDevice->loadFromCache() ) { + debugOutput( DEBUG_LEVEL_VERBOSE, "could load from cache\n" ); + isFromCache = true; + } else if ( avDevice->discover() ) { + debugOutput( DEBUG_LEVEL_VERBOSE, "discovering successful\n" ); + } else { + debugError( "could not discover device\n" ); delete avDevice; continue; } + + if (snoopMode) { + debugOutput( DEBUG_LEVEL_VERBOSE, + "Enabling snoop mode on node %d...\n", nodeId ); + + if(!avDevice->setOption("snoopMode", snoopMode)) { + debugWarning("Could not set snoop mode for device on node %d\n", nodeId); + delete avDevice; + continue; + } + } + + if ( !isFromCache && !avDevice->saveCache() ) { + debugOutput( DEBUG_LEVEL_VERBOSE, "No cached version of AVC model created\n" ); + } + + m_avDevices.push_back( avDevice ); + + if (!addElement(avDevice)) { + debugWarning("failed to add AvDevice to Control::Container\n"); + } + + debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d on port %d done...\n", nodeId, portService->getPort() ); } - - if ( !isFromCache && !avDevice->saveCache() ) { - debugOutput( DEBUG_LEVEL_VERBOSE, "No cached version of AVC model created\n" ); - } - - m_avDevices.push_back( avDevice ); - - if (!addElement(avDevice)) { - debugWarning("failed to add AvDevice to Control::Container\n"); - } - - debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d done...\n", nodeId ); - } } debugOutput( DEBUG_LEVEL_NORMAL, "Discovery finished...\n" ); - + // FIXME: do better sorting // sort the m_avDevices vector on their GUID // then assign reassign the id's to the devices @@ -296,5 +371,4 @@ // a device id always corresponds to the same device sort(m_avDevices.begin(), m_avDevices.end(), FFADODevice::compareGUID); - int i=0; for ( FFADODeviceVectorIterator it = m_avDevices.begin(); @@ -306,14 +380,13 @@ } } - show(); return true; - } else { // slave mode - fb_nodeid_t nodeId = m_1394Service->getLocalNodeId(); + Ieee1394Service *portService = m_1394Services.at(0); + fb_nodeid_t nodeId = portService->getLocalNodeId(); debugOutput( DEBUG_LEVEL_VERBOSE, "Starting in slave mode on node %d...\n", nodeId ); std::auto_ptr configRom = - std::auto_ptr( new ConfigRom( *m_1394Service, + std::auto_ptr( new ConfigRom( *portService, nodeId ) ); if ( !configRom->initialize() ) { @@ -350,12 +423,9 @@ avDevice->showDevice(); } - m_avDevices.push_back( avDevice ); - - debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d done...\n", nodeId ); + debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d on port %d done...\n", nodeId, portService->getPort() ); } debugOutput( DEBUG_LEVEL_NORMAL, "discovery finished...\n" ); - return true; } @@ -369,5 +439,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying BeBoB...\n" ); if ( BeBoB::AvDevice::probe( *configRom.get() ) ) { - return BeBoB::AvDevice::createDevice( *m_1394Service, configRom ); + return BeBoB::AvDevice::createDevice( configRom ); } #endif @@ -376,5 +446,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Generic AV/C...\n" ); if ( GenericAVC::AvDevice::probe( *configRom.get() ) ) { - return GenericAVC::AvDevice::createDevice( *m_1394Service, configRom ); + return GenericAVC::AvDevice::createDevice( configRom ); } #endif @@ -383,5 +453,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying ECHO Audio FireWorks...\n" ); if ( FireWorks::Device::probe( *configRom.get() ) ) { - return FireWorks::Device::createDevice( *m_1394Service, configRom ); + return FireWorks::Device::createDevice( configRom ); } #endif @@ -390,5 +460,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying M-Audio...\n" ); if ( MAudio::AvDevice::probe( *configRom.get() ) ) { - return MAudio::AvDevice::createDevice( *m_1394Service, configRom ); + return MAudio::AvDevice::createDevice( configRom ); } #endif @@ -397,5 +467,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Motu...\n" ); if ( Motu::MotuDevice::probe( *configRom.get() ) ) { - return Motu::MotuDevice::createDevice( *m_1394Service, configRom ); + return Motu::MotuDevice::createDevice( configRom ); } #endif @@ -404,5 +474,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Dice...\n" ); if ( Dice::DiceAvDevice::probe( *configRom.get() ) ) { - return Dice::DiceAvDevice::createDevice( *m_1394Service, configRom ); + return Dice::DiceAvDevice::createDevice( configRom ); } #endif @@ -411,5 +481,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Metric Halo...\n" ); if ( MetricHalo::MHAvDevice::probe( *configRom.get() ) ) { - return MetricHalo::MHAvDevice::createDevice( *m_1394Service, configRom ); + return MetricHalo::MHAvDevice::createDevice( configRom ); } #endif @@ -418,5 +488,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying RME...\n" ); if ( Rme::RmeDevice::probe( *configRom.get() ) ) { - return Rme::RmeDevice::createDevice( *m_1394Service, configRom ); + return Rme::RmeDevice::createDevice( configRom ); } #endif @@ -425,5 +495,5 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Bounce...\n" ); if ( Bounce::BounceDevice::probe( *configRom.get() ) ) { - return Bounce::BounceDevice::createDevice( *m_1394Service, configRom ); + return Bounce::BounceDevice::createDevice( configRom ); } #endif @@ -438,5 +508,5 @@ #ifdef ENABLE_BOUNCE if ( Bounce::BounceSlaveDevice::probe( *configRom.get() ) ) { - return Bounce::BounceSlaveDevice::createDevice( *m_1394Service, configRom ); + return Bounce::BounceSlaveDevice::createDevice( configRom ); } #endif Index: /trunk/libffado/src/maudio/maudio_avdevice.cpp =================================================================== --- /trunk/libffado/src/maudio/maudio_avdevice.cpp (revision 587) +++ /trunk/libffado/src/maudio/maudio_avdevice.cpp (revision 739) @@ -40,7 +40,6 @@ namespace MAudio { -AvDevice::AvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) - : BeBoB::AvDevice( ieee1394Service, configRom) +AvDevice::AvDevice(std::auto_ptr( configRom )) + : BeBoB::AvDevice( configRom) , m_model ( NULL ) { @@ -82,8 +81,7 @@ FFADODevice * -AvDevice::createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )) +AvDevice::createDevice(std::auto_ptr( configRom )) { - return new AvDevice(ieee1394Service, configRom ); + return new AvDevice(configRom ); } @@ -91,6 +89,6 @@ AvDevice::discover() { - unsigned int vendorId = m_pConfigRom->getNodeVendorId(); - unsigned int modelId = m_pConfigRom->getModelId(); + unsigned int vendorId = getConfigRom().getNodeVendorId(); + unsigned int modelId = getConfigRom().getModelId(); for ( unsigned int i = 0; Index: /trunk/libffado/src/maudio/maudio_avdevice.h =================================================================== --- /trunk/libffado/src/maudio/maudio_avdevice.h (revision 734) +++ /trunk/libffado/src/maudio/maudio_avdevice.h (revision 739) @@ -54,11 +54,9 @@ class AvDevice : public BeBoB::AvDevice { public: - AvDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + AvDevice(std::auto_ptr( configRom )); virtual ~AvDevice(); static bool probe( ConfigRom& configRom ); - static FFADODevice * createDevice( Ieee1394Service& ieee1394Service, - std::auto_ptr( configRom )); + static FFADODevice * createDevice(std::auto_ptr( configRom )); virtual bool discover(); Index: /unk/libffado/src/ffado_streaming.cpp =================================================================== --- /trunk/libffado/src/ffado_streaming.cpp (revision 734) +++ (revision ) @@ -1,547 +1,0 @@ -/* - * Copyright (C) 2005-2007 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software Foundation; - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -/* - * Implementation of the FFADO Streaming API - */ - -#include "../libffado/ffado.h" -#include "devicemanager.h" -#include "ffadodevice.h" - -#include "libstreaming/StreamProcessorManager.h" - -#include - -#include -#include - -/** -* Device structure -*/ - -DECLARE_GLOBAL_DEBUG_MODULE; - -using namespace Streaming; - -struct _ffado_device -{ - DeviceManager * m_deviceManager; - StreamProcessorManager *processorManager; - - ffado_options_t options; - ffado_device_info_t device_info; -}; - -ffado_device_t *ffado_streaming_init (ffado_device_info_t *device_info, ffado_options_t options) { - unsigned int i=0; - - struct _ffado_device *dev = new struct _ffado_device; - - debugWarning("%s built %s %s\n", ffado_get_version(), __DATE__, __TIME__); - - if(!dev) { - debugFatal( "Could not allocate streaming device\n" ); - return 0; - } - - memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); - memcpy((void *)&dev->device_info, (void *)device_info, sizeof(dev->device_info)); - - dev->m_deviceManager = new DeviceManager(); - if ( !dev->m_deviceManager ) { - debugFatal( "Could not allocate device manager\n" ); - delete dev; - return 0; - } - - dev->m_deviceManager->setVerboseLevel(DEBUG_LEVEL_NORMAL); - if ( !dev->m_deviceManager->initialize( dev->options.port ) ) { - debugFatal( "Could not initialize device manager\n" ); - delete dev->m_deviceManager; - delete dev; - return 0; - } - - // create a processor manager to manage the actual stream - // processors - dev->processorManager = new StreamProcessorManager( dev->options.period_size, - dev->options.sample_rate, - dev->options.nb_buffers); - if(!dev->processorManager) { - debugFatal("Could not create StreamProcessorManager\n"); - delete dev->m_deviceManager; - delete dev; - return 0; - } - - dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); - - dev->processorManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - if(!dev->processorManager->init()) { - debugFatal("Could not init StreamProcessorManager\n"); - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - return 0; - } - - // set slave mode option - bool slaveMode=(dev->options.slave_mode != 0); - debugOutput(DEBUG_LEVEL_VERBOSE, "setting slave mode to %d\n", slaveMode); - if(!dev->m_deviceManager->setOption("slaveMode", slaveMode)) { - debugWarning("Failed to set slave mode option\n"); - } - // set snoop mode option - bool snoopMode=(dev->options.snoop_mode != 0); - debugOutput(DEBUG_LEVEL_VERBOSE, "setting snoop mode to %d\n", snoopMode); - if(!dev->m_deviceManager->setOption("snoopMode", snoopMode)) { - debugWarning("Failed to set snoop mode option\n"); - } - - // discover the devices on the bus - if(!dev->m_deviceManager->discover()) { - debugFatal("Could not discover devices\n"); - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - return 0; - } - - // are there devices on the bus? - if(dev->m_deviceManager->getAvDeviceCount()==0) { - debugFatal("There are no devices on the bus\n"); - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - return 0; - } - - // iterate over the found devices - // add the stream processors of the devices to the managers - for(i=0;im_deviceManager->getAvDeviceCount();i++) { - FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); - assert(device); - - debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); - - if (!device->lock()) { - debugWarning("Could not lock device, skipping device (%p)!\n", device); - continue; - } - - debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", - dev->options.sample_rate, device); - - // Set the device's sampling rate to that requested - // FIXME: does this really belong here? If so we need to handle errors. - if (!device->setSamplingFrequency(dev->options.sample_rate)) { - debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", - dev->options.sample_rate, device); - - // try again: - if (!device->setSamplingFrequency(dev->options.sample_rate)) { - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); - return 0; - } - } - - // prepare the device - device->prepare(); - int j=0; - for(j=0; jgetStreamCount();j++) { - StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); - debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); - if (!dev->processorManager->registerProcessor(streamproc)) { - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - debugFatal("Could not register stream processor (%p) with the Processor manager\n", streamproc); - return 0; - } - } - } - - // set the sync source - if (!dev->processorManager->setSyncSource(dev->m_deviceManager->getSyncSource())) { - debugWarning("Could not set processorManager sync source (%p)\n", - dev->m_deviceManager->getSyncSource()); - } - - // we are ready! - debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); - return dev; - -} - -int ffado_streaming_prepare(ffado_device_t *dev) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); - - if (!dev->processorManager->prepare()) { - debugFatal("Could not prepare streaming...\n"); - return false; - } - - return true; -} - -void ffado_streaming_finish(ffado_device_t *dev) { - unsigned int i=0; - - assert(dev); - - // iterate over the found devices - for(i=0;im_deviceManager->getAvDeviceCount();i++) { - FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); - assert(device); - - debugOutput(DEBUG_LEVEL_VERBOSE, "Unlocking device (%p)\n", device); - - if (!device->unlock()) { - debugWarning("Could not unlock device (%p)!\n", device); - } - } - - delete dev->processorManager; - delete dev->m_deviceManager; - delete dev; - - return; -} - -int ffado_streaming_start(ffado_device_t *dev) { - unsigned int i=0; - debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Start -------------\n"); - - // create the connections for all devices - // iterate over the found devices - // add the stream processors of the devices to the managers - for(i=0;im_deviceManager->getAvDeviceCount();i++) { - FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); - assert(device); - - int j=0; - for(j=0; jgetStreamCount();j++) { - debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %d\n",j,i); - // start the stream - if (!device->startStreamByIndex(j)) { - debugWarning("Could not start stream %d of device %d\n",j,i); - continue; - } - } - - if (!device->enableStreaming()) { - debugWarning("Could not enable streaming on device %d!\n",i); - } - } - - if(dev->processorManager->start()) { - return 0; - } else { - ffado_streaming_stop(dev); - return -1; - } -} - -int ffado_streaming_stop(ffado_device_t *dev) { - unsigned int i; - debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); - - dev->processorManager->stop(); - - // create the connections for all devices - // iterate over the found devices - // add the stream processors of the devices to the managers - for(i=0;im_deviceManager->getAvDeviceCount();i++) { - FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); - assert(device); - - if (!device->disableStreaming()) { - debugWarning("Could not disable streaming on device %d!\n",i); - } - - int j=0; - for(j=0; jgetStreamCount();j++) { - debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); - // stop the stream - // start the stream - if (!device->stopStreamByIndex(j)) { - debugWarning("Could not stop stream %d of device %d\n",j,i); - continue; - } - } - } - - return 0; -} - -int ffado_streaming_reset(ffado_device_t *dev) { - debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); - - // dev->processorManager->reset(); - - return 0; -} - -int ffado_streaming_wait(ffado_device_t *dev) { - static int periods=0; - static int periods_print=0; - static int xruns=0; - - periods++; - if(periods>periods_print) { - debugOutputShort(DEBUG_LEVEL_VERBOSE, "\nffado_streaming_wait\n"); - debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); - debugOutputShort(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); - debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); - dev->processorManager->dumpInfo(); - debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); - periods_print+=100; - } - - if(dev->processorManager->waitForPeriod()) { - return dev->options.period_size; - } else { - debugWarning("XRUN detected\n"); - - // do xrun recovery - dev->processorManager->handleXrun(); - xruns++; - return -1; - } -} - -int ffado_streaming_transfer_capture_buffers(ffado_device_t *dev) { - return dev->processorManager->transfer(StreamProcessor::ePT_Receive); -} - -int ffado_streaming_transfer_playback_buffers(ffado_device_t *dev) { - return dev->processorManager->transfer(StreamProcessor::ePT_Transmit); -} - -int ffado_streaming_transfer_buffers(ffado_device_t *dev) { - return dev->processorManager->transfer(); -} - - -int ffado_streaming_write(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); - // use an assert here performancewise, - // it should already have failed before, if not correct - assert(p); - - return p->writeEvents((void *)buffer, nsamples); -} - -int ffado_streaming_read(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); - // use an assert here performancewise, - // it should already have failed before, if not correct - assert(p); - - return p->readEvents((void *)buffer, nsamples); -} - -int ffado_streaming_get_nb_capture_streams(ffado_device_t *dev) { - return dev->processorManager->getPortCount(Port::E_Capture); -} - -int ffado_streaming_get_nb_playback_streams(ffado_device_t *dev) { - return dev->processorManager->getPortCount(Port::E_Playback); -} - -int ffado_streaming_get_capture_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); - if(!p) { - debugWarning("Could not get capture port at index %d\n",i); - return -1; - } - - std::string name=p->getName(); - if (!strncpy(buffer, name.c_str(), buffersize)) { - debugWarning("Could not copy name\n"); - return -1; - } else return 0; -} - -int ffado_streaming_get_playback_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); - if(!p) { - debugWarning("Could not get playback port at index %d\n",i); - return -1; - } - - std::string name=p->getName(); - if (!strncpy(buffer, name.c_str(), buffersize)) { - debugWarning("Could not copy name\n"); - return -1; - } else return 0; -} - -ffado_streaming_stream_type ffado_streaming_get_capture_stream_type(ffado_device_t *dev, int i) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); - if(!p) { - debugWarning("Could not get capture port at index %d\n",i); - return ffado_stream_type_invalid; - } - switch(p->getPortType()) { - case Port::E_Audio: - return ffado_stream_type_audio; - case Port::E_Midi: - return ffado_stream_type_midi; - case Port::E_Control: - return ffado_stream_type_control; - default: - return ffado_stream_type_unknown; - } -} - -ffado_streaming_stream_type ffado_streaming_get_playback_stream_type(ffado_device_t *dev, int i) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); - if(!p) { - debugWarning("Could not get playback port at index %d\n",i); - return ffado_stream_type_invalid; - } - switch(p->getPortType()) { - case Port::E_Audio: - return ffado_stream_type_audio; - case Port::E_Midi: - return ffado_stream_type_midi; - case Port::E_Control: - return ffado_stream_type_control; - default: - return ffado_stream_type_unknown; - } -} - -int ffado_streaming_set_stream_buffer_type(ffado_device_t *dev, int i, - ffado_streaming_buffer_type t, enum Port::E_Direction direction) { - - Port *p=dev->processorManager->getPortByIndex(i, direction); - if(!p) { - debugWarning("Could not get %s port at index %d\n", - (direction==Port::E_Playback?"Playback":"Capture"),i); - return -1; - } - - switch(t) { - case ffado_buffer_type_int24: - if (!p->setDataType(Port::E_Int24)) { - debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); - return -1; - } - if (!p->setBufferType(Port::E_PointerBuffer)) { - debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); - return -1; - } - break; - case ffado_buffer_type_float: - if (!p->setDataType(Port::E_Float)) { - debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); - return -1; - } - if (!p->setBufferType(Port::E_PointerBuffer)) { - debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); - return -1; - } - break; - case ffado_buffer_type_midi: - if (!p->setDataType(Port::E_MidiEvent)) { - debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); - return -1; - } - if (!p->setBufferType(Port::E_RingBuffer)) { - debugWarning("%s: Could not set buffer type to Ringbuffer\n",p->getName().c_str()); - return -1; - } - break; - default: - debugWarning("%s: Unsupported buffer type\n",p->getName().c_str()); - return -1; - } - return 0; - -} - -int ffado_streaming_set_playback_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { - return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Playback); -} - -int ffado_streaming_set_capture_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { - return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Capture); -} - -int ffado_streaming_stream_onoff(ffado_device_t *dev, int i, - int on, enum Port::E_Direction direction) { - Port *p=dev->processorManager->getPortByIndex(i, direction); - if(!p) { - debugWarning("Could not get %s port at index %d\n", - (direction==Port::E_Playback?"Playback":"Capture"),i); - return -1; - } - if(on) { - p->enable(); - } else { - p->disable(); - } - return 0; -} - -int ffado_streaming_playback_stream_onoff(ffado_device_t *dev, int number, int on) { - return ffado_streaming_stream_onoff(dev, number, on, Port::E_Playback); -} - -int ffado_streaming_capture_stream_onoff(ffado_device_t *dev, int number, int on) { - return ffado_streaming_stream_onoff(dev, number, on, Port::E_Capture); -} - -// TODO: the way port buffers are set in the C api doesn't satisfy me -int ffado_streaming_set_capture_stream_buffer(ffado_device_t *dev, int i, char *buff) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); - - // use an assert here performancewise, - // it should already have failed before, if not correct - assert(p); - - p->useExternalBuffer(true); - p->setExternalBufferAddress((void *)buff); - - return 0; - -} - -int ffado_streaming_set_playback_stream_buffer(ffado_device_t *dev, int i, char *buff) { - Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); - // use an assert here performancewise, - // it should already have failed before, if not correct - assert(p); - - p->useExternalBuffer(true); - p->setExternalBufferAddress((void *)buff); - - return 0; -} - Index: /trunk/libffado/config.h.in =================================================================== --- /trunk/libffado/config.h.in (revision 734) +++ /trunk/libffado/config.h.in (revision 739) @@ -21,4 +21,7 @@ #define PACKAGE_VERSION "$VERSION-$REVISION" +/* Define to the api version */ +#define FFADO_API_VERSION $FFADO_API_VERSION + /* Define to 1 if SSE assembly is available. */ /*#define USE_SSE 1*/ Index: /trunk/libffado/tests/streaming/teststreaming.c =================================================================== --- /trunk/libffado/tests/streaming/teststreaming.c (revision 554) +++ /trunk/libffado/tests/streaming/teststreaming.c (revision 739) @@ -79,12 +79,7 @@ dev_options.nb_buffers=3; - dev_options.port=0; - dev_options.node_id=-1; - dev_options.realtime=1; dev_options.packetizer_priority=60; - dev_options.directions=0; - dev_options.verbose=5; @@ -92,5 +87,5 @@ dev_options.snoop_mode=0; - ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); + ffado_device_t *dev=ffado_streaming_init(device_info, dev_options); if (!dev) { Index: /trunk/libffado/tests/streaming/teststreaming2.c =================================================================== --- /trunk/libffado/tests/streaming/teststreaming2.c (revision 554) +++ /trunk/libffado/tests/streaming/teststreaming2.c (revision 739) @@ -81,11 +81,6 @@ dev_options.nb_buffers=3; - dev_options.port=0; - dev_options.node_id=-1; - dev_options.realtime=0; dev_options.packetizer_priority=60; - - dev_options.directions=0; dev_options.verbose=5; @@ -94,5 +89,5 @@ dev_options.snoop_mode=0; - ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); + ffado_device_t *dev=ffado_streaming_init(device_info, dev_options); if (!dev) { fprintf(stderr,"Could not init Ffado Streaming layer\n"); Index: /trunk/libffado/tests/streaming/teststreaming3.c =================================================================== --- /trunk/libffado/tests/streaming/teststreaming3.c (revision 554) +++ /trunk/libffado/tests/streaming/teststreaming3.c (revision 739) @@ -85,11 +85,6 @@ dev_options.nb_buffers=3; - dev_options.port=0; - dev_options.node_id=-1; - dev_options.realtime=1; dev_options.packetizer_priority=70; - - dev_options.directions=0; dev_options.verbose=5; @@ -98,5 +93,5 @@ dev_options.snoop_mode=0; - ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); + ffado_device_t *dev=ffado_streaming_init(device_info, dev_options); if (!dev) { Index: /trunk/libffado/tests/streaming/testmidistreaming1.c =================================================================== --- /trunk/libffado/tests/streaming/testmidistreaming1.c (revision 554) +++ /trunk/libffado/tests/streaming/testmidistreaming1.c (revision 739) @@ -170,11 +170,6 @@ dev_options.nb_buffers=3; - dev_options.port=0; - dev_options.node_id=-1; - dev_options.realtime=0; dev_options.packetizer_priority=60; - - dev_options.directions=0; dev_options.verbose=5; @@ -183,5 +178,5 @@ dev_options.snoop_mode=0; - ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); + ffado_device_t *dev=ffado_streaming_init(device_info, dev_options); if (!dev) { fprintf(stderr,"Could not init Ffado Streaming layer\n"); Index: /trunk/libffado/tests/test-ffado.cpp =================================================================== --- /trunk/libffado/tests/test-ffado.cpp (revision 734) +++ /trunk/libffado/tests/test-ffado.cpp (revision 739) @@ -207,5 +207,5 @@ m_deviceManager->setVerboseLevel(arguments.verbose); } - if ( !m_deviceManager->initialize( arguments.port ) ) { + if ( !m_deviceManager->initialize() ) { fprintf( stderr, "Could not initialize device manager\n" ); delete m_deviceManager; @@ -238,5 +238,5 @@ m_deviceManager->setVerboseLevel(arguments.verbose); } - if ( !m_deviceManager->initialize( arguments.port ) ) { + if ( !m_deviceManager->initialize() ) { fprintf( stderr, "Could not initialize device manager\n" ); delete m_deviceManager; @@ -295,5 +295,5 @@ m_deviceManager->setVerboseLevel(arguments.verbose); } - if ( !m_deviceManager->initialize( arguments.port ) ) { + if ( !m_deviceManager->initialize() ) { fprintf( stderr, "Could not initialize device manager\n" ); delete m_deviceManager; Index: /trunk/libffado/libffado/ffado.h =================================================================== --- /trunk/libffado/libffado/ffado.h (revision 734) +++ /trunk/libffado/libffado/ffado.h (revision 739) @@ -29,11 +29,10 @@ #define FFADO_MAX_NAME_LEN 256 -#define FFADO_BOUNCE_SERVER_VENDORNAME "FFADO Server" -#define FFADO_BOUNCE_SERVER_MODELNAME "ffado-server" - -#define FFADO_BOUNCE_SERVER_GETXMLDESCRIPTION_CMD -#define AVC1394_SUBUNIT_TYPE_FFADO_BOUNCE_SERVER 0x0D - -#define FFADO_API_VERSION 2 +#include + +#define FFADO_STREAMING_MAX_URL_LENGTH 2048 + +#define FFADO_IGNORE_CAPTURE (1<<0) +#define FFADO_IGNORE_PLAYBACK (1<<1) enum ffado_direction { @@ -48,19 +47,4 @@ #endif -ffado_handle_t -ffado_new_handle( int port ); - -int -ffado_destroy_handle( ffado_handle_t ffado_handle ); - -int -ffado_discover_devices( ffado_handle_t ffado_handle, int verbose_level ); - -int ffado_node_is_valid_ffado_device(ffado_handle_t fb_handle, int node_id); -int ffado_get_nb_devices_on_bus(ffado_handle_t fb_handle); - -int ffado_get_device_node_id(ffado_handle_t fb_handle, int device_nr); -int ffado_set_samplerate(ffado_handle_t ffado_handle, int node_id, int samplerate); - /* ABI stuff */ const char* @@ -75,29 +59,4 @@ will disapear as soon bug is fixed */ void ffado_sleep_after_avc_command( int time ); - -#ifdef __cplusplus -} -#endif - -#endif /* FFADO_H */ - -/* ffado_streaming.h - * - * Specification for the FFADO Streaming API - * - */ -#ifndef __FFADO_STREAMING_H__ -#define __FFADO_STREAMING_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define FFADO_STREAMING_MAX_URL_LENGTH 2048 - -#define FFADO_IGNORE_CAPTURE (1<<0) -#define FFADO_IGNORE_PLAYBACK (1<<1) @@ -137,13 +96,53 @@ */ -typedef unsigned int ffado_sample_t; - - +typedef unsigned int ffado_sample_t; // FIXME typedef unsigned int ffado_nframes_t; - +#define FFADO_MAX_SPECSTRING_LENGTH 256 +#define FFADO_MAX_SPECSTRINGS 64 +/** + * This struct serves to define the devices that should be used by the library + * device_spec_strings is an array of pointers that should contain nb_device_spec_strings + * valid pointers to strings. + * + * The spec strings should be null terminated and can be no longer + * than FFADO_MAX_SPECSTRINGS. + * + * nb_device_spec_strings < FFADO_MAX_SPECSTRING_LENGTH + * nb_device_spec_strings >= 0 + * + * If nb_device_spec_strings == 0, all busses are scanned for attached devices, and + * all found devices that are supported are combined into one large pseudo-device. The + * device order is defined by the GUID of the device. Devices with lower GUID's will + * be the first ones. + * + * If multiple device specifications are present, the device order is defined as follows: + * - device(s) that correspond to a spec string with a lower index will be added before + * devices from higher indexes. + * - if a spec string results in multiple devices, they are sorted by GUID unless the + * spec format dictates otherwise. + * + * The actual meaning of the device specification should be one of the following: + * - Format 1: "hw:x[,y[,z]]" + * x = the firewire bus to use ('port' in raw1394 terminology) + * (mandatory) + * y = the node id the device currently has (bus resets might change that, but FFADO + * will track these changes and keep using the device specified on startup) + * (optional) + * z = the stream direction to use. + * 0 => capture (record) channels only + * 1 => playback channels only + * other/unspecified => both playback and capture + * (optional) + * + * - Format 2: the device alias as defined in the ffado config file (UNIMPLEMENTED) + */ typedef struct ffado_device_info { - /* TODO: How is the device specification done? */ -// ffado_device_info_location_type location_type; + unsigned int nb_device_spec_strings; + char **device_spec_strings; + + /* add some extra space to allow for future API extention + w/o breaking binary compatibility */ + int32_t reserved[32]; } ffado_device_info_t; @@ -153,35 +152,31 @@ typedef struct ffado_options { /* driver related setup */ - int sample_rate; /* this is acutally dictated by the device + int32_t sample_rate; /* * you can specify a value here or -1 to autodetect */ /* buffer setup */ - int period_size; /* one period is the amount of frames that + int32_t period_size; /* one period is the amount of frames that * has to be sent or received in order for * a period boundary to be signalled. * (unit: frames) */ - int nb_buffers; /* the size of the frame buffer (in periods) */ + int32_t nb_buffers; /* the size of the frame buffer (in periods) */ /* packetizer thread options */ - int realtime; - int packetizer_priority; - - /* libffado related setup */ - int node_id; - int port; - - /* direction map */ - int directions; - + int32_t realtime; + int32_t packetizer_priority; + /* verbosity */ - int verbose; - + int32_t verbose; + /* slave mode */ - int slave_mode; - + int32_t slave_mode; /* snoop mode */ - int snoop_mode; + int32_t snoop_mode; + + /* add some extra space to allow for future API extention + w/o breaking binary compatibility */ + int32_t reserved[24]; } ffado_options_t; @@ -197,8 +192,11 @@ * A ffado_midi type stream is a stream of midi bytes. The bytes are 8bit UINT, * aligned as the first 8LSB's of the 32bit UINT of the read/write buffer. + * + * A ffado_control type stream is a stream that provides control information. The + * format of this control information is undefined, and the stream should be ignored. * */ typedef enum { - ffado_stream_type_invalid = -1, + ffado_stream_type_invalid = -1, ffado_stream_type_unknown = 0, ffado_stream_type_audio = 1, @@ -213,11 +211,8 @@ */ typedef enum { - ffado_buffer_type_per_stream = -1, // use this to use the per-stream read functions - ffado_buffer_type_int24 = 0, - ffado_buffer_type_float = 1, - ffado_buffer_type_midi = 2, -// ffado_buffer_type_uint32 = 2, -// ffado_buffer_type_double = 3, -// ... + ffado_buffer_type_per_stream = -1, // use this to use the per-stream read functions + ffado_buffer_type_int24 = 0, + ffado_buffer_type_float = 1, + ffado_buffer_type_midi = 2, } ffado_streaming_buffer_type; @@ -237,5 +232,6 @@ * */ -ffado_device_t *ffado_streaming_init (ffado_device_info_t *device_info, +ffado_device_t *ffado_streaming_init( + ffado_device_info_t device_info, ffado_options_t options); @@ -327,7 +323,5 @@ * */ - - - + /** * Sets the decode buffer for the stream. This allows for zero-copy decoding. Index: /trunk/libffado/SConstruct =================================================================== --- /trunk/libffado/SConstruct (revision 736) +++ /trunk/libffado/SConstruct (revision 739) @@ -206,4 +206,6 @@ env['REVISION'] = '' +env['FFADO_API_VERSION']="3" + env['PACKAGE'] = "libffado" env['VERSION'] = "1.999.7" Index: /trunk/libffado/support/firmware/fireworks-downloader.cpp =================================================================== --- /trunk/libffado/support/firmware/fireworks-downloader.cpp (revision 689) +++ /trunk/libffado/support/firmware/fireworks-downloader.cpp (revision 739) @@ -166,5 +166,5 @@ } - Device *dev = new Device( service, std::auto_ptr(configRom) ); + Device *dev = new Device( std::auto_ptr(configRom) ); if (dev == NULL) { debugError("Could not create FireWorks::Device\n"); Index: /trunk/libffado/support/dbus/ffado-dbus-server.cpp =================================================================== --- /trunk/libffado/support/dbus/ffado-dbus-server.cpp (revision 730) +++ /trunk/libffado/support/dbus/ffado-dbus-server.cpp (revision 739) @@ -213,5 +213,5 @@ return exitfunction(-1); } - if ( !m_deviceManager->initialize( arguments.port ) ) { + if ( !m_deviceManager->initialize() ) { debugError("Could not initialize device manager\n" ); delete m_deviceManager;