Changeset 750

Show
Ignore:
Timestamp:
11/30/07 14:18:26 (16 years ago)
Author:
ppalmers
Message:

Code refactoring. Tries to simplify things and tries to put all code where it belongs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/SConstruct

    r742 r750  
    227227        env['REVISION'] = '' 
    228228 
    229 env['FFADO_API_VERSION']="3
     229env['FFADO_API_VERSION']="4
    230230 
    231231env['PACKAGE'] = "libffado" 
  • trunk/libffado/src/bebob/bebob_avdevice.cpp

    r744 r750  
    5555namespace BeBoB { 
    5656 
    57 AvDevice::AvDevice(std::auto_ptr< ConfigRom >( configRom ) ) 
    58     : GenericAVC::AvDevice( configRom ) 
     57AvDevice::AvDevice( DeviceManager& d, std::auto_ptr< ConfigRom >( configRom ) ) 
     58    : GenericAVC::AvDevice( d, configRom ) 
    5959    , m_Mixer ( 0 ) 
    6060{ 
     
    9090 
    9191FFADODevice * 
    92 AvDevice::createDevice(std::auto_ptr<ConfigRom>( configRom )) 
     92AvDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
    9393{ 
    9494    unsigned int vendorId = configRom->getNodeVendorId(); 
     
    9797    switch (vendorId) { 
    9898        case FW_VENDORID_TERRATEC: 
    99             return new Terratec::PhaseSeriesDevice(configRom); 
     99            return new Terratec::PhaseSeriesDevice(d, configRom); 
    100100        case FW_VENDORID_FOCUSRITE: 
    101101            switch(modelId) { 
    102102                case 0x00000003: 
    103103                case 0x00000006: 
    104                     return new Focusrite::SaffireProDevice(configRom); 
     104                    return new Focusrite::SaffireProDevice(d, configRom); 
    105105                case 0x00000000: 
    106                     return new Focusrite::SaffireDevice(configRom); 
     106                    return new Focusrite::SaffireDevice(d, configRom); 
    107107                default: // return a plain BeBoB device 
    108                     return new AvDevice(configRom); 
     108                    return new AvDevice(d, configRom); 
    109109           } 
    110110        default: 
    111             return new AvDevice(configRom); 
     111            return new AvDevice(d, configRom); 
    112112    } 
    113113    return NULL; 
  • trunk/libffado/src/bebob/bebob_avdevice.h

    r744 r750  
    6060class AvDevice : public GenericAVC::AvDevice { 
    6161public: 
    62     AvDevice( std::auto_ptr<ConfigRom>( configRom )); 
     62    AvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    6363    virtual ~AvDevice(); 
    6464 
     
    6868    virtual bool discover(); 
    6969 
    70     static FFADODevice * createDevice( std::auto_ptr<ConfigRom>( configRom )); 
     70    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    7171 
    7272    virtual AVC::Subunit* createSubunit(AVC::Unit& unit, 
  • trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp

    r742 r750  
    3030namespace Focusrite { 
    3131 
    32 FocusriteDevice::FocusriteDevice( std::auto_ptr<ConfigRom>( configRom )) 
    33     : BeBoB::AvDevice( configRom) 
     32FocusriteDevice::FocusriteDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     33    : BeBoB::AvDevice( d, configRom) 
    3434{ 
    3535    debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::FocusriteDevice (NodeID %d)\n", 
  • trunk/libffado/src/bebob/focusrite/focusrite_generic.h

    r742 r750  
    136136class FocusriteDevice : public BeBoB::AvDevice { 
    137137public: 
    138     FocusriteDevice(std::auto_ptr<ConfigRom>( configRom )); 
     138    FocusriteDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    139139    virtual ~FocusriteDevice() {}; 
    140140 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffire.cpp

    r742 r750  
    2828namespace Focusrite { 
    2929 
    30 SaffireDevice::SaffireDevice( std::auto_ptr<ConfigRom>( configRom )) 
    31     : FocusriteDevice( configRom) 
     30SaffireDevice::SaffireDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     31    : FocusriteDevice( d, configRom) 
    3232{ 
    3333    debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::SaffireDevice (NodeID %d)\n", 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffire.h

    r742 r750  
    142142class SaffireDevice : public FocusriteDevice { 
    143143public: 
    144     SaffireDevice(std::auto_ptr<ConfigRom>( configRom )); 
     144    SaffireDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    145145    virtual ~SaffireDevice() {}; 
    146146 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.cpp

    r742 r750  
    2828namespace Focusrite { 
    2929 
    30 SaffireProDevice::SaffireProDevice(std::auto_ptr<ConfigRom>( configRom )) 
    31     : FocusriteDevice( configRom ) 
     30SaffireProDevice::SaffireProDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     31    : FocusriteDevice( d, configRom ) 
    3232    , m_MixerContainer( NULL ) 
    3333    , m_ControlContainer( NULL ) 
  • trunk/libffado/src/bebob/focusrite/focusrite_saffirepro.h

    r742 r750  
    302302 
    303303public: 
    304     SaffireProDevice(std::auto_ptr<ConfigRom>( configRom )); 
     304    SaffireProDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    305305    virtual ~SaffireProDevice(); 
    306306 
  • trunk/libffado/src/bebob/terratec/terratec_device.cpp

    r742 r750  
    2727namespace Terratec { 
    2828 
    29 PhaseSeriesDevice::PhaseSeriesDevice(std::auto_ptr<ConfigRom>( configRom )) 
    30     : BeBoB::AvDevice( configRom) 
     29PhaseSeriesDevice::PhaseSeriesDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     30    : BeBoB::AvDevice( d, configRom) 
    3131{ 
    3232    debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Terratec::PhaseSeriesDevice (NodeID %d)\n", 
  • trunk/libffado/src/bebob/terratec/terratec_device.h

    r742 r750  
    3434class PhaseSeriesDevice : public BeBoB::AvDevice { 
    3535public: 
    36     PhaseSeriesDevice( std::auto_ptr<ConfigRom>( configRom )); 
     36    PhaseSeriesDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    3737    virtual ~PhaseSeriesDevice(); 
    3838 
  • trunk/libffado/src/devicemanager.cpp

    r745 r750  
    3232 
    3333#include "libstreaming/generic/StreamProcessor.h" 
     34#include "libstreaming/StreamProcessorManager.h" 
    3435 
    3536#include "debugmodule/debugmodule.h" 
     
    111112} 
    112113 
    113 void 
    114 DeviceManager::setVerboseLevel(int l) 
    115 
    116     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 
    117     setDebugLevel(l); 
    118     Control::Element::setVerboseLevel(l); 
    119     for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
    120           it != m_avDevices.end(); 
    121           ++it ) 
    122     { 
    123         (*it)->setVerboseLevel(l); 
     114bool 
     115DeviceManager::setThreadParameters(bool rt, int priority) { 
     116    if (!m_processorManager.setThreadParameters(rt, priority)) { 
     117        debugError("Could not set processor manager thread parameters\n"); 
     118        return false; 
    124119    } 
    125120    for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); 
     
    127122          ++it ) 
    128123    { 
    129         (*it)->setVerboseLevel(l); 
    130     } 
    131 
    132  
    133 void 
    134 DeviceManager::show() { 
    135     debugOutput(DEBUG_LEVEL_NORMAL, "===== Device Manager =====\n"); 
    136     Control::Element::show(); 
    137  
    138     int i=0; 
    139     for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); 
    140           it != m_1394Services.end(); 
    141           ++it ) 
    142     { 
    143         debugOutput(DEBUG_LEVEL_NORMAL, "--- IEEE1394 Service %2d ---\n", i++); 
    144         (*it)->show(); 
    145     } 
    146  
    147     i=0; 
    148     for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
    149         it != m_avDevices.end(); 
    150         ++it ) 
    151     { 
    152         FFADODevice* avDevice = *it; 
    153         debugOutput(DEBUG_LEVEL_NORMAL, "--- Device %2d ---\n", i++); 
    154         avDevice->showDevice(); 
    155  
    156         debugOutput(DEBUG_LEVEL_NORMAL, "Clock sync sources:\n"); 
    157         FFADODevice::ClockSourceVector sources=avDevice->getSupportedClockSources(); 
    158         for ( FFADODevice::ClockSourceVector::const_iterator it 
    159                 = sources.begin(); 
    160             it != sources.end(); 
    161             ++it ) 
    162         { 
    163             FFADODevice::ClockSource c=*it; 
    164             debugOutput(DEBUG_LEVEL_NORMAL, " Type: %s, Id: %2d, Valid: %1d, Active: %1d, Locked %1d, Slipping: %1d, Description: %s\n", 
    165                 FFADODevice::ClockSourceTypeToString(c.type), c.id, c.valid, c.active, c.locked, c.slipping, c.description.c_str()); 
    166         } 
    167     } 
     124        if (!(*it)->setThreadParameters(rt, priority)) { 
     125            debugError("Could not set 1394 service thread parameters\n"); 
     126            return false; 
     127        } 
     128    } 
     129    m_thread_realtime = rt; 
     130    m_thread_priority = priority; 
     131    return true; 
    168132} 
    169133 
     
    186150            return false; 
    187151        } 
     152        tmp1394Service->setVerboseLevel( getDebugLevel() ); 
    188153        m_1394Services.push_back(tmp1394Service); 
    189154 
     155        tmp1394Service->setThreadParameters(m_thread_realtime, m_thread_priority); 
    190156        if ( !tmp1394Service->initialize( port ) ) { 
    191157            debugFatal( "Could not initialize Ieee1349Service object for port %d\n", port ); 
     
    203169 
    204170        tmp1394Service->addBusResetHandler( tmp_busreset_functor ); 
    205         tmp1394Service->setVerboseLevel( getDebugLevel() ); 
    206     } 
     171    } 
     172 
    207173    return true; 
    208174} 
     
    333299                        avDevice->setVerboseLevel( getDebugLevel() ); 
    334300                    } else if ( avDevice->discover() ) { 
    335                         debugOutput( DEBUG_LEVEL_VERBOSE, "discovering successful\n" ); 
     301                        debugOutput( DEBUG_LEVEL_VERBOSE, "discovery successful\n" ); 
    336302                    } else { 
    337303                        debugError( "could not discover device\n" ); 
     
    354320                        debugOutput( DEBUG_LEVEL_VERBOSE, "No cached version of AVC model created\n" ); 
    355321                    } 
    356  
    357322                    m_avDevices.push_back( avDevice ); 
    358323 
     
    382347            } 
    383348        } 
    384         show(); 
     349        showDeviceInfo(); 
    385350        return true; 
    386351    } else { // slave mode 
     
    434399} 
    435400 
     401bool 
     402DeviceManager::initStreaming() 
     403{ 
     404    // iterate over the found devices 
     405    // add the stream processors of the devices to the managers 
     406    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     407        it != m_avDevices.end(); 
     408        ++it ) 
     409    { 
     410        FFADODevice *device = *it; 
     411        assert(device); 
     412 
     413        debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); 
     414 
     415        if (!device->lock()) { 
     416            debugWarning("Could not lock device, skipping device (%p)!\n", device); 
     417            continue; 
     418        } 
     419 
     420        debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", 
     421                    m_processorManager.getNominalRate(), device); 
     422 
     423        // Set the device's sampling rate to that requested 
     424        // FIXME: does this really belong here?  If so we need to handle errors. 
     425        if (!device->setSamplingFrequency(m_processorManager.getNominalRate())) { 
     426            debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", 
     427                        m_processorManager.getNominalRate(), device); 
     428 
     429            // try again: 
     430            if (!device->setSamplingFrequency(m_processorManager.getNominalRate())) { 
     431                debugFatal("Could not set sampling frequency to %d\n",m_processorManager.getNominalRate()); 
     432                return false; 
     433            } 
     434        } 
     435        // prepare the device 
     436        device->prepare(); 
     437    } 
     438 
     439    // set the sync source 
     440    if (!m_processorManager.setSyncSource(getSyncSource())) { 
     441        debugWarning("Could not set processorManager sync source (%p)\n", 
     442            getSyncSource()); 
     443    } 
     444    return true; 
     445} 
     446 
     447bool 
     448DeviceManager::prepareStreaming() 
     449{ 
     450    if (!m_processorManager.prepare()) { 
     451        debugFatal("Could not prepare streaming...\n"); 
     452        return false; 
     453    } 
     454    return true; 
     455} 
     456 
     457bool 
     458DeviceManager::finishStreaming() { 
     459    bool result = true; 
     460    // iterate over the found devices 
     461    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     462        it != m_avDevices.end(); 
     463        ++it ) 
     464    { 
     465        debugOutput(DEBUG_LEVEL_VERBOSE, "Unlocking device (%p)\n", *it); 
     466 
     467        if (!(*it)->unlock()) { 
     468            debugWarning("Could not unlock device (%p)!\n", *it); 
     469            result = false; 
     470        } 
     471    } 
     472    return result; 
     473} 
     474 
     475bool 
     476DeviceManager::startStreaming() { 
     477    // create the connections for all devices 
     478    // iterate over the found devices 
     479    // add the stream processors of the devices to the managers 
     480    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     481        it != m_avDevices.end(); 
     482        ++it ) 
     483    { 
     484        FFADODevice *device = *it; 
     485        assert(device); 
     486 
     487        int j=0; 
     488        for(j=0; j < device->getStreamCount(); j++) { 
     489        debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %p\n", j, device); 
     490            // start the stream 
     491            if (!device->startStreamByIndex(j)) { 
     492                debugWarning("Could not start stream %d of device %p\n", j, device); 
     493                continue; 
     494            } 
     495        } 
     496 
     497        if (!device->enableStreaming()) { 
     498            debugWarning("Could not enable streaming on device %p!\n", device); 
     499        } 
     500    } 
     501 
     502    if(m_processorManager.start()) { 
     503        return true; 
     504    } else { 
     505        stopStreaming(); 
     506        return false; 
     507    } 
     508} 
     509 
     510bool 
     511DeviceManager::resetStreaming() { 
     512    return true; 
     513} 
     514 
     515bool 
     516DeviceManager::stopStreaming() 
     517{ 
     518    bool result = true; 
     519    m_processorManager.stop(); 
     520 
     521    // create the connections for all devices 
     522    // iterate over the found devices 
     523    // add the stream processors of the devices to the managers 
     524    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     525        it != m_avDevices.end(); 
     526        ++it ) 
     527    { 
     528        FFADODevice *device = *it; 
     529        assert(device); 
     530 
     531        if (!device->disableStreaming()) { 
     532            debugWarning("Could not disable streaming on device %p!\n", device); 
     533        } 
     534 
     535        int j=0; 
     536        for(j=0; j < device->getStreamCount(); j++) { 
     537            debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %p\n", j, device); 
     538            // stop the stream 
     539            // start the stream 
     540            if (!device->stopStreamByIndex(j)) { 
     541                debugWarning("Could not stop stream %d of device %p\n", j, device); 
     542                result = false; 
     543                continue; 
     544            } 
     545        } 
     546    } 
     547    return result; 
     548} 
     549 
     550bool 
     551DeviceManager::waitForPeriod() { 
     552    if(m_processorManager.waitForPeriod()) { 
     553        return true; 
     554    } else { 
     555        debugWarning("XRUN detected\n"); 
     556        // do xrun recovery 
     557        m_processorManager.handleXrun(); 
     558        return false; 
     559    } 
     560} 
     561 
     562bool 
     563DeviceManager::setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers) { 
     564    m_processorManager.setPeriodSize(period); 
     565    m_processorManager.setNominalRate(rate); 
     566    m_processorManager.setNbBuffers(nb_buffers); 
     567    return true; 
     568} 
     569 
    436570FFADODevice* 
    437571DeviceManager::getDriverForDevice( std::auto_ptr<ConfigRom>( configRom ), 
     
    441575    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying BeBoB...\n" ); 
    442576    if ( BeBoB::AvDevice::probe( *configRom.get() ) ) { 
    443         return BeBoB::AvDevice::createDevice( configRom ); 
     577        return BeBoB::AvDevice::createDevice( *this, configRom ); 
    444578    } 
    445579#endif 
     
    448582    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Generic AV/C...\n" ); 
    449583    if ( GenericAVC::AvDevice::probe( *configRom.get() ) ) { 
    450         return GenericAVC::AvDevice::createDevice( configRom ); 
     584        return GenericAVC::AvDevice::createDevice( *this, configRom ); 
    451585    } 
    452586#endif 
     
    455589    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying ECHO Audio FireWorks...\n" ); 
    456590    if ( FireWorks::Device::probe( *configRom.get() ) ) { 
    457         return FireWorks::Device::createDevice( configRom ); 
     591        return FireWorks::Device::createDevice( *this, configRom ); 
    458592    } 
    459593#endif 
     
    462596    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying M-Audio...\n" ); 
    463597    if ( MAudio::AvDevice::probe( *configRom.get() ) ) { 
    464         return MAudio::AvDevice::createDevice( configRom ); 
     598        return MAudio::AvDevice::createDevice( *this, configRom ); 
    465599    } 
    466600#endif 
     
    469603    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Motu...\n" ); 
    470604    if ( Motu::MotuDevice::probe( *configRom.get() ) ) { 
    471         return Motu::MotuDevice::createDevice( configRom ); 
     605        return Motu::MotuDevice::createDevice( *this, configRom ); 
    472606    } 
    473607#endif 
     
    476610    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Dice...\n" ); 
    477611    if ( Dice::DiceAvDevice::probe( *configRom.get() ) ) { 
    478         return Dice::DiceAvDevice::createDevice( configRom ); 
     612        return Dice::DiceAvDevice::createDevice( *this, configRom ); 
    479613    } 
    480614#endif 
     
    483617    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Metric Halo...\n" ); 
    484618    if ( MetricHalo::MHAvDevice::probe( *configRom.get() ) ) { 
    485         return MetricHalo::MHAvDevice::createDevice( configRom ); 
     619        return MetricHalo::MHAvDevice::createDevice( *this, configRom ); 
    486620    } 
    487621#endif 
     
    490624    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying RME...\n" ); 
    491625    if ( Rme::RmeDevice::probe( *configRom.get() ) ) { 
    492         return Rme::RmeDevice::createDevice( configRom ); 
     626        return Rme::RmeDevice::createDevice( *this, configRom ); 
    493627    } 
    494628#endif 
     
    497631    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Bounce...\n" ); 
    498632    if ( Bounce::BounceDevice::probe( *configRom.get() ) ) { 
    499         return Bounce::BounceDevice::createDevice( configRom ); 
     633        return Bounce::BounceDevice::createDevice( *this, configRom ); 
    500634    } 
    501635#endif 
     
    615749    return true; 
    616750} 
     751 
     752 
     753void 
     754DeviceManager::setVerboseLevel(int l) 
     755{ 
     756    setDebugLevel(l); 
     757    Control::Element::setVerboseLevel(l); 
     758    m_processorManager.setVerboseLevel(l); 
     759    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     760          it != m_avDevices.end(); 
     761          ++it ) 
     762    { 
     763        (*it)->setVerboseLevel(l); 
     764    } 
     765    for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); 
     766          it != m_1394Services.end(); 
     767          ++it ) 
     768    { 
     769        (*it)->setVerboseLevel(l); 
     770    } 
     771    debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 
     772} 
     773 
     774void 
     775DeviceManager::showDeviceInfo() { 
     776    debugOutput(DEBUG_LEVEL_NORMAL, "===== Device Manager =====\n"); 
     777    Control::Element::show(); 
     778 
     779    int i=0; 
     780    for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); 
     781          it != m_1394Services.end(); 
     782          ++it ) 
     783    { 
     784        debugOutput(DEBUG_LEVEL_NORMAL, "--- IEEE1394 Service %2d ---\n", i++); 
     785        (*it)->show(); 
     786    } 
     787 
     788    i=0; 
     789    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
     790        it != m_avDevices.end(); 
     791        ++it ) 
     792    { 
     793        FFADODevice* avDevice = *it; 
     794        debugOutput(DEBUG_LEVEL_NORMAL, "--- Device %2d ---\n", i++); 
     795        avDevice->showDevice(); 
     796 
     797        debugOutput(DEBUG_LEVEL_NORMAL, "Clock sync sources:\n"); 
     798        FFADODevice::ClockSourceVector sources=avDevice->getSupportedClockSources(); 
     799        for ( FFADODevice::ClockSourceVector::const_iterator it 
     800                = sources.begin(); 
     801            it != sources.end(); 
     802            ++it ) 
     803        { 
     804            FFADODevice::ClockSource c=*it; 
     805            debugOutput(DEBUG_LEVEL_NORMAL, " Type: %s, Id: %2d, Valid: %1d, Active: %1d, Locked %1d, Slipping: %1d, Description: %s\n", 
     806                FFADODevice::ClockSourceTypeToString(c.type), c.id, c.valid, c.active, c.locked, c.slipping, c.description.c_str()); 
     807        } 
     808    } 
     809} 
     810void 
     811DeviceManager::showStreamingInfo() { 
     812    m_processorManager.dumpInfo(); 
     813} 
  • trunk/libffado/src/devicemanager.h

    r742 r750  
    3131#include "libieee1394/ieee1394service.h" 
    3232 
     33#include "libstreaming/StreamProcessorManager.h" 
     34 
    3335#include "libutil/OptionContainer.h" 
    3436#include "libcontrol/BasicElements.h" 
     
    6264    ~DeviceManager(); 
    6365 
     66    bool setThreadParameters(bool rt, int priority); 
     67 
    6468    bool initialize(); 
    6569    bool deinitialize(); 
     
    6973 
    7074    bool discover(); 
     75    bool initStreaming(); 
     76    bool prepareStreaming(); 
     77    bool finishStreaming(); 
     78    bool startStreaming(); 
     79    bool stopStreaming(); 
     80    bool resetStreaming(); 
     81    bool waitForPeriod(); 
     82    bool setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers); 
    7183 
    7284    bool isValidNode( int node ); 
     
    8092    Streaming::StreamProcessor *getSyncSource(); 
    8193 
    82     void show(); 
     94    void showDeviceInfo(); 
     95    void showStreamingInfo(); 
    8396 
    8497    // the Control::Container functions 
     
    102115    FunctorVector           m_busreset_functors; 
    103116 
     117public: // FIXME: this should be better 
     118    Streaming::StreamProcessorManager&  getStreamProcessorManager()  
     119        {return m_processorManager;}; 
     120private: 
     121    Streaming::StreamProcessorManager  m_processorManager; 
     122protected: 
    104123    std::vector<std::string>          m_SpecStrings; 
     124 
     125    bool m_thread_realtime; 
     126    int m_thread_priority; 
    105127 
    106128// debug stuff 
  • trunk/libffado/src/dice/dice_avdevice.cpp

    r748 r750  
    5252}; 
    5353 
    54 DiceAvDevice::DiceAvDevice( std::auto_ptr<ConfigRom>( configRom )) 
    55     : FFADODevice( configRom ) 
     54DiceAvDevice::DiceAvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     55    : FFADODevice( d, configRom ) 
    5656    , m_model( NULL ) 
    5757    , m_global_reg_offset (0xFFFFFFFFLU) 
     
    107107 
    108108FFADODevice * 
    109 DiceAvDevice::createDevice( std::auto_ptr<ConfigRom>( configRom )) 
     109DiceAvDevice::createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
    110110{ 
    111     return new DiceAvDevice( configRom ); 
     111    return new DiceAvDevice( d, configRom ); 
    112112} 
    113113 
  • trunk/libffado/src/dice/dice_avdevice.h

    r745 r750  
    5757    class DiceNotifier; 
    5858public: 
    59     DiceAvDevice( std::auto_ptr<ConfigRom>( configRom )); 
     59    DiceAvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    6060    ~DiceAvDevice(); 
    6161 
    6262    static bool probe( ConfigRom& configRom ); 
    63     static FFADODevice * createDevice( std::auto_ptr<ConfigRom>( configRom )); 
     63    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    6464    virtual bool discover(); 
    6565 
  • trunk/libffado/src/ffado.cpp

    r742 r750  
    3030 
    3131#include "../libffado/ffado.h" 
     32#include "libstreaming/generic/StreamProcessor.h" 
     33#include "libstreaming/generic/Port.h" 
    3234 
    3335#include "debugmodule/debugmodule.h" 
     
    3537#include "devicemanager.h" 
    3638#include "ffadodevice.h" 
    37 #include "libstreaming/StreamProcessorManager.h" 
    3839 
    3940#include <stdio.h> 
     
    8283} 
    8384 
    84  
    85 using namespace Streaming; 
    86  
    8785struct _ffado_device 
    8886{ 
    8987    DeviceManager * m_deviceManager; 
    90     StreamProcessorManager *processorManager; 
    9188 
    9289    ffado_options_t options; 
     
    117114 
    118115    dev->m_deviceManager->setVerboseLevel(dev->options.verbose); 
    119     if ( !dev->m_deviceManager->initialize() ) { 
    120         debugFatal( "Could not initialize device manager\n" ); 
    121         delete dev->m_deviceManager; 
    122         delete dev; 
    123         return 0; 
    124     } 
     116    dev->m_deviceManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 
    125117 
    126118    for (i = 0; i < device_info.nb_device_spec_strings; i++) { 
     
    133125        } 
    134126    } 
    135  
    136  
    137127    // create a processor manager to manage the actual stream 
    138128    // processors 
    139     dev->processorManager = new StreamProcessorManager( dev->options.period_size,  
    140                                                         dev->options.sample_rate, 
    141                                                         dev->options.nb_buffers); 
    142     if(!dev->processorManager) { 
    143             debugFatal("Could not create StreamProcessorManager\n"); 
    144             delete dev->m_deviceManager; 
    145             delete dev; 
    146             return 0; 
    147     } 
    148  
    149     dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 
    150  
    151     dev->processorManager->setVerboseLevel(dev->options.verbose); 
    152     if(!dev->processorManager->init()) { 
    153             debugFatal("Could not init StreamProcessorManager\n"); 
    154             delete dev->processorManager; 
    155             delete dev->m_deviceManager; 
    156             delete dev; 
    157             return 0; 
     129    if ( !dev->m_deviceManager->setStreamingParams(dev->options.period_size,  
     130                                                   dev->options.sample_rate, 
     131                                                   dev->options.nb_buffers)) 
     132    { 
     133        debugFatal( "Could not set streaming parameters of device manager\n" ); 
     134        delete dev->m_deviceManager; 
     135        delete dev; 
     136        return 0; 
    158137    } 
    159138 
     
    171150    } 
    172151 
     152    if ( !dev->m_deviceManager->initialize() ) { 
     153        debugFatal( "Could not initialize device manager\n" ); 
     154        delete dev->m_deviceManager; 
     155        delete dev; 
     156        return 0; 
     157    } 
    173158    // discover the devices on the bus 
    174159    if(!dev->m_deviceManager->discover()) { 
    175             debugFatal("Could not discover devices\n"); 
    176             delete dev->processorManager; 
    177             delete dev->m_deviceManager; 
    178             delete dev; 
    179             return 0; 
    180     } 
    181  
     160        debugFatal("Could not discover devices\n"); 
     161        delete dev->m_deviceManager; 
     162        delete dev; 
     163        return 0; 
     164    } 
    182165    // are there devices on the bus? 
    183     if(dev->m_deviceManager->getAvDeviceCount()==0) { 
    184             debugFatal("There are no devices on the bus\n"); 
    185             delete dev->processorManager; 
    186             delete dev->m_deviceManager; 
    187             delete dev; 
    188             return 0; 
    189     } 
    190  
    191     // iterate over the found devices 
    192     // add the stream processors of the devices to the managers 
    193     for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    194         FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    195         assert(device); 
    196  
    197         debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); 
    198  
    199         if (!device->lock()) { 
    200             debugWarning("Could not lock device, skipping device (%p)!\n", device); 
    201             continue; 
    202         } 
    203  
    204         debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", 
    205                     dev->options.sample_rate, device); 
    206  
    207         // Set the device's sampling rate to that requested 
    208         // FIXME: does this really belong here?  If so we need to handle errors. 
    209         if (!device->setSamplingFrequency(dev->options.sample_rate)) { 
    210             debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", 
    211                         dev->options.sample_rate, device); 
    212  
    213             // try again: 
    214             if (!device->setSamplingFrequency(dev->options.sample_rate)) { 
    215                 delete dev->processorManager; 
    216                 delete dev->m_deviceManager; 
    217                 delete dev; 
    218                 debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); 
    219                 return 0; 
    220             } 
    221         } 
    222  
    223         // prepare the device 
    224         device->prepare(); 
    225         int j=0; 
    226         for(j=0; j<device->getStreamCount();j++) { 
    227             StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); 
    228             debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); 
    229             if (!dev->processorManager->registerProcessor(streamproc)) { 
    230                 delete dev->processorManager; 
    231                 delete dev->m_deviceManager; 
    232                 delete dev; 
    233                 debugFatal("Could not register stream processor (%p) with the Processor manager\n", streamproc); 
    234                 return 0; 
    235             } 
    236         } 
    237     } 
    238  
    239     // set the sync source 
    240     if (!dev->processorManager->setSyncSource(dev->m_deviceManager->getSyncSource())) { 
    241         debugWarning("Could not set processorManager sync source (%p)\n", 
    242             dev->m_deviceManager->getSyncSource()); 
    243     } 
    244  
     166    if(dev->m_deviceManager->getAvDeviceCount() == 0) { 
     167        debugFatal("There are no devices on the bus\n"); 
     168        delete dev->m_deviceManager; 
     169        delete dev; 
     170        return 0; 
     171    } 
     172    // prepare here or there are no ports for jack 
     173    if(!dev->m_deviceManager->initStreaming()) { 
     174        debugFatal("Could not init the streaming system\n"); 
     175        return 0; 
     176    } 
    245177    // we are ready! 
    246     debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); 
    247178    return dev; 
    248  
    249179} 
    250180 
    251181int ffado_streaming_prepare(ffado_device_t *dev) { 
    252182    debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
    253  
    254     if (!dev->processorManager->prepare()) { 
    255         debugFatal("Could not prepare streaming...\n"); 
    256         return false; 
    257     } 
    258  
    259     return true; 
     183    // prepare here or there are no ports for jack 
     184    if(!dev->m_deviceManager->prepareStreaming()) { 
     185        debugFatal("Could not prepare the streaming system\n"); 
     186        return 0; 
     187    } 
     188    return 0; 
    260189} 
    261190 
    262191void ffado_streaming_finish(ffado_device_t *dev) { 
    263     unsigned int i=0; 
    264  
    265192    assert(dev); 
    266  
    267     // iterate over the found devices 
    268     for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    269         FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    270         assert(device); 
    271  
    272         debugOutput(DEBUG_LEVEL_VERBOSE, "Unlocking device (%p)\n", device); 
    273  
    274         if (!device->unlock()) { 
    275             debugWarning("Could not unlock device (%p)!\n", device); 
    276         } 
    277     } 
    278  
    279     delete dev->processorManager; 
     193    if(!dev->m_deviceManager->finishStreaming()) { 
     194        debugError("Could not finish the streaming\n"); 
     195    } 
    280196    delete dev->m_deviceManager; 
    281197    delete dev; 
    282  
    283198    return; 
    284199} 
    285200 
    286201int ffado_streaming_start(ffado_device_t *dev) { 
    287     unsigned int i=0; 
    288202    debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Start -------------\n"); 
    289  
    290     // create the connections for all devices 
    291     // iterate over the found devices 
    292     // add the stream processors of the devices to the managers 
    293     for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    294         FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    295         assert(device); 
    296  
    297         int j=0; 
    298         for(j=0; j<device->getStreamCount();j++) { 
    299         debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %d\n",j,i); 
    300             // start the stream 
    301             if (!device->startStreamByIndex(j)) { 
    302                 debugWarning("Could not start stream %d of device %d\n",j,i); 
    303                 continue; 
    304             } 
    305         } 
    306  
    307         if (!device->enableStreaming()) { 
    308             debugWarning("Could not enable streaming on device %d!\n",i); 
    309         } 
    310     } 
    311  
    312     if(dev->processorManager->start()) { 
    313         return 0; 
    314     } else { 
    315         ffado_streaming_stop(dev); 
    316         return -1; 
    317     } 
     203    if(!dev->m_deviceManager->startStreaming()) { 
     204        debugFatal("Could not start the streaming system\n"); 
     205        return -1; 
     206    } 
     207    return 0; 
    318208} 
    319209 
    320210int ffado_streaming_stop(ffado_device_t *dev) { 
    321     unsigned int i; 
    322211    debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); 
    323  
    324     dev->processorManager->stop(); 
    325  
    326     // create the connections for all devices 
    327     // iterate over the found devices 
    328     // add the stream processors of the devices to the managers 
    329     for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 
    330         FFADODevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 
    331         assert(device); 
    332  
    333         if (!device->disableStreaming()) { 
    334             debugWarning("Could not disable streaming on device %d!\n",i); 
    335         } 
    336  
    337         int j=0; 
    338         for(j=0; j<device->getStreamCount();j++) { 
    339             debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); 
    340             // stop the stream 
    341             // start the stream 
    342             if (!device->stopStreamByIndex(j)) { 
    343                 debugWarning("Could not stop stream %d of device %d\n",j,i); 
    344                 continue; 
    345             } 
    346         } 
    347     } 
    348  
     212    if(!dev->m_deviceManager->stopStreaming()) { 
     213        debugFatal("Could not stop the streaming system\n"); 
     214        return -1; 
     215    } 
    349216    return 0; 
    350217} 
     
    352219int ffado_streaming_reset(ffado_device_t *dev) { 
    353220    debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); 
    354  
    355     // dev->processorManager->reset(); 
    356  
     221    if(!dev->m_deviceManager->resetStreaming()) { 
     222        debugFatal("Could not reset the streaming system\n"); 
     223        return -1; 
     224    } 
    357225    return 0; 
    358226} 
     
    367235        debugOutputShort(DEBUG_LEVEL_VERBOSE, "\nffado_streaming_wait\n"); 
    368236        debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
    369         debugOutputShort(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); 
     237        debugOutputShort(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n", xruns); 
    370238        debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); 
    371         dev->processorManager->dumpInfo(); 
     239        dev->m_deviceManager->showStreamingInfo(); 
    372240        debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 
    373241        periods_print+=100; 
    374242    } 
    375243 
    376     if(dev->processorManager->waitForPeriod()) { 
     244    if(dev->m_deviceManager->waitForPeriod()) { 
    377245        return dev->options.period_size; 
    378246    } else { 
    379         debugWarning("XRUN detected\n"); 
    380  
    381         // do xrun recovery 
    382         dev->processorManager->handleXrun(); 
    383247        xruns++; 
    384248        return -1; 
     
    387251 
    388252int ffado_streaming_transfer_capture_buffers(ffado_device_t *dev) { 
    389     return dev->processorManager->transfer(StreamProcessor::ePT_Receive); 
     253    return dev->m_deviceManager->getStreamProcessorManager().transfer(Streaming::StreamProcessor::ePT_Receive); 
    390254} 
    391255 
    392256int ffado_streaming_transfer_playback_buffers(ffado_device_t *dev) { 
    393     return dev->processorManager->transfer(StreamProcessor::ePT_Transmit); 
     257    return dev->m_deviceManager->getStreamProcessorManager().transfer(Streaming::StreamProcessor::ePT_Transmit); 
    394258} 
    395259 
    396260int ffado_streaming_transfer_buffers(ffado_device_t *dev) { 
    397     return dev->processorManager->transfer(); 
     261    return dev->m_deviceManager->getStreamProcessorManager().transfer(); 
    398262} 
    399263 
    400264 
    401265int ffado_streaming_write(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { 
    402     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     266    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Playback); 
    403267    // use an assert here performancewise, 
    404268    // it should already have failed before, if not correct 
     
    409273 
    410274int ffado_streaming_read(ffado_device_t *dev, int i, ffado_sample_t *buffer, int nsamples) { 
    411     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     275    Streaming::Port *p=dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Capture); 
    412276    // use an assert here performancewise, 
    413277    // it should already have failed before, if not correct 
     
    418282 
    419283int ffado_streaming_get_nb_capture_streams(ffado_device_t *dev) { 
    420     return dev->processorManager->getPortCount(Port::E_Capture); 
     284    return dev->m_deviceManager->getStreamProcessorManager().getPortCount(Streaming::Port::E_Capture); 
    421285} 
    422286 
    423287int ffado_streaming_get_nb_playback_streams(ffado_device_t *dev) { 
    424     return dev->processorManager->getPortCount(Port::E_Playback); 
     288    return dev->m_deviceManager->getStreamProcessorManager().getPortCount(Streaming::Port::E_Playback); 
    425289} 
    426290 
    427291int ffado_streaming_get_capture_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { 
    428     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     292    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Capture); 
    429293    if(!p) { 
    430294        debugWarning("Could not get capture port at index %d\n",i); 
     
    440304 
    441305int ffado_streaming_get_playback_stream_name(ffado_device_t *dev, int i, char* buffer, size_t buffersize) { 
    442     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     306    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Playback); 
    443307    if(!p) { 
    444308        debugWarning("Could not get playback port at index %d\n",i); 
     
    454318 
    455319ffado_streaming_stream_type ffado_streaming_get_capture_stream_type(ffado_device_t *dev, int i) { 
    456     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     320    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Capture); 
    457321    if(!p) { 
    458322        debugWarning("Could not get capture port at index %d\n",i); 
     
    460324    } 
    461325    switch(p->getPortType()) { 
    462     case Port::E_Audio: 
     326    case Streaming::Port::E_Audio: 
    463327        return ffado_stream_type_audio; 
    464     case Port::E_Midi: 
     328    case Streaming::Port::E_Midi: 
    465329        return ffado_stream_type_midi; 
    466     case Port::E_Control: 
     330    case Streaming::Port::E_Control: 
    467331        return ffado_stream_type_control; 
    468332    default: 
     
    472336 
    473337ffado_streaming_stream_type ffado_streaming_get_playback_stream_type(ffado_device_t *dev, int i) { 
    474     Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     338    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Playback); 
    475339    if(!p) { 
    476340        debugWarning("Could not get playback port at index %d\n",i); 
     
    478342    } 
    479343    switch(p->getPortType()) { 
    480     case Port::E_Audio: 
     344    case Streaming::Port::E_Audio: 
    481345        return ffado_stream_type_audio; 
    482     case Port::E_Midi: 
     346    case Streaming::Port::E_Midi: 
    483347        return ffado_stream_type_midi; 
    484     case Port::E_Control: 
     348    case Streaming::Port::E_Control: 
    485349        return ffado_stream_type_control; 
    486350    default: 
     
    490354 
    491355int ffado_streaming_set_stream_buffer_type(ffado_device_t *dev, int i, 
    492     ffado_streaming_buffer_type t, enum Port::E_Direction direction) { 
    493  
    494     Port *p=dev->processorManager->getPortByIndex(i, direction); 
     356    ffado_streaming_buffer_type t, enum Streaming::Port::E_Direction direction) { 
     357 
     358    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, direction); 
    495359    if(!p) { 
    496360        debugWarning("Could not get %s port at index %d\n", 
    497             (direction==Port::E_Playback?"Playback":"Capture"),i); 
     361            (direction==Streaming::Port::E_Playback?"Playback":"Capture"),i); 
    498362        return -1; 
    499363    } 
     
    501365    switch(t) { 
    502366    case ffado_buffer_type_int24: 
    503         if (!p->setDataType(Port::E_Int24)) { 
     367        if (!p->setDataType(Streaming::Port::E_Int24)) { 
    504368            debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); 
    505369            return -1; 
    506370        } 
    507         if (!p->setBufferType(Port::E_PointerBuffer)) { 
     371        if (!p->setBufferType(Streaming::Port::E_PointerBuffer)) { 
    508372            debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
    509373            return -1; 
     
    511375        break; 
    512376    case ffado_buffer_type_float: 
    513         if (!p->setDataType(Port::E_Float)) { 
     377        if (!p->setDataType(Streaming::Port::E_Float)) { 
    514378            debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); 
    515379            return -1; 
    516380        } 
    517         if (!p->setBufferType(Port::E_PointerBuffer)) { 
     381        if (!p->setBufferType(Streaming::Port::E_PointerBuffer)) { 
    518382            debugWarning("%s: Could not set buffer type to Pointerbuffer\n",p->getName().c_str()); 
    519383            return -1; 
     
    521385        break; 
    522386    case ffado_buffer_type_midi: 
    523         if (!p->setDataType(Port::E_MidiEvent)) { 
     387        if (!p->setDataType(Streaming::Port::E_MidiEvent)) { 
    524388            debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); 
    525389            return -1; 
    526390        } 
    527         if (!p->setBufferType(Port::E_RingBuffer)) { 
     391        if (!p->setBufferType(Streaming::Port::E_RingBuffer)) { 
    528392            debugWarning("%s: Could not set buffer type to Ringbuffer\n",p->getName().c_str()); 
    529393            return -1; 
     
    539403 
    540404int ffado_streaming_set_playback_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { 
    541     return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Playback); 
     405    return ffado_streaming_set_stream_buffer_type(dev, i, t, Streaming::Port::E_Playback); 
    542406} 
    543407 
    544408int ffado_streaming_set_capture_buffer_type(ffado_device_t *dev, int i, ffado_streaming_buffer_type t) { 
    545     return ffado_streaming_set_stream_buffer_type(dev, i, t, Port::E_Capture); 
     409    return ffado_streaming_set_stream_buffer_type(dev, i, t, Streaming::Port::E_Capture); 
    546410} 
    547411 
    548412int ffado_streaming_stream_onoff(ffado_device_t *dev, int i, 
    549     int on, enum Port::E_Direction direction) { 
    550     Port *p=dev->processorManager->getPortByIndex(i, direction); 
     413    int on, enum Streaming::Port::E_Direction direction) { 
     414    Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, direction); 
    551415    if(!p) { 
    552416        debugWarning("Could not get %s port at index %d\n", 
    553             (direction==Port::E_Playback?"Playback":"Capture"),i); 
     417            (direction==Streaming::Port::E_Playback?"Playback":"Capture"),i); 
    554418        return -1; 
    555419    } 
     
    563427 
    564428int ffado_streaming_playback_stream_onoff(ffado_device_t *dev, int number, int on) { 
    565     return ffado_streaming_stream_onoff(dev, number, on, Port::E_Playback); 
     429    return ffado_streaming_stream_onoff(dev, number, on, Streaming::Port::E_Playback); 
    566430} 
    567431 
    568432int ffado_streaming_capture_stream_onoff(ffado_device_t *dev, int number, int on) { 
    569     return ffado_streaming_stream_onoff(dev, number, on, Port::E_Capture); 
     433    return ffado_streaming_stream_onoff(dev, number, on, Streaming::Port::E_Capture); 
    570434} 
    571435 
    572436// TODO: the way port buffers are set in the C api doesn't satisfy me 
    573437int ffado_streaming_set_capture_stream_buffer(ffado_device_t *dev, int i, char *buff) { 
    574         Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 
     438        Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Capture); 
    575439 
    576440        // use an assert here performancewise, 
     
    586450 
    587451int ffado_streaming_set_playback_stream_buffer(ffado_device_t *dev, int i, char *buff) { 
    588         Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 
     452        Streaming::Port *p = dev->m_deviceManager->getStreamProcessorManager().getPortByIndex(i, Streaming::Port::E_Playback); 
    589453        // use an assert here performancewise, 
    590454        // it should already have failed before, if not correct 
  • trunk/libffado/src/ffadodevice.cpp

    r745 r750  
    3535IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_NORMAL ); 
    3636 
    37 FFADODevice::FFADODevice( std::auto_ptr<ConfigRom>( configRom )
     37FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )
    3838    : Control::Container() 
     39    , m_pDeviceManager( d ) 
    3940    , m_pConfigRom( configRom ) 
    4041{ 
  • trunk/libffado/src/ffadodevice.h

    r745 r750  
    3434#include <string> 
    3535 
     36class DeviceManager; 
    3637class ConfigRom; 
    3738class Ieee1394Service; 
     
    3940namespace Streaming { 
    4041    class StreamProcessor; 
     42    class StreamProcessorManager; 
    4143} 
    4244 
     
    5355{ 
    5456public: 
    55     FFADODevice( std::auto_ptr< ConfigRom >( configRom ) ); 
     57    FFADODevice( DeviceManager&, std::auto_ptr< ConfigRom >( configRom ) ); 
    5658 
    5759    virtual ~FFADODevice(); 
     
    418420        { return false; }; 
    419421 
    420  
     422    DeviceManager& getDeviceManager() 
     423        {return m_pDeviceManager;}; 
    421424private: 
    422425    std::auto_ptr<ConfigRom>( m_pConfigRom ); 
     426    DeviceManager& m_pDeviceManager; 
    423427protected: 
    424428    DECLARE_DEBUG_MODULE; 
  • trunk/libffado/src/fireworks/audiofire/audiofire_device.cpp

    r742 r750  
    3030namespace ECHO { 
    3131 
    32 AudioFire::AudioFire(std::auto_ptr<ConfigRom>( configRom )) 
    33     : FireWorks::Device(configRom) 
     32AudioFire::AudioFire( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     33    : FireWorks::Device( d, configRom) 
    3434{ 
    3535    debugOutput( DEBUG_LEVEL_VERBOSE, "Created FireWorks::ECHO::AudioFire (NodeID %d)\n", 
  • trunk/libffado/src/fireworks/audiofire/audiofire_device.h

    r742 r750  
    3535 
    3636public: 
    37     AudioFire(std::auto_ptr<ConfigRom>( configRom )); 
     37    AudioFire( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    3838    virtual ~AudioFire(); 
    3939 
  • trunk/libffado/src/fireworks/fireworks_device.cpp

    r745 r750  
    4343namespace FireWorks { 
    4444 
    45 Device::Device(std::auto_ptr<ConfigRom>( configRom )) 
    46     : GenericAVC::AvDevice(configRom) 
     45Device::Device(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     46    : GenericAVC::AvDevice( d, configRom) 
    4747    , m_efc_discovery_done ( false ) 
    4848    , m_MixerContainer ( NULL ) 
     
    146146 
    147147FFADODevice * 
    148 Device::createDevice(std::auto_ptr<ConfigRom>( configRom )) 
     148Device::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
    149149{ 
    150150    unsigned int vendorId = configRom->getNodeVendorId(); 
     
    152152 
    153153    switch(vendorId) { 
    154         case FW_VENDORID_ECHO: return new ECHO::AudioFire(configRom ); 
    155         default: return new Device(configRom ); 
     154        case FW_VENDORID_ECHO: return new ECHO::AudioFire(d, configRom ); 
     155        default: return new Device(d, configRom ); 
    156156    } 
    157157} 
  • trunk/libffado/src/fireworks/fireworks_device.h

    r742 r750  
    4242class Device : public GenericAVC::AvDevice { 
    4343public: 
    44     Device(std::auto_ptr<ConfigRom>( configRom )); 
     44    Device( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) ); 
    4545    virtual ~Device(); 
    4646     
    4747    static bool probe( ConfigRom& configRom ); 
    48     static FFADODevice * createDevice( std::auto_ptr<ConfigRom>( configRom )); 
     48    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    4949    virtual bool discover(); 
    5050 
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r748 r750  
    5151IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_NORMAL ); 
    5252 
    53 AvDevice::AvDevice(std::auto_ptr<ConfigRom>( configRom )) 
    54     : FFADODevice( configRom ) 
     53AvDevice::AvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     54    : FFADODevice( d, configRom ) 
    5555{ 
    5656    debugOutput( DEBUG_LEVEL_VERBOSE, "Created GenericAVC::AvDevice (NodeID %d)\n", 
     
    7474 
    7575FFADODevice * 
    76 AvDevice::createDevice(std::auto_ptr<ConfigRom>( configRom )) 
    77 { 
    78     return new AvDevice(configRom ); 
     76AvDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     77{ 
     78    return new AvDevice(d, configRom ); 
    7979} 
    8080 
     
    418418        return false; 
    419419    } 
    420     p=new Streaming::AmdtpReceiveStreamProcessor(*this, 
     420    p = new Streaming::AmdtpReceiveStreamProcessor(*this, 
    421421                             outputPlug->getNrOfChannels()); 
    422422 
  • trunk/libffado/src/genericavc/avc_avdevice.h

    r742 r750  
    4848class AvDevice : public FFADODevice, public AVC::Unit { 
    4949public: 
    50     AvDevice( std::auto_ptr<ConfigRom>( configRom )); 
     50    AvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    5151    virtual ~AvDevice() {}; 
    5252 
    5353    static bool probe( ConfigRom& configRom ); 
    5454    virtual bool discover(); 
    55     static FFADODevice * createDevice( std::auto_ptr<ConfigRom>( configRom )); 
     55    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    5656 
    5757    virtual bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r748 r750  
    2626#include "ARMHandler.h" 
    2727#include "cycletimer.h" 
     28#include "IsoHandlerManager.h" 
    2829 
    2930#include <libavc1394/avc1394.h> 
     
    3940#include <iomanip> 
    4041 
    41 #define FFADO_MAX_FIREWIRE_PORTS 8 
     42#define FFADO_MAX_FIREWIRE_PORTS 16 
    4243 
    4344IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL ); 
     
    4748    , m_port( -1 ) 
    4849    , m_threadRunning( false ) 
     50    , m_isoManager( new IsoHandlerManager( *this ) ) 
    4951{ 
    5052    pthread_mutex_init( &m_mutex, 0 ); 
     
    6365Ieee1394Service::~Ieee1394Service() 
    6466{ 
     67    delete m_isoManager; 
    6568    stopRHThread(); 
    6669    for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); 
     
    7982        raw1394_destroy_handle( m_handle ); 
    8083    } 
    81  
    8284    if ( m_resetHandle ) { 
    8385        raw1394_destroy_handle( m_resetHandle ); 
     
    148150    } 
    149151 
     152    // test the cycle timer read function 
     153    int err; 
     154    uint32_t cycle_timer; 
     155    uint64_t local_time; 
     156    err=raw1394_read_cycle_timer(m_handle, &cycle_timer, &local_time); 
     157    if(err) { 
     158        debugError("raw1394_read_cycle_timer failed.\n"); 
     159        debugError(" Error: %s\n", strerror(err)); 
     160        debugError(" Your system doesn't seem to support the raw1394_read_cycle_timer call\n"); 
     161        return false; 
     162    } 
     163 
    150164    m_port = port; 
    151165 
    152166    // obtain port name 
     167    raw1394handle_t tmp_handle = raw1394_new_handle(); 
     168    if ( tmp_handle == NULL ) { 
     169        debugError("Could not get temporaty libraw1394 handle.\n"); 
     170        return false; 
     171    } 
    153172    struct raw1394_portinfo pinf[FFADO_MAX_FIREWIRE_PORTS]; 
    154     int nb_detected_ports = raw1394_get_port_info(m_handle, pinf, FFADO_MAX_FIREWIRE_PORTS); 
     173    int nb_detected_ports = raw1394_get_port_info(tmp_handle, pinf, FFADO_MAX_FIREWIRE_PORTS); 
     174    raw1394_destroy_handle(tmp_handle); 
     175 
     176    if (nb_detected_ports < 0) { 
     177        debugError("Failed to detect number of ports\n"); 
     178        return false; 
     179    } 
    155180 
    156181    if(nb_detected_ports && port < FFADO_MAX_FIREWIRE_PORTS) { 
     
    165190    raw1394_set_userdata( m_handle, this ); 
    166191    raw1394_set_userdata( m_resetHandle, this ); 
     192    raw1394_set_userdata( m_rtHandle, this ); 
    167193    raw1394_set_bus_reset_handler( m_resetHandle, 
    168194                                   this->resetHandlerLowLevel ); 
     
    171197                                   this->armHandlerLowLevel ); 
    172198 
     199    if(!m_isoManager) { 
     200        debugFatal("No IsoHandlerManager available, bad!\n"); 
     201        return false; 
     202    } 
     203    m_isoManager->setVerboseLevel(getDebugLevel()); 
     204    if(!m_isoManager->init()) { 
     205        debugFatal("Could not initialize IsoHandlerManager\n"); 
     206        return false; 
     207    } 
     208 
    173209    startRHThread(); 
    174  
    175210    return true; 
     211} 
     212 
     213bool 
     214Ieee1394Service::setThreadParameters(bool rt, int priority) { 
     215    if (m_isoManager) { 
     216        return m_isoManager->setThreadParameters(rt, priority); 
     217    } else { 
     218        return true; 
     219    } 
    176220} 
    177221 
     
    930974Ieee1394Service::setVerboseLevel(int l) 
    931975{ 
     976    if (m_isoManager) m_isoManager->setVerboseLevel(l); 
     977    setDebugLevel(l); 
    932978    debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 
    933     setDebugLevel(l); 
    934979} 
    935980 
     
    939984    debugOutput( DEBUG_LEVEL_VERBOSE, "Port:  %d\n", getPort() ); 
    940985    debugOutput( DEBUG_LEVEL_VERBOSE, " Name: %s\n", getPortName().c_str() ); 
    941 
     986    debugOutputShort( DEBUG_LEVEL_NORMAL, "Iso handler info:\n"); 
     987    if (m_isoManager) m_isoManager->dumpInfo(); 
     988
  • trunk/libffado/src/libieee1394/ieee1394service.h

    r748 r750  
    4040 
    4141class ARMHandler; 
     42class IsoHandlerManager; 
    4243 
    4344class Ieee1394Service : public IEC61883 { 
     
    4748 
    4849    bool initialize( int port ); 
    49  
     50    bool setThreadParameters(bool rt, int priority); 
    5051   /** 
    5152    * @brief get number of ports (firewire adapters) in this machine 
     
    220221    bool freeIsoChannel(signed int channel); 
    221222 
     223    IsoHandlerManager& getIsoHandlerManager() {return *m_isoManager;}; 
    222224private: 
    223225    enum EAllocType { 
     
    273275    bool            m_threadRunning; 
    274276 
     277    IsoHandlerManager*      m_isoManager; 
     278 
    275279    typedef std::vector< Functor* > reset_handler_vec_t; 
    276280    reset_handler_vec_t m_busResetHandlers; 
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r748 r750  
    2323 
    2424#include "IsoHandler.h" 
    25 #include "../generic/StreamProcessor.h" 
    26  
    27 #include "libutil/TimeSource.h" 
    28 #include "libutil/SystemTimeSource.h" 
     25#include "ieee1394service.h"  
     26 
     27#include "libstreaming/generic/StreamProcessor.h" 
    2928 
    3029#include <errno.h> 
     
    3635#include <iostream> 
    3736using namespace std; 
    38  
    39 namespace Streaming 
    40 
     37using namespace Streaming; 
    4138 
    4239IMPL_DEBUG_MODULE( IsoHandler, IsoHandler, DEBUG_LEVEL_NORMAL ); 
     
    7875 
    7976/* Base class implementation */ 
    80 IsoHandler::IsoHandler(int port) 
    81    :  m_handle(0), m_handle_util(0), m_port(port), 
    82    m_buf_packets(400), m_max_packet_size(1024), m_irq_interval(-1), 
    83    m_packetcount(0), m_dropped(0), m_Client(0), 
    84    m_State(E_Created) 
    85 
    86 
    87  
    88 IsoHandler::IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq) 
    89    : m_handle(0), m_port(port), 
    90    m_buf_packets(buf_packets), m_max_packet_size( max_packet_size), 
    91    m_irq_interval(irq), 
    92    m_packetcount(0), m_dropped(0), m_Client(0), 
    93    m_State(E_Created) 
     77IsoHandler::IsoHandler(IsoHandlerManager& manager) 
     78   : m_manager(manager) 
     79   , m_handle(0) 
     80   , m_buf_packets(400) 
     81   , m_max_packet_size(1024) 
     82   , m_irq_interval(-1) 
     83   , m_packetcount(0) 
     84   , m_dropped(0) 
     85   , m_Client(0) 
     86   , m_State(E_Created) 
     87
     88
     89 
     90IsoHandler::IsoHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq) 
     91   : m_manager(manager) 
     92   , m_handle(0) 
     93   , m_buf_packets(buf_packets) 
     94   , m_max_packet_size( max_packet_size) 
     95   , m_irq_interval(irq) 
     96   , m_packetcount(0) 
     97   , m_dropped(0) 
     98   , m_Client(0) 
     99   , m_State(E_Created) 
    94100{ 
    95101} 
     
    102108// raw1394_destroy_handle() will do any iso system shutdown required. 
    103109//     raw1394_iso_shutdown(m_handle); 
    104  
    105110    if(m_handle) { 
    106111        if (m_State == E_Running) { 
    107             stop(); 
    108         } 
    109  
     112            disable(); 
     113        } 
    110114        raw1394_destroy_handle(m_handle); 
    111115    } 
    112  
    113     if(m_handle_util) raw1394_destroy_handle(m_handle_util); 
    114  
    115116} 
    116117 
     
    136137{ 
    137138    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) enter...\n",this); 
    138  
    139139    // check the state 
    140140    if(m_State != E_Created) { 
     
    144144 
    145145    // the main handle for the ISO traffic 
    146     m_handle = raw1394_new_handle_on_port( m_port ); 
     146    m_handle = raw1394_new_handle_on_port( m_manager.get1394Service().getPort() ); 
    147147    if ( !m_handle ) { 
    148148        if ( !errno ) { 
     
    155155    } 
    156156    raw1394_set_userdata(m_handle, static_cast<void *>(this)); 
    157  
    158     // a second handle for utility stuff 
    159     m_handle_util = raw1394_new_handle_on_port( m_port ); 
    160     if ( !m_handle_util ) { 
    161         if ( !errno ) { 
    162             debugError("libraw1394 not compatible\n"); 
    163         } else { 
    164             debugError("Could not get 1394 handle: %s\n", strerror(errno) ); 
    165             debugError("Are ieee1394 and raw1394 drivers loaded?\n"); 
    166         } 
    167  
    168         raw1394_destroy_handle(m_handle); 
    169         return false; 
    170     } 
    171     raw1394_set_userdata(m_handle_util, static_cast<void *>(this)); 
    172157 
    173158    // bus reset handling 
     
    181166    } 
    182167 
    183     // test the cycle timer read function 
    184     int err; 
    185     uint32_t cycle_timer; 
    186     uint64_t local_time; 
    187     err=raw1394_read_cycle_timer(m_handle_util, &cycle_timer, &local_time); 
    188     if(err) { 
    189         debugError("raw1394_read_cycle_timer failed.\n"); 
    190         debugError(" Error: %s\n", strerror(err)); 
    191         debugError(" Your system doesn't seem to support the raw1394_read_cycle_timer call\n"); 
    192         return false; 
    193     } 
    194  
    195168    // update the internal state 
    196169    m_State=E_Initialized; 
    197  
    198170    return true; 
    199171} 
     
    201173bool IsoHandler::prepare() 
    202174{ 
    203     debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) enter...\n",this); 
    204  
     175    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) prepare...\n", this); 
    205176    // check the state 
    206177    if(m_State != E_Initialized) { 
     
    208179        return false; 
    209180    } 
    210  
    211181    // Don't call until libraw1394's raw1394_new_handle() function has been 
    212182    // fixed to correctly initialise the iso_packet_infos field.  Bug is 
    213183    // confirmed present in libraw1394 1.2.1. 
    214  
    215184//     raw1394_iso_shutdown(m_handle); 
    216  
    217185    m_State = E_Prepared; 
    218  
    219     return true; 
    220 
    221  
    222 bool IsoHandler::start(int cycle) 
     186    return true; 
     187
     188 
     189bool IsoHandler::enable(int cycle) 
    223190{ 
    224191    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    225  
    226     // check the state 
    227     if(m_State != E_Prepared) { 
    228         debugError("Incorrect state, expected E_Prepared, got %d\n",(int)m_State); 
    229         return false; 
    230     } 
    231  
    232     m_State=E_Running; 
    233  
    234     return true; 
    235 
    236  
    237 bool IsoHandler::stop() 
     192    m_State = E_Running; 
     193    return true; 
     194
     195 
     196bool IsoHandler::disable() 
    238197{ 
    239198    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    240199 
    241200    // check state 
     201    if(m_State == E_Prepared) return true; 
    242202    if(m_State != E_Running) { 
    243203        debugError("Incorrect state, expected E_Running, got %d\n",(int)m_State); 
     
    249209    // don't know if it will help though. 
    250210    raw1394_iso_xmit_sync(m_handle); 
    251  
    252211    raw1394_iso_stop(m_handle); 
    253  
    254     m_State=E_Prepared; 
    255  
     212    m_State = E_Prepared; 
    256213    return true; 
    257214} 
     
    281238    if (m_Client) channel=m_Client->getChannel(); 
    282239 
    283     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Handler type    : %s\n", 
     240    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Handler type................: %s\n", 
    284241            (this->getType()==EHT_Receive ? "Receive" : "Transmit")); 
    285     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel   : %2d, %2d\n", 
    286             m_port, channel); 
    287     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Packet count    : %10d (%5d dropped)\n", 
     242    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel...............: %2d, %2d\n", 
     243            m_manager.get1394Service().getPort(), channel); 
     244    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Buffer, MaxPacketSize, IRQ..: %4d, %4d, %4d\n", 
     245            m_buf_packets, m_max_packet_size, m_irq_interval); 
     246    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Packet count................: %10d (%5d dropped)\n", 
    288247            this->getPacketCount(), this->getDroppedCount()); 
    289248} 
     
    304263    } 
    305264    m_Client=stream; 
    306     m_Client->setHandler(this); 
    307265    return true; 
    308266} 
     
    317275            return false; 
    318276    } 
    319  
    320     m_Client->clearHandler(); 
    321  
    322277    m_Client=0; 
    323278    return true; 
    324  
    325279} 
    326280 
    327281/* Child class implementations */ 
    328282 
    329 IsoRecvHandler::IsoRecvHandler(int port
    330                 : IsoHandler(port
     283IsoRecvHandler::IsoRecvHandler(IsoHandlerManager& manager
     284                : IsoHandler(manager
    331285{ 
    332286    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    333287} 
    334 IsoRecvHandler::IsoRecvHandler(int port, unsigned int buf_packets, 
     288IsoRecvHandler::IsoRecvHandler(IsoHandlerManager& manager, unsigned int buf_packets, 
    335289                               unsigned int max_packet_size, int irq) 
    336                 : IsoHandler(port, buf_packets,max_packet_size,irq) 
     290                : IsoHandler(manager, buf_packets,max_packet_size,irq) 
    337291{ 
    338292    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     
    342296{ 
    343297 
     298} 
     299 
     300void IsoRecvHandler::flush() 
     301{ 
     302    raw1394_iso_recv_flush(m_handle); 
    344303} 
    345304 
     
    375334bool IsoRecvHandler::prepare() 
    376335{ 
    377  
     336    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p, client=%p)\n", this, m_Client); 
    378337    // prepare the generic IsoHandler 
    379338    if(!IsoHandler::prepare()) { 
    380339        return false; 
    381340    } 
    382  
    383341    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p)\n",this); 
    384342    debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers         : %d \n", m_buf_packets); 
     
    419377} 
    420378 
    421 bool IsoRecvHandler::start(int cycle) 
     379bool IsoRecvHandler::enable(int cycle) 
    422380{ 
    423381    debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); 
    424  
    425     // start the generic IsoHandler 
    426     if(!IsoHandler::start(cycle)) { 
    427         return false; 
    428     } 
    429  
     382    // check the state 
     383    if(m_State != E_Prepared) { 
     384        if(!prepare()) { 
     385            debugFatal("Could not prepare recv handler\n"); 
     386            return false; 
     387        } 
     388    } 
    430389    if(raw1394_iso_recv_start(m_handle, cycle, -1, 0)) { 
    431390        debugFatal("Could not start receive handler (%s)\n",strerror(errno)); 
     391        dumpInfo(); 
     392        return false; 
     393    } 
     394    // start the generic IsoHandler 
     395    if(!IsoHandler::enable(cycle)) { 
    432396        return false; 
    433397    } 
     
    449413/* ----------------- XMIT --------------- */ 
    450414 
    451 IsoXmitHandler::IsoXmitHandler(int port
    452                 : IsoHandler(port), m_prebuffers(0) 
     415IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager
     416                : IsoHandler(manager), m_prebuffers(0) 
    453417{ 
    454418    debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); 
    455419 
    456420} 
    457 IsoXmitHandler::IsoXmitHandler(int port, unsigned int buf_packets, 
     421IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, 
    458422                               unsigned int max_packet_size, int irq) 
    459                 : IsoHandler(port, buf_packets, max_packet_size,irq), 
     423                : IsoHandler(manager, buf_packets, max_packet_size,irq), 
    460424                  m_speed(RAW1394_ISO_SPEED_400), m_prebuffers(0) 
    461425{ 
     
    463427 
    464428} 
    465 IsoXmitHandler::IsoXmitHandler(int port, unsigned int buf_packets, 
     429IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, 
    466430                               unsigned int max_packet_size, int irq, 
    467431                               enum raw1394_iso_speed speed) 
    468                 : IsoHandler(port, buf_packets,max_packet_size,irq), 
     432                : IsoHandler(manager, buf_packets,max_packet_size,irq), 
    469433                  m_speed(speed), m_prebuffers(0) 
    470434{ 
     
    492456bool IsoXmitHandler::prepare() 
    493457{ 
    494     debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso transmit handler (%p, client=%p)\n",this,m_Client); 
    495  
     458    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso transmit handler (%p, client=%p)\n", this, m_Client); 
    496459    if(!(IsoHandler::prepare())) { 
    497460        return false; 
     
    503466    debugOutput( DEBUG_LEVEL_VERBOSE, " Speed           : %d \n",m_speed); 
    504467    debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval    : %d \n",m_irq_interval); 
    505  
    506468    if(raw1394_iso_xmit_init(m_handle, 
    507469                             iso_transmit_handler, 
     
    515477        return false; 
    516478    } 
    517  
    518     return true; 
    519 
    520  
    521 bool IsoXmitHandler::start(int cycle) 
     479    return true; 
     480
     481 
     482bool IsoXmitHandler::enable(int cycle) 
    522483{ 
    523484    debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d, %d prebuffers\n",  
    524485        cycle, m_prebuffers); 
    525  
    526     if(!(IsoHandler::start(cycle))) { 
    527         return false; 
    528     } 
    529  
     486    // check the state 
     487    if(m_State != E_Prepared) { 
     488        if(!prepare()) { 
     489            debugFatal("Could not prepare xmit handler\n"); 
     490            return false; 
     491        } 
     492    } 
    530493    if(raw1394_iso_xmit_start(m_handle, cycle, m_prebuffers)) { 
    531494        debugFatal("Could not start xmit handler (%s)\n",strerror(errno)); 
     495        dumpInfo(); 
     496        return false; 
     497    } 
     498    if(!(IsoHandler::enable(cycle))) { 
    532499        return false; 
    533500    } 
     
    549516        return m_Client->getPacket(data, length, tag, sy, cycle, dropped, m_max_packet_size); 
    550517    } 
    551  
    552518    return RAW1394_ISO_OK; 
    553519} 
     
    556522    debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); 
    557523    //TODO: implement busreset 
    558  
    559524    // pass on the busreset signal 
    560525    if(IsoHandler::handleBusReset(generation)) { 
    561526            return -1; 
    562527    } 
    563  
    564528    return 0; 
    565529} 
    566530 
    567 
    568  
    569 /* multichannel receive  */ 
    570 #if 0 
    571 IsoRecvHandler::IsoRecvHandler(int port) 
    572         : IsoHandler(port) 
    573 
    574     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    575 
    576 IsoRecvHandler::IsoRecvHandler(int port, unsigned int buf_packets, 
    577                                unsigned int max_packet_size, int irq) 
    578         : IsoHandler(port, buf_packets,max_packet_size,irq) 
    579 
    580     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    581  
    582 
    583 IsoRecvHandler::~IsoRecvHandler() 
    584 
    585 // Don't call until libraw1394's raw1394_new_handle() function has been 
    586 // fixed to correctly initialise the iso_packet_infos field.  Bug is 
    587 // confirmed present in libraw1394 1.2.1.  In any case, 
    588 // raw1394_destroy_handle() (in the base class destructor) will do any iso 
    589 // system shutdown required. 
    590     raw1394_iso_shutdown(m_handle); 
    591  
    592 
    593  
    594 bool 
    595 IsoRecvHandler::initialize() { 
    596     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    597  
    598     IsoHandler *base=static_cast<IsoHandler *>(this); 
    599  
    600     if(!(base->initialize())) { 
    601         return false; 
    602     } 
    603  
    604     raw1394_set_userdata(m_handle, static_cast<void *>(this)); 
    605  
    606     if(raw1394_iso_multichannel_recv_init(m_handle, 
    607                                          iso_receive_handler, 
    608                                          m_buf_packets, 
    609                                          m_max_packet_size, 
    610                                          m_irq_interval)) { 
    611         debugFatal("Could not do multichannel receive initialisation!\n" ); 
    612  
    613         return false; 
    614     } 
    615  
    616     return true; 
    617  
    618 
    619  
    620 enum raw1394_iso_disposition IsoRecvHandler::putPacket(unsigned char *data, unsigned int length, 
    621                       unsigned char channel, unsigned char tag, unsigned char sy, 
    622                       unsigned int cycle, unsigned int dropped) { 
    623  
    624     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, 
    625                  "received packet: length=%d, channel=%d, cycle=%d\n", 
    626                  length, channel, cycle ); 
    627  
    628     return RAW1394_ISO_OK; 
    629 
    630  
    631 // an recv handler can have multiple destination StreamProcessors 
    632 // NOTE: this implementation even allows for already registered 
    633 // streams to be registered again. 
    634 int IsoRecvHandler::registerStream(IsoRecvStream *stream) 
    635 
    636     assert(stream); 
    637     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    638  
    639     m_Clients.push_back(stream); 
    640  
    641     listen(stream->getChannel()); 
    642     return 0; 
    643  
    644 
    645  
    646 int IsoRecvHandler::unregisterStream(IsoRecvStream *stream) 
    647 
    648     assert(stream); 
    649     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    650  
    651     for ( IsoRecvStreamVectorIterator it = m_Clients.begin(); 
    652           it != m_Clients.end(); 
    653           ++it ) 
    654     { 
    655         IsoRecvStream* s = *it; 
    656         if ( s == stream ) { 
    657             unListen(s->getChannel()); 
    658             m_Clients.erase(it); 
    659             return 0; 
    660         } 
    661     } 
    662  
    663     return -1; //not found 
    664  
    665 
    666  
    667 void IsoRecvHandler::listen(int channel) { 
    668     int retval; 
    669     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    670  
    671     retval=raw1394_iso_recv_listen_channel(m_handle, channel); 
    672  
    673 
    674  
    675 void IsoRecvHandler::unListen(int channel) { 
    676     int retval; 
    677     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    678  
    679     retval=raw1394_iso_recv_unlisten_channel(m_handle, channel); 
    680  
    681 
    682  
    683 int IsoRecvHandler::start(int cycle) 
    684 
    685     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    686     return raw1394_iso_recv_start(m_handle, cycle, -1, 0); 
    687 
    688 #endif 
     531void IsoXmitHandler::dumpInfo() 
     532
     533    IsoHandler::dumpInfo(); 
     534    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Speed, PreBuffers...........: %2d, %2d\n", 
     535                                          m_speed, m_prebuffers); 
     536
  • trunk/libffado/src/libieee1394/IsoHandler.h

    r748 r750  
    2626 
    2727#include "debugmodule/debugmodule.h" 
    28  
    29 #include <libraw1394/raw1394.h> 
    30  
     28#include "IsoHandlerManager.h" 
    3129 
    3230enum raw1394_iso_disposition ; 
    33 namespace Streaming 
    34 
    35  
    36 class StreamProcessor; 
     31 
     32namespace Streaming { 
     33    class StreamProcessor; 
     34
     35 
    3736/*! 
    3837\brief The Base Class for ISO Handlers 
    3938 
    4039 These classes perform the actual ISO communication through libraw1394. 
    41  They are different from StreamProcessors because one handler can provide multiple 
     40 They are different from Streaming::StreamProcessors because one handler can provide multiple 
    4241 streams with packets in case of ISO multichannel receive. 
    4342 
     
    4645class IsoHandler 
    4746{ 
    48     protected: 
    49  
    50     public: 
    51  
    52         enum EHandlerType { 
    53                 EHT_Receive, 
    54                 EHT_Transmit 
    55         }; 
    56  
    57         IsoHandler(int port); 
    58  
    59         IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
    60  
    61         virtual ~IsoHandler(); 
    62  
    63         virtual bool init(); 
    64         virtual bool prepare(); 
    65         virtual bool start(int cycle); 
    66         virtual bool stop(); 
    67  
    68         bool iterate(); 
    69  
    70         void setVerboseLevel(int l); 
    71  
    72         // no setter functions, because those would require a re-init 
    73         unsigned int getMaxPacketSize() { return m_max_packet_size;}; 
    74         unsigned int getNbBuffers() { return m_buf_packets;}; 
    75         int getWakeupInterval() { return m_irq_interval;}; 
    76  
    77         int getPacketCount() {return m_packetcount;}; 
    78         void resetPacketCount() {m_packetcount=0;}; 
    79  
    80         int getDroppedCount() {return m_dropped;}; 
    81         void resetDroppedCount() {m_dropped=0;}; 
    82  
    83         virtual enum EHandlerType getType() = 0; 
    84  
    85         int getFileDescriptor() { return raw1394_get_fd(m_handle);}; 
    86  
    87         void dumpInfo(); 
    88  
    89         bool inUse() {return (m_Client != 0) ;}; 
    90         virtual bool isStreamRegistered(StreamProcessor *s) {return (m_Client == s);}; 
    91  
    92         virtual bool registerStream(StreamProcessor *); 
    93         virtual bool unregisterStream(StreamProcessor *); 
    94  
    95         int getLocalNodeId() {return raw1394_get_local_id( m_handle );}; 
    96         int getPort() {return m_port;}; 
    97  
    98     protected: 
     47public: 
     48    enum EHandlerType { 
     49            EHT_Receive, 
     50            EHT_Transmit 
     51    }; 
     52    IsoHandler(IsoHandlerManager& manager); 
     53    IsoHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
     54 
     55    virtual ~IsoHandler(); 
     56 
     57    virtual bool init(); 
     58    virtual bool prepare(); 
     59 
     60    bool iterate(); 
     61    void setVerboseLevel(int l); 
     62 
     63    virtual bool enable() {return enable(-1);}; 
     64    virtual bool enable(int cycle); 
     65    virtual bool disable(); 
     66 
     67    virtual void flush() = 0; 
     68 
     69    bool isEnabled() 
     70        {return m_State == E_Running;}; 
     71 
     72    // no setter functions, because those would require a re-init 
     73    unsigned int getMaxPacketSize() { return m_max_packet_size;}; 
     74    unsigned int getNbBuffers() { return m_buf_packets;}; 
     75    int getPacketLatency() { return m_irq_interval;}; 
     76 
     77    int getPacketCount() {return m_packetcount;}; 
     78    void resetPacketCount() {m_packetcount=0;}; 
     79 
     80    int getDroppedCount() {return m_dropped;}; 
     81    void resetDroppedCount() {m_dropped=0;}; 
     82 
     83    virtual enum EHandlerType getType() = 0; 
     84 
     85    int getFileDescriptor() { return raw1394_get_fd(m_handle);}; 
     86 
     87    virtual void dumpInfo(); 
     88 
     89    bool inUse() {return (m_Client != 0) ;}; 
     90    virtual bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);}; 
     91 
     92    virtual bool registerStream(Streaming::StreamProcessor *); 
     93    virtual bool unregisterStream(Streaming::StreamProcessor *); 
     94 
     95    protected: 
     96        IsoHandlerManager& m_manager; 
    9997        raw1394handle_t m_handle; 
    100         raw1394handle_t m_handle_util; 
    101         int             m_port; 
    10298        unsigned int    m_buf_packets; 
    10399        unsigned int    m_max_packet_size; 
     
    106102        int m_packetcount; 
    107103        int m_dropped; 
    108  
    109         StreamProcessor *m_Client; 
     104        Streaming::StreamProcessor *m_Client; 
    110105 
    111106        virtual int handleBusReset(unsigned int generation); 
    112  
    113  
    114107        DECLARE_DEBUG_MODULE; 
    115  
    116108    private: 
    117109        static int busreset_handler(raw1394handle_t handle, unsigned int generation); 
    118110 
    119111    // the state machine 
    120     private
     112    protected
    121113        enum EHandlerStates { 
    122114            E_Created, 
     
    126118            E_Error 
    127119        }; 
    128  
    129120        enum EHandlerStates m_State; 
    130  
    131121}; 
    132122 
     
    139129 
    140130    public: 
    141         IsoRecvHandler(int port); 
    142         IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
     131        IsoRecvHandler(IsoHandlerManager& manager); 
     132        IsoRecvHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq); 
    143133        virtual ~IsoRecvHandler(); 
    144134 
    145135        bool init(); 
    146  
    147136        enum EHandlerType getType() { return EHT_Receive;}; 
    148  
    149         bool start(int cycle); 
    150  
    151         bool prepare(); 
     137        bool enable(int cycle); 
     138        virtual bool prepare(); 
     139        virtual void flush(); 
    152140 
    153141    protected: 
    154142        int handleBusReset(unsigned int generation); 
    155  
    156143    private: 
    157144        static enum raw1394_iso_disposition 
     
    165152                          unsigned char channel, unsigned char tag, unsigned char sy, 
    166153                          unsigned int cycle, unsigned int dropped); 
    167  
    168154}; 
    169155 
     
    175161{ 
    176162    public: 
    177         IsoXmitHandler(int port); 
    178         IsoXmitHandler(int port, unsigned int buf_packets, 
     163        IsoXmitHandler(IsoHandlerManager& manager); 
     164        IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, 
    179165                        unsigned int max_packet_size, int irq); 
    180         IsoXmitHandler(int port, unsigned int buf_packets, 
     166        IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, 
    181167                        unsigned int max_packet_size, int irq, 
    182168                        enum raw1394_iso_speed speed); 
     
    184170 
    185171        bool init(); 
    186  
    187172        enum EHandlerType getType() { return EHT_Transmit;}; 
    188  
    189173        unsigned int getPreBuffers() {return m_prebuffers;}; 
    190174        void setPreBuffers(unsigned int n) {m_prebuffers=n;}; 
    191  
    192         bool start(int cycle); 
    193  
    194         bool prepare(); 
    195  
     175        virtual bool enable(int cycle); 
     176        virtual bool prepare(); 
     177        virtual void flush() {}; 
     178 
     179        void dumpInfo(); 
    196180    protected: 
    197181        int handleBusReset(unsigned int generation); 
     
    208192 
    209193        enum raw1394_iso_speed m_speed; 
    210  
    211194        unsigned int m_prebuffers; 
    212  
    213195}; 
    214196 
    215 } 
    216  
    217197#endif /* __FFADO_ISOHANDLER__  */ 
    218198 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.cpp

    r747 r750  
    2323 
    2424#include "IsoHandlerManager.h" 
     25#include "ieee1394service.h"  
    2526#include "IsoHandler.h" 
    26 #include "../generic/StreamProcessor.h" 
    27  
     27#include "libstreaming/generic/StreamProcessor.h" 
     28 
     29#include "libutil/Atomic.h" 
    2830#include "libutil/PosixThread.h" 
    2931 
     
    3335#define PACKETS_PER_INTERRUPT          4U 
    3436 
    35 namespace Streaming 
    36 
     37#define FFADO_ISOHANDLERMANAGER_PRIORITY_INCREASE 7 
    3738 
    3839IMPL_DEBUG_MODULE( IsoHandlerManager, IsoHandlerManager, DEBUG_LEVEL_NORMAL ); 
    3940 
    40 IsoHandlerManager::IsoHandlerManager() : 
    41    m_State(E_Created), 
    42    m_poll_timeout(100), m_poll_fds(0), m_poll_nfds(0), 
    43    m_realtime(false), m_priority(0), m_xmit_nb_frames( 20 ) 
     41using namespace Streaming; 
     42 
     43IsoHandlerManager::IsoHandlerManager(Ieee1394Service& service) 
     44   : m_State(E_Created) 
     45   , m_service( service ) 
     46   , m_poll_timeout(100), m_poll_nfds_shadow(0) 
     47   , m_realtime(false), m_priority(0), m_xmit_nb_frames( 20 ) 
    4448{} 
    4549 
    46 IsoHandlerManager::IsoHandlerManager(bool run_rt, unsigned int rt_prio) : 
    47    m_State(E_Created), 
    48    m_poll_timeout(100), m_poll_fds(0), m_poll_nfds(0), 
    49    m_realtime(run_rt), m_priority(rt_prio), m_xmit_nb_frames( 20 ) 
     50IsoHandlerManager::IsoHandlerManager(Ieee1394Service& service, bool run_rt, unsigned int rt_prio) 
     51   : m_State(E_Created) 
     52   , m_service( service ) 
     53   , m_poll_timeout(100), m_poll_nfds_shadow(0) 
     54   , m_realtime(run_rt), m_priority(rt_prio), m_xmit_nb_frames( 20 ) 
    5055{} 
    5156 
     57IsoHandlerManager::~IsoHandlerManager() 
     58{ 
     59    stopHandlers(); 
     60} 
     61 
     62bool 
     63IsoHandlerManager::setThreadParameters(bool rt, int priority) { 
     64    if (m_isoManagerThread) { 
     65        if (rt) { 
     66            unsigned int prio = priority + FFADO_ISOHANDLERMANAGER_PRIORITY_INCREASE; 
     67            if (prio > 98) prio = 98; 
     68            m_isoManagerThread->AcquireRealTime(prio); 
     69        } else { 
     70            m_isoManagerThread->DropRealTime(); 
     71        } 
     72    } 
     73    m_realtime = rt; 
     74    m_priority = priority; 
     75    return true; 
     76} 
     77 
    5278bool IsoHandlerManager::init() 
    5379{ 
     80    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing ISO manager %p...\n", this); 
     81    // check state 
     82    if(m_State != E_Created) { 
     83        debugError("Manager already initialized...\n"); 
     84        return false; 
     85    } 
     86 
    5487    // the tread that performs the actual packet transfer 
    5588    // needs high priority 
    56     unsigned int prio=m_priority+6
    57  
    58     if (prio>98) prio=98; 
    59  
    60     m_isoManagerThread=new Util::PosixThread( 
     89    unsigned int prio = m_priority + FFADO_ISOHANDLERMANAGER_PRIORITY_INCREASE
     90    debugOutput( DEBUG_LEVEL_VERBOSE, " thread should have prio %d, base is %d...\n", prio, m_priority); 
     91 
     92    if (prio > 98) prio = 98; 
     93    m_isoManagerThread = new Util::PosixThread( 
    6194        this, 
    6295        m_realtime, prio, 
     
    67100        return false; 
    68101    } 
    69  
    70102    // propagate the debug level 
    71103    m_isoManagerThread->setVerboseLevel(getDebugLevel()); 
    72104 
     105    debugOutput( DEBUG_LEVEL_VERBOSE, "Starting ISO iterator thread...\n"); 
     106    // note: libraw1394 doesn't like it if you poll() and/or iterate() before 
     107    //       starting the streams. this is prevented by the isEnabled() on a handler 
     108    // start the iso runner thread 
     109    if (m_isoManagerThread->Start() == 0) { 
     110        m_State=E_Running; 
     111        requestShadowUpdate(); 
     112    } else { 
     113        m_State=E_Error; 
     114    } 
    73115    return true; 
    74116} 
     
    77119{ 
    78120    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    79     pthread_mutex_init(&m_debug_lock, NULL); 
    80  
    81121    return true; 
    82122} 
     
    97137bool IsoHandlerManager::Execute() 
    98138{ 
    99 //     updateCycleTimers(); 
    100  
    101     pthread_mutex_lock(&m_debug_lock); 
    102  
    103139    if(!iterate()) { 
    104140        debugFatal("Could not iterate the isoManager\n"); 
    105         pthread_mutex_unlock(&m_debug_lock); 
    106141        return false; 
    107142    } 
    108  
    109     pthread_mutex_unlock(&m_debug_lock); 
    110  
    111143    return true; 
     144} 
     145 
     146/** 
     147 * Update the shadow variables. Should only be called from 
     148 * the iso handler iteration thread 
     149 */ 
     150void 
     151IsoHandlerManager::updateShadowVars() 
     152{ 
     153    debugOutput( DEBUG_LEVEL_VERBOSE, "updating shadow vars...\n"); 
     154    unsigned int i; 
     155    m_poll_nfds_shadow = m_IsoHandlers.size(); 
     156    if(m_poll_nfds_shadow > FFADO_MAX_ISO_HANDLERS_PER_PORT) { 
     157        debugWarning("Too much ISO Handlers in manager...\n"); 
     158        m_poll_nfds_shadow = FFADO_MAX_ISO_HANDLERS_PER_PORT; 
     159    } 
     160    for (i = 0; i < m_poll_nfds_shadow; i++) { 
     161        IsoHandler *h = m_IsoHandlers.at(i); 
     162        assert(h); 
     163        m_IsoHandler_map_shadow[i] = h; 
     164 
     165        m_poll_fds_shadow[i].fd = h->getFileDescriptor(); 
     166        m_poll_fds_shadow[i].revents = 0; 
     167        if (h->isEnabled()) { 
     168            m_poll_fds_shadow[i].events = POLLIN; 
     169        } else { 
     170            m_poll_fds_shadow[i].events = 0; 
     171        } 
     172    } 
     173    debugOutput( DEBUG_LEVEL_VERBOSE, " updated shadow vars...\n"); 
    112174} 
    113175 
     
    121183{ 
    122184    int err; 
    123     int i=0; 
    124     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "poll %d fd's, timeout = %dms...\n", m_poll_nfds, m_poll_timeout); 
    125  
    126     err = poll (m_poll_fds, m_poll_nfds, m_poll_timeout); 
     185    int i; 
     186 
     187    // update the shadow variables if requested 
     188    if(m_request_fdmap_update) { 
     189        updateShadowVars(); 
     190        ZERO_ATOMIC((SInt32*)&m_request_fdmap_update); 
     191    } 
     192 
     193    // bypass if no handlers are registered 
     194    if (m_poll_nfds_shadow == 0) { 
     195        usleep(m_poll_timeout * 1000); 
     196        return true; 
     197    } 
     198 
     199    // Use a shadow map of the fd's such that the poll call is not in a critical section 
     200 
     201    err = poll (m_poll_fds_shadow, m_poll_nfds_shadow, m_poll_timeout); 
    127202 
    128203    if (err == -1) { 
     
    135210 
    136211//     #ifdef DEBUG 
    137 //     for (i = 0; i < m_poll_nfds; i++) { 
    138 //         IsoHandler *s = m_IsoHandlers.at(i)
     212//     for (i = 0; i < m_poll_nfds_shadow; i++) { 
     213//         IsoHandler *s = m_IsoHandler_map_shadow[i]
    139214//         assert(s); 
    140 //         debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%d) handler %p: iterate? %d, revents: %08X\n",  
    141 //             i, s, (m_poll_fds[i].revents & (POLLIN) == 1), m_poll_fds[i].revents); 
     215//         debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "post poll: (%d) handler %p: enabled? %d, events: %08X, revents: %08X\n",  
     216//             i, s, s->isEnabled(), m_poll_fds_shadow[i].events, m_poll_fds_shadow[i].revents); 
    142217//     } 
    143218//     #endif 
    144219 
    145     for (i = 0; i < m_poll_nfds; i++) { 
    146         if (m_poll_fds[i].revents & POLLERR) { 
     220    for (i = 0; i < m_poll_nfds_shadow; i++) { 
     221        if (m_poll_fds_shadow[i].revents & POLLERR) { 
    147222            debugWarning("error on fd for %d\n",i); 
    148223        } 
    149224 
    150         if (m_poll_fds[i].revents & POLLHUP) { 
     225        if (m_poll_fds_shadow[i].revents & POLLHUP) { 
    151226            debugWarning("hangup on fd for %d\n",i); 
    152227        } 
    153228 
    154         if(m_poll_fds[i].revents & (POLLIN)) { 
    155             IsoHandler *s = m_IsoHandlers.at(i); 
    156             assert(s); 
    157             s->iterate(); 
    158         } 
    159     } 
    160  
     229        if(m_poll_fds_shadow[i].revents & (POLLIN)) { 
     230            m_IsoHandler_map_shadow[i]->iterate(); 
     231        } 
     232    } 
    161233    return true; 
    162  
    163234} 
    164235 
     
    167238    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    168239    assert(handler); 
     240    handler->setVerboseLevel(getDebugLevel()); 
    169241 
    170242    m_IsoHandlers.push_back(handler); 
    171  
    172     handler->setVerboseLevel(getDebugLevel()); 
     243    requestShadowUpdate(); 
    173244 
    174245    // rebuild the fd map for poll()'ing. 
    175     return rebuildFdMap(); 
    176  
     246    return true; 
    177247} 
    178248 
     
    187257    { 
    188258        if ( *it == handler ) { 
    189             // erase the iso handler from the list 
    190259            m_IsoHandlers.erase(it); 
    191             // rebuild the fd map for poll()'ing. 
    192             return rebuildFdMap()
     260            requestShadowUpdate(); 
     261            return true
    193262        } 
    194263    } 
    195264    debugFatal("Could not find handler (%p)\n", handler); 
    196  
    197265    return false; //not found 
    198  
    199 
    200  
    201 bool IsoHandlerManager::rebuildFdMap() { 
     266
     267 
     268void 
     269IsoHandlerManager::requestShadowUpdate() { 
    202270    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     271    int i; 
     272 
     273    if (m_isoManagerThread == NULL) { 
     274        debugOutput( DEBUG_LEVEL_VERBOSE, "No thread running, so no shadow variables needed.\n"); 
     275        return; 
     276    } 
     277 
     278    // the m_request_fdmap_update variable is zeroed by the 
     279    // handler thread when it has accepted the new FD map 
     280    // and copied it over to it's shadow variables. 
     281    while(m_request_fdmap_update && m_isoManagerThread) { 
     282        usleep(1000); 
     283    } 
     284 
     285    debugOutput(DEBUG_LEVEL_VERBOSE, " requesting update of shadow variables...\n"); 
     286    // request that the handler thread updates it's FD shadow 
     287    INC_ATOMIC((SInt32*)&m_request_fdmap_update); 
     288 
     289    debugOutput(DEBUG_LEVEL_VERBOSE, " waiting for update of shadow variables to complete...\n"); 
     290    // the m_request_fdmap_update variable is zeroed by the 
     291    // handler thread when it has accepted the new FD map 
     292    // and copied it over to it's shadow variables. 
     293    while(m_request_fdmap_update && m_isoManagerThread) { 
     294        usleep(1000); 
     295    } 
     296    debugOutput(DEBUG_LEVEL_VERBOSE, " shadow variables updated...\n"); 
     297} 
     298 
     299bool 
     300IsoHandlerManager::disable(IsoHandler *h) { 
     301    bool result; 
    203302    int i=0; 
    204  
    205     m_poll_nfds=0; 
    206     if(m_poll_fds) free(m_poll_fds); 
    207  
    208     // count the number of handlers 
    209     m_poll_nfds=m_IsoHandlers.size(); 
    210  
    211     // allocate the fd array 
    212     m_poll_fds   = (struct pollfd *) calloc (m_poll_nfds, sizeof (struct pollfd)); 
    213     if(!m_poll_fds) { 
    214         debugFatal("Could not allocate memory for poll FD array\n"); 
    215         return false; 
    216     } 
    217  
    218     // fill the fd map 
    219     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    220       it != m_IsoHandlers.end(); 
    221       ++it ) 
    222     { 
    223         m_poll_fds[i].fd=(*it)->getFileDescriptor(); 
    224         m_poll_fds[i].events = POLLIN; 
    225         i++; 
    226     } 
    227  
    228     return true; 
    229 
    230  
    231 void IsoHandlerManager::disablePolling(StreamProcessor *stream) { 
    232     int i=0; 
    233  
    234     debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Disable polling on stream %p\n",stream); 
    235  
     303    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Disable on IsoHandler %p\n", h); 
    236304    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    237305        it != m_IsoHandlers.end(); 
    238306        ++it ) 
    239307    { 
    240         if ((*it)->isStreamRegistered(stream)) { 
    241             m_poll_fds[i].events = 0
    242             m_poll_fds[i].revents = 0
    243             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "polling disabled\n"); 
    244         } 
    245  
     308        if ((*it) == h) { 
     309            result = h->disable()
     310            requestShadowUpdate()
     311            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " disabled\n"); 
     312            return result; 
     313        } 
    246314        i++; 
    247315    } 
    248 
    249  
    250 void IsoHandlerManager::enablePolling(StreamProcessor *stream) { 
     316    debugError("Handler not found\n"); 
     317    return false; 
     318
     319 
     320bool 
     321IsoHandlerManager::enable(IsoHandler *h) { 
     322    bool result; 
    251323    int i=0; 
    252  
    253     debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Enable polling on stream %p\n",stream); 
    254  
     324    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Enable on IsoHandler %p\n", h); 
    255325    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    256326        it != m_IsoHandlers.end(); 
    257327        ++it ) 
    258328    { 
    259         if ((*it)->isStreamRegistered(stream)) { 
    260             m_poll_fds[i].events = POLLIN
    261             m_poll_fds[i].revents = 0
    262             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "polling enabled\n"); 
    263         } 
    264  
     329        if ((*it) == h) { 
     330            result = h->enable()
     331            requestShadowUpdate()
     332            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " enabled\n"); 
     333            return result; 
     334        } 
    265335        i++; 
    266336    } 
    267 
    268  
     337    debugError("Handler not found\n"); 
     338    return false; 
     339
    269340 
    270341/** 
     
    293364    { 
    294365        if((*it)->isStreamRegistered(stream)) { 
    295             debugWarning( "stream already registered!\n"); 
    296             (*it)->unregisterStream(stream); 
    297  
     366            debugError( "stream already registered!\n"); 
     367            return false; 
    298368        } 
    299369    } 
     
    367437           but it has a minimal value in order for libraw to operate correctly (300) */ 
    368438        int buffers=400; 
    369  
     439        //max_packet_size = getpagesize(); // HACK 
     440        //irq_interval=2; // HACK 
    370441        // create the actual handler 
    371         IsoRecvHandler *h = new IsoRecvHandler(stream->getPort(), buffers, 
     442        IsoRecvHandler *h = new IsoRecvHandler(*this, buffers, 
    372443                                               max_packet_size, irq_interval); 
    373444 
     
    405476        unsigned int packets_per_period = stream->getPacketsPerPeriod(); 
    406477 
    407 #if 1 
    408478        // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    409479        // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq 
     
    422492 
    423493         unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
    424          if(irq_interval <= 0) irq_interval=1; 
    425 #else 
    426         // hardware interrupts occur when one DMA block is full, and the size of one DMA 
    427         // block = PAGE_SIZE. Setting the max_packet_size enables control over the IRQ 
    428         // frequency, as the controller uses max_packet_size, and not the effective size 
    429         // when writing to the DMA buffer. 
    430  
    431         // configure it such that we have an irq for every PACKETS_PER_INTERRUPT packets 
    432         unsigned int irq_interval = PACKETS_PER_INTERRUPT; 
    433  
    434         // unless the period size doesn't allow this 
    435         if ((packets_per_period/MINIMUM_INTERRUPTS_PER_PERIOD) < irq_interval) { 
    436             irq_interval = 1; 
    437         } 
    438  
    439         // FIXME: test 
    440         irq_interval = 1; 
    441 #warning Using fixed irq_interval 
    442  
    443         unsigned int max_packet_size = getpagesize() / irq_interval; 
    444  
    445         if (max_packet_size < stream->getMaxPacketSize()) { 
    446             max_packet_size = stream->getMaxPacketSize(); 
    447         } 
    448  
    449         // Ensure we don't request a packet size bigger than the 
    450         // kernel-enforced maximum which is currently 1 page. 
    451         if (max_packet_size > (unsigned int)getpagesize()) 
    452                     max_packet_size = getpagesize(); 
    453 #endif 
     494         if(irq_interval <= 0) irq_interval = 1; 
     495 
    454496        // the transmit buffer size should be as low as possible for latency. 
    455497        // note however that the raw1394 subsystem tries to keep this buffer 
     
    461503        // buffers get transfered, meaning that we should have at least some 
    462504        // margin here 
    463 //         int buffers=irq_interval * 2; 
    464  
    465         // the SPM specifies how many packets to buffer 
    466         int buffers = stream->getNominalPacketsNeeded(m_xmit_nb_frames); 
     505        //irq_interval=2; 
     506        //int buffers=30; 
     507        //max_packet_size = getpagesize(); // HACK 
     508 
     509        // the SP specifies how many packets to buffer 
     510        int buffers = stream->getNbPacketsIsoXmitBuffer(); 
    467511 
    468512        // create the actual handler 
    469         IsoXmitHandler *h = new IsoXmitHandler(stream->getPort(), buffers, 
     513        IsoXmitHandler *h = new IsoXmitHandler(*this, buffers, 
    470514                                               max_packet_size, irq_interval); 
    471515 
     
    498542        debugOutput( DEBUG_LEVEL_VERBOSE, " registered stream (%p) with handler (%p)\n",stream,h); 
    499543    } 
    500  
    501544    m_StreamProcessors.push_back(stream); 
    502545    debugOutput( DEBUG_LEVEL_VERBOSE, " %d streams, %d handlers registered\n", 
    503546                                      m_StreamProcessors.size(), m_IsoHandlers.size()); 
    504  
    505547    return true; 
    506548} 
     
    521563                return false; 
    522564            } 
    523  
    524565            debugOutput( DEBUG_LEVEL_VERBOSE, " unregistered stream (%p) from handler (%p)...\n",stream,*it); 
    525566        } 
     
    536577        if ( *it == stream ) { 
    537578            m_StreamProcessors.erase(it); 
    538  
    539579            debugOutput( DEBUG_LEVEL_VERBOSE, " deleted stream (%p) from list...\n", *it); 
    540580            return true; 
    541581        } 
    542582    } 
    543  
    544583    return false; //not found 
    545  
    546 
    547  
     584
     585 
     586/** 
     587 * @brief unregister a handler from the manager 
     588 * @note called without the lock held. 
     589 */ 
    548590void IsoHandlerManager::pruneHandlers() { 
    549591    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     
    566608    { 
    567609        unregisterHandler(*it); 
     610 
    568611        debugOutput( DEBUG_LEVEL_VERBOSE, " deleting handler (%p)\n",*it); 
    569612 
     
    578621        delete *it; 
    579622    } 
    580  
    581 
    582  
    583  
    584 bool IsoHandlerManager::prepare() 
    585 
     623
     624 
     625bool 
     626IsoHandlerManager::stopHandlerForStream(Streaming::StreamProcessor *stream) { 
     627    // check state 
     628    if(m_State != E_Running) { 
     629        debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State)); 
     630        return false; 
     631    } 
     632    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     633      it != m_IsoHandlers.end(); 
     634      ++it ) 
     635    { 
     636        if((*it)->isStreamRegistered(stream)) { 
     637            bool result; 
     638            debugOutput( DEBUG_LEVEL_VERBOSE, " stopping handler %p for stream %p\n", *it, stream); 
     639            result = (*it)->disable(); 
     640            //requestShadowUpdate(); 
     641            if(!result) { 
     642                debugOutput( DEBUG_LEVEL_VERBOSE, " could not disable handler (%p)\n",*it); 
     643                return false; 
     644            } 
     645            return true; 
     646        } 
     647    } 
     648    debugError("Stream %p has no attached handler\n", stream); 
     649    return false; 
     650
     651 
     652int 
     653IsoHandlerManager::getPacketLatencyForStream(Streaming::StreamProcessor *stream) { 
     654    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     655      it != m_IsoHandlers.end(); 
     656      ++it ) 
     657    { 
     658        if((*it)->isStreamRegistered(stream)) { 
     659            return (*it)->getPacketLatency(); 
     660        } 
     661    } 
     662    debugError("Stream %p has no attached handler\n", stream); 
     663    return 0; 
     664
     665 
     666void 
     667IsoHandlerManager::flushHandlerForStream(Streaming::StreamProcessor *stream) { 
     668    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     669      it != m_IsoHandlers.end(); 
     670      ++it ) 
     671    { 
     672        if((*it)->isStreamRegistered(stream)) { 
     673            return (*it)->flush(); 
     674        } 
     675    } 
     676    debugError("Stream %p has no attached handler\n", stream); 
     677    return; 
     678
     679 
     680bool 
     681IsoHandlerManager::startHandlerForStream(Streaming::StreamProcessor *stream) { 
     682    return startHandlerForStream(stream, -1); 
     683
     684 
     685bool 
     686IsoHandlerManager::startHandlerForStream(Streaming::StreamProcessor *stream, int cycle) { 
     687    // check state 
     688    if(m_State != E_Running) { 
     689        debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State)); 
     690        return false; 
     691    } 
     692    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     693      it != m_IsoHandlers.end(); 
     694      ++it ) 
     695    { 
     696        if((*it)->isStreamRegistered(stream)) { 
     697            bool result; 
     698            debugOutput( DEBUG_LEVEL_VERBOSE, " starting handler %p for stream %p\n", *it, stream); 
     699            result = (*it)->enable(cycle); 
     700            requestShadowUpdate(); 
     701            if(!result) { 
     702                debugOutput( DEBUG_LEVEL_VERBOSE, " could not enable handler (%p)\n",*it); 
     703                return false; 
     704            } 
     705            return true; 
     706        } 
     707    } 
     708    debugError("Stream %p has no attached handler\n", stream); 
     709    return false; 
     710
     711 
     712bool IsoHandlerManager::stopHandlers() { 
     713    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
     714 
     715    // check state 
     716    if(m_State != E_Running) { 
     717        debugError("Incorrect state, expected E_Running, got %s\n", eHSToString(m_State)); 
     718        return false; 
     719    } 
     720 
    586721    bool retval=true; 
    587  
    588     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    589  
    590     // check state 
    591     if(m_State != E_Created) { 
    592         debugError("Incorrect state, expected E_Created, got %d\n",(int)m_State); 
    593         return false; 
    594     } 
    595  
    596     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    597           it != m_IsoHandlers.end(); 
    598           ++it ) 
    599     { 
    600         if(!(*it)->prepare()) { 
    601             debugFatal("Could not prepare handlers\n"); 
     722    debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping ISO iterator thread...\n"); 
     723 
     724    m_isoManagerThread->Stop(); 
     725    m_isoManagerThread = NULL; 
     726    ZERO_ATOMIC((SInt32*)&m_request_fdmap_update); 
     727 
     728    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
     729        it != m_IsoHandlers.end(); 
     730        ++it ) 
     731    { 
     732        debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handler (%p)\n",*it); 
     733        if(!(*it)->disable()){ 
     734            debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it); 
    602735            retval=false; 
    603736        } 
    604737    } 
     738    requestShadowUpdate(); 
    605739 
    606740    if (retval) { 
     
    609743        m_State=E_Error; 
    610744    } 
    611  
    612     return retval; 
    613 } 
    614  
    615 bool IsoHandlerManager::startHandlers() { 
    616     return startHandlers(-1); 
    617 } 
    618  
    619 bool IsoHandlerManager::startHandlers(int cycle) { 
    620     bool retval=true; 
    621  
    622     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    623  
    624     // check state 
    625     if(m_State != E_Prepared) { 
    626         debugError("Incorrect state, expected E_Prepared, got %d\n",(int)m_State); 
    627         return false; 
    628     } 
    629  
    630     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    631         it != m_IsoHandlers.end(); 
    632         ++it ) 
    633     { 
    634         debugOutput( DEBUG_LEVEL_VERBOSE, " starting handler (%p)\n",*it); 
    635         if(!(*it)->start(cycle)) { 
    636             debugOutput( DEBUG_LEVEL_VERBOSE, " could not start handler (%p)\n",*it); 
    637             retval=false; 
    638         } 
    639     } 
    640  
    641     debugOutput( DEBUG_LEVEL_VERBOSE, "Starting ISO iterator thread...\n"); 
    642  
    643     // note: libraw1394 doesn't like it if you poll() and/or iterate() before 
    644     //       starting the streams. 
    645     // start the iso runner thread 
    646     m_isoManagerThread->Start(); 
    647  
    648     if (retval) { 
    649         m_State=E_Running; 
    650     } else { 
    651         m_State=E_Error; 
    652     } 
    653  
    654     return retval; 
    655 } 
    656  
    657 bool IsoHandlerManager::stopHandlers() { 
    658     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    659  
    660     // check state 
    661     if(m_State != E_Running) { 
    662         debugError("Incorrect state, expected E_Running, got %d\n",(int)m_State); 
    663         return false; 
    664     } 
    665  
    666     bool retval=true; 
    667  
    668     debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping ISO iterator thread...\n"); 
    669     m_isoManagerThread->Stop(); 
    670  
    671     for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    672         it != m_IsoHandlers.end(); 
    673         ++it ) 
    674     { 
    675         debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handler (%p)\n",*it); 
    676         if(!(*it)->stop()){ 
    677             debugOutput( DEBUG_LEVEL_VERBOSE, " could not stop handler (%p)\n",*it); 
    678             retval=false; 
    679         } 
    680     } 
    681  
    682     if (retval) { 
    683         m_State=E_Prepared; 
    684     } else { 
    685         m_State=E_Error; 
    686     } 
    687  
    688745    return retval; 
    689746} 
     
    691748bool IsoHandlerManager::reset() { 
    692749    debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    693  
    694750    // check state 
    695751    if(m_State == E_Error) { 
     
    697753        return false; 
    698754    } 
    699  
    700755    // if not in an error condition, reset means stop the handlers 
    701756    return stopHandlers(); 
     
    705760void IsoHandlerManager::setVerboseLevel(int i) { 
    706761    setDebugLevel(i); 
    707  
    708762    // propagate the debug level 
    709763    if(m_isoManagerThread) { 
    710764        m_isoManagerThread->setVerboseLevel(getDebugLevel()); 
    711765    } 
    712  
    713766    for ( IsoHandlerVectorIterator it = m_IsoHandlers.begin(); 
    714767          it != m_IsoHandlers.end(); 
     
    721774void IsoHandlerManager::dumpInfo() { 
    722775    int i=0; 
    723  
    724776    debugOutputShort( DEBUG_LEVEL_NORMAL, "Dumping IsoHandlerManager Stream handler information...\n"); 
    725777    debugOutputShort( DEBUG_LEVEL_NORMAL, " State: %d\n",(int)m_State); 
     
    730782    { 
    731783        debugOutputShort( DEBUG_LEVEL_NORMAL, " IsoHandler %d (%p)\n",i++,*it); 
    732  
    733784        (*it)->dumpInfo(); 
    734785    } 
    735  
    736 
    737  
    738 } // end of namespace Streaming 
    739  
     786
     787 
     788const char * 
     789IsoHandlerManager::eHSToString(enum eHandlerStates s) { 
     790    switch (s) { 
     791        default: return "Invalid"; 
     792        case E_Created: return "Created"; 
     793        case E_Prepared: return "Prepared"; 
     794        case E_Running: return "Running"; 
     795        case E_Error: return "Error"; 
     796    } 
     797
  • trunk/libffado/src/libieee1394/IsoHandlerManager.h

    r747 r750  
    3434#include <vector> 
    3535 
     36#define FFADO_MAX_ISO_HANDLERS_PER_PORT 16 
     37 
    3638#define USLEEP_AFTER_UPDATE_FAILURE 10 
    3739#define USLEEP_AFTER_UPDATE 100 
    3840#define MAX_UPDATE_TRIES 10 
     41class Ieee1394Service; 
    3942namespace Util { 
    4043    class PosixThread; 
    4144} 
    4245 
    43 namespace Streaming 
    44 { 
    4546class IsoHandler; 
    46 class StreamProcessor; 
     47namespace Streaming { 
     48    class StreamProcessor; 
     49    class StreamProcessorManager; 
     50    typedef std::vector<StreamProcessor *> StreamProcessorVector; 
     51    typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; 
     52
    4753 
    4854typedef std::vector<IsoHandler *> IsoHandlerVector; 
    4955typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator; 
    50  
    51 typedef std::vector<StreamProcessor *> StreamProcessorVector; 
    52 typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator; 
    53  
    5456 
    5557/*! 
     
    5759 
    5860 This class manages the use of ISO handlers by ISO streams. 
    59  You can register an StreamProcessor with an IsoHandlerManager. This 
     61 You can register an Streaming::StreamProcessor with an IsoHandlerManager. This 
    6062 manager will assign an IsoHandler to the stream. If nescessary 
    6163 the manager allocates a new handler. If there is already a handler 
    62  that can handle the StreamProcessor (e.g. in case of multichannel receive), 
     64 that can handle the Streaming::StreamProcessor (e.g. in case of multichannel receive), 
    6365 it can be assigned. 
    6466 
    6567*/ 
    66  
    6768class IsoHandlerManager : public Util::RunnableInterface 
    6869{ 
    69     friend class StreamProcessorManager; 
     70    friend class Streaming::StreamProcessorManager; 
    7071 
    7172    public: 
    7273 
    73         IsoHandlerManager(); 
    74         IsoHandlerManager(bool run_rt, unsigned int rt_prio); 
    75         virtual ~IsoHandlerManager() {}; 
     74        IsoHandlerManager(Ieee1394Service& service); 
     75        IsoHandlerManager(Ieee1394Service& service, bool run_rt, unsigned int rt_prio); 
     76        virtual ~IsoHandlerManager(); 
     77 
     78        bool setThreadParameters(bool rt, int priority); 
    7679 
    7780        void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll() 
     
    8588        void dumpInfo(); ///< print some information about the manager to stdout/stderr 
    8689 
    87         bool registerStream(StreamProcessor *); ///< register an iso stream with the manager 
    88         bool unregisterStream(StreamProcessor *); ///< unregister an iso stream from the manager 
     90        bool registerStream(Streaming::StreamProcessor *); ///< register an iso stream with the manager 
     91        bool unregisterStream(Streaming::StreamProcessor *); ///< unregister an iso stream from the manager 
    8992 
    9093        bool startHandlers(); ///< start the managed ISO handlers 
     
    9396 
    9497        bool reset(); ///< reset the ISO manager and all streams 
    95  
    96         bool prepare(); ///< prepare the ISO manager and all streams 
    97  
    9898        bool init(); 
    9999 
    100         void disablePolling(StreamProcessor *); ///< disables polling on a stream 
    101         void enablePolling(StreamProcessor *); ///< enables polling on a stream 
     100        bool disable(IsoHandler *); ///< disables a handler 
     101        bool enable(IsoHandler *); ///< enables a handler 
     102        ///> disables the handler attached to the stream 
     103        bool stopHandlerForStream(Streaming::StreamProcessor *); 
     104        ///> starts the handler attached to the specific stream 
     105        bool startHandlerForStream(Streaming::StreamProcessor *); 
     106        ///> starts the handler attached to the specific stream on a specific cycle 
     107        bool startHandlerForStream(Streaming::StreamProcessor *, int cycle);  
    102108 
     109        /** 
     110         * returns the latency of a wake-up for this stream. 
     111         * The latency is the time it takes for a packet is delivered to the 
     112         * stream after it has been received (was on the wire). 
     113         * expressed in cycles 
     114         */ 
     115        int getPacketLatencyForStream(Streaming::StreamProcessor *); 
     116 
     117        void flushHandlerForStream(Streaming::StreamProcessor *stream); 
     118 
     119        Ieee1394Service& get1394Service() {return m_service;}; 
    103120    // RunnableInterface interface 
    104121    public: 
    105122        bool Execute(); // note that this is called in we while(running) loop 
    106123        bool Init(); 
    107         pthread_mutex_t m_debug_lock; 
     124         
     125        // protects the operations on the lists  
     126        // (FIXME: should be changed into a lock-free approach) 
     127        pthread_mutex_t m_list_lock; 
    108128 
    109129    // the state machine 
    110130    private: 
    111         enum EHandlerStates { 
     131        enum eHandlerStates { 
    112132            E_Created, 
    113133            E_Prepared, 
     
    116136        }; 
    117137 
    118         enum EHandlerStates m_State; 
    119  
     138        enum eHandlerStates m_State; 
     139        const char *eHSToString(enum eHandlerStates); 
    120140    private: 
    121141        /// iterate all child handlers 
     
    123143 
    124144    private: 
     145        Ieee1394Service&  m_service; 
    125146        // note: there is a disctinction between streams and handlers 
    126147        // because one handler can serve multiple streams (in case of 
     
    139160 
    140161        // the collection of streams 
    141         StreamProcessorVector m_StreamProcessors; 
     162        Streaming::StreamProcessorVector m_StreamProcessors; 
    142163 
    143164        // poll stuff 
    144165        int m_poll_timeout; 
    145         struct pollfd *m_poll_fds; 
    146         int m_poll_nfds; 
     166        // FD map sync requested 
     167        int32_t m_request_fdmap_update; 
     168        void updateShadowVars(); 
    147169 
    148         bool rebuildFdMap(); 
     170        // shadow variables 
     171        struct pollfd m_poll_fds_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
     172        IsoHandler *m_IsoHandler_map_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT]; 
     173        unsigned int m_poll_nfds_shadow; 
     174 
     175        void requestShadowUpdate(); 
    149176 
    150177        // threading 
     
    161188}; 
    162189 
    163 } 
    164  
    165190#endif /* __FFADO_ISOHANDLERMANAGER__  */ 
    166191 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp

    r748 r750  
    2525#include "AmdtpPort.h" 
    2626#include "../StreamProcessorManager.h" 
    27  
     27#include "devicemanager.h" 
     28 
     29#include "libieee1394/ieee1394service.h" 
     30#include "libieee1394/IsoHandlerManager.h" 
    2831#include "libieee1394/cycletimer.h" 
    2932 
     
    4043{} 
    4144 
    42 bool AmdtpReceiveStreamProcessor::prepareChild() { 
    43     debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this); 
    44  
    45     switch (m_manager->getNominalRate()) { 
     45unsigned int 
     46AmdtpReceiveStreamProcessor::getSytInterval() { 
     47    switch (m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()) { 
    4648        case 32000: 
    4749        case 44100: 
    4850        case 48000: 
    49             m_syt_interval = 8; 
    50             break; 
     51            return 8; 
    5152        case 88200: 
    5253        case 96000: 
    53             m_syt_interval = 16; 
    54             break; 
     54            return 16; 
    5555        case 176400: 
    5656        case 192000: 
    57             m_syt_interval = 32; 
    58             break; 
     57            return 32; 
    5958        default: 
    60             debugError("Unsupported rate: %d\n", m_manager->getNominalRate()); 
    61             return false; 
    62     } 
     59            debugError("Unsupported rate: %d\n", m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
     60            return 0; 
     61    } 
     62
     63 
     64bool AmdtpReceiveStreamProcessor::prepareChild() { 
     65    debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this); 
     66    m_syt_interval = getSytInterval(); 
    6367    return true; 
    6468} 
     
    8993                  (length >= 2*sizeof(quadlet_t)); 
    9094    if(ok) { 
    91         uint64_t now = m_parent.get1394Service().getCycleTimer(); 
     95        uint64_t now = m_Parent.get1394Service().getCycleTimer(); 
    9296        //=> convert the SYT to a full timestamp in ticks 
    9397        m_last_timestamp = sytRecvToFullTicks((uint32_t)ntohs(packet->syt), 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.h

    r748 r750  
    9191                    {return 4;}; 
    9292    virtual unsigned int getMaxPacketSize()  
    93                     {return 4 * (2 + m_syt_interval * m_dimension);}; 
     93                    {return 4 * (2 + getSytInterval() * m_dimension);}; 
    9494    virtual unsigned int getEventsPerFrame()  
    9595                    { return m_dimension; }; 
    9696    virtual unsigned int getNominalFramesPerPacket()  
    97                     {return m_syt_interval;}; 
     97                    {return getSytInterval();}; 
    9898 
    9999protected: 
     
    103103    bool decodePacketPorts(quadlet_t *data, unsigned int nevents, unsigned int dbc); 
    104104    int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
     105 
     106    unsigned int getSytInterval(); 
    105107 
    106108    int m_dimension; 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r748 r750  
    2525#include "AmdtpPort.h" 
    2626#include "../StreamProcessorManager.h" 
    27  
     27#include "devicemanager.h" 
     28 
     29#include "libieee1394/ieee1394service.h" 
     30#include "libieee1394/IsoHandlerManager.h" 
    2831#include "libieee1394/cycletimer.h" 
    2932 
     
    5760    /* Our node ID can change after a bus reset, so it is best to fetch 
    5861    * our node ID for each packet. */ 
    59     packet->sid = m_handler->getLocalNodeId() & 0x3f; 
     62    packet->sid = m_Parent.get1394Service().getLocalNodeId() & 0x3f; 
    6063 
    6164    packet->dbs = m_dimension; 
     
    276279    /* Our node ID can change after a bus reset, so it is best to fetch 
    277280    * our node ID for each packet. */ 
    278     packet->sid = m_handler->getLocalNodeId() & 0x3f; 
     281    packet->sid = m_Parent.get1394Service().getLocalNodeId() & 0x3f; 
    279282 
    280283    packet->dbs = m_dimension; 
     
    345348} 
    346349 
     350unsigned int 
     351AmdtpTransmitStreamProcessor::getSytInterval() { 
     352    switch (m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()) { 
     353        case 32000: 
     354        case 44100: 
     355        case 48000: 
     356            return 8; 
     357        case 88200: 
     358        case 96000: 
     359            return 16; 
     360        case 176400: 
     361        case 192000: 
     362            return 32; 
     363        default: 
     364            debugError("Unsupported rate: %d\n", m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
     365            return 0; 
     366    } 
     367} 
     368unsigned int 
     369AmdtpTransmitStreamProcessor::getFDF() { 
     370    switch (m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()) { 
     371        case 32000: return IEC61883_FDF_SFC_32KHZ; 
     372        case 44100: return IEC61883_FDF_SFC_44K1HZ; 
     373        case 48000: return IEC61883_FDF_SFC_48KHZ; 
     374        case 88200: return IEC61883_FDF_SFC_88K2HZ; 
     375        case 96000: return IEC61883_FDF_SFC_96KHZ; 
     376        case 176400: return IEC61883_FDF_SFC_176K4HZ; 
     377        case 192000: return IEC61883_FDF_SFC_192KHZ; 
     378        default: 
     379            debugError("Unsupported rate: %d\n", m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
     380            return 0; 
     381    } 
     382} 
     383 
    347384bool AmdtpTransmitStreamProcessor::prepareChild() 
    348385{ 
    349386    debugOutput ( DEBUG_LEVEL_VERBOSE, "Preparing (%p)...\n", this ); 
    350     switch ( m_manager->getNominalRate() ) 
    351     { 
    352         case 32000: 
    353             m_syt_interval = 8; 
    354             m_fdf = IEC61883_FDF_SFC_32KHZ; 
    355             break; 
    356         case 44100: 
    357             m_syt_interval = 8; 
    358             m_fdf = IEC61883_FDF_SFC_44K1HZ; 
    359             break; 
    360         default: 
    361         case 48000: 
    362             m_syt_interval = 8; 
    363             m_fdf = IEC61883_FDF_SFC_48KHZ; 
    364             break; 
    365         case 88200: 
    366             m_syt_interval = 16; 
    367             m_fdf = IEC61883_FDF_SFC_88K2HZ; 
    368             break; 
    369         case 96000: 
    370             m_syt_interval = 16; 
    371             m_fdf = IEC61883_FDF_SFC_96KHZ; 
    372             break; 
    373         case 176400: 
    374             m_syt_interval = 32; 
    375             m_fdf = IEC61883_FDF_SFC_176K4HZ; 
    376             break; 
    377         case 192000: 
    378             m_syt_interval = 32; 
    379             m_fdf = IEC61883_FDF_SFC_192KHZ; 
    380             break; 
    381     } 
     387    m_syt_interval = getSytInterval(); 
     388    m_fdf = getFDF(); 
    382389 
    383390    iec61883_cip_init ( 
     
    385392        IEC61883_FMT_AMDTP, 
    386393        m_fdf, 
    387         m_manager->getNominalRate(), 
     394        m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(), 
    388395        m_dimension, 
    389396        m_syt_interval ); 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h

    r748 r750  
    9898                    {return 4;}; 
    9999    virtual unsigned int getMaxPacketSize() 
    100                     {return 4 * (2 + m_syt_interval * m_dimension);}; 
     100                    {return 4 * (2 + getSytInterval() * m_dimension);}; 
    101101    virtual unsigned int getEventsPerFrame() 
    102102                    { return m_dimension; }; 
    103103    virtual unsigned int getNominalFramesPerPacket() 
    104                     {return m_syt_interval;}; 
     104                    {return getSytInterval();}; 
    105105 
    106106protected: 
     
    123123                                unsigned int offset, unsigned int nevents); 
    124124 
     125    unsigned int getFDF(); 
     126    unsigned int getSytInterval(); 
     127 
    125128    struct iec61883_cip m_cip_status; 
    126129    int m_dimension; 
  • trunk/libffado/src/libstreaming/generic/Port.cpp

    r742 r750  
    6363 */ 
    6464bool Port::init() { 
    65     if (m_State != E_Created) { 
    66         debugFatal("Port (%s) not in E_Created state: %d\n",m_Name.c_str(),m_State); 
     65    debugOutput( DEBUG_LEVEL_VERBOSE, "Initialize port %s\n", m_Name.c_str()); 
     66    if (m_State != E_Created) { 
     67        debugFatal("Port (%s) not in E_Created state: %d\n", m_Name.c_str(), m_State); 
    6768        return false; 
    6869    } 
  • trunk/libffado/src/libstreaming/generic/PortManager.cpp

    r742 r750  
    102102    debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s, type: %d, dir: %d, dtype: %d\n", 
    103103        port->getName().c_str(), port->getPortType(), port->getDirection(), port->getDataType()); 
    104      
     104 
     105    port->setVerboseLevel(getDebugLevel()); 
     106 
    105107    if (makeNameUnique(port)) { 
    106108        m_Ports.push_back(port); 
     
    178180 
    179181void PortManager::setVerboseLevel(int i) { 
    180  
    181182    setDebugLevel(i); 
    182  
    183183    for ( PortVectorIterator it = m_Ports.begin(); 
    184184      it != m_Ports.end(); 
     
    187187        (*it)->setVerboseLevel(i); 
    188188    } 
    189  
    190189} 
    191190 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp

    r749 r750  
    2323 
    2424#include "StreamProcessor.h" 
     25#include "../StreamProcessorManager.h" 
     26 
     27#include "devicemanager.h" 
     28 
     29#include "libieee1394/ieee1394service.h" 
     30#include "libieee1394/IsoHandlerManager.h" 
    2531#include "libieee1394/cycletimer.h" 
    26 #include "../StreamProcessorManager.h" 
    2732 
    2833#include "libutil/Atomic.h" 
     
    4045    , m_next_state( ePS_Invalid ) 
    4146    , m_cycle_to_switch_state( 0 ) 
    42     , m_parent( parent ) 
     47    , m_Parent( parent ) 
    4348    , m_channel( -1 ) 
    44     , m_handler( NULL ) 
    4549    , m_dropped(0) 
    4650    , m_last_timestamp(0) 
     
    4852    , m_scratch_buffer( NULL ) 
    4953    , m_scratch_buffer_size_bytes( 0 ) 
    50     , m_manager( NULL ) 
    5154    , m_ticks_per_frame( 0 ) 
    5255    , m_last_cycle( -1 ) 
     
    5962 
    6063StreamProcessor::~StreamProcessor() { 
     64    m_Parent.getDeviceManager().getStreamProcessorManager().unregisterProcessor(this); 
     65    if(!m_Parent.get1394Service().getIsoHandlerManager().unregisterStream(this)) { 
     66        debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister stream processor with the Iso manager\n"); 
     67    } 
     68 
    6169    if (m_data_buffer) delete m_data_buffer; 
    6270    if (m_scratch_buffer) delete[] m_scratch_buffer; 
     
    6472 
    6573uint64_t StreamProcessor::getTimeNow() { 
    66     return m_parent.get1394Service().getCycleTimerTicks(); 
     74    return m_Parent.get1394Service().getCycleTimerTicks(); 
    6775} 
    6876 
    6977int StreamProcessor::getMaxFrameLatency() { 
    7078    if (getType() == ePT_Receive) { 
    71         return (int)(m_handler->getWakeupInterval() * TICKS_PER_CYCLE); 
     79        return (int)(m_Parent.get1394Service().getIsoHandlerManager().getPacketLatencyForStream( this ) * TICKS_PER_CYCLE); 
    7280    } else { 
    73         return (int)(m_handler->getWakeupInterval() * TICKS_PER_CYCLE); 
     81        return (int)(m_Parent.get1394Service().getIsoHandlerManager().getPacketLatencyForStream( this ) * TICKS_PER_CYCLE); 
    7482    } 
    7583} 
     
    7886StreamProcessor::getNominalPacketsNeeded(unsigned int nframes) 
    7987{ 
    80     unsigned int nominal_frames_per_second = m_manager->getNominalRate(); 
     88    unsigned int nominal_frames_per_second  
     89                    = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
    8190    uint64_t nominal_ticks_per_frame = TICKS_PER_SECOND / nominal_frames_per_second; 
    8291    uint64_t nominal_ticks = nominal_ticks_per_frame * nframes; 
     
    8897StreamProcessor::getPacketsPerPeriod() 
    8998{ 
    90     return getNominalPacketsNeeded(m_manager->getPeriodSize()); 
     99    return getNominalPacketsNeeded(m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize()); 
    91100} 
    92101 
     
    95104 * Buffer management and manipulation          * 
    96105 ***********************************************/ 
     106void StreamProcessor::flush() { 
     107    m_Parent.get1394Service().getIsoHandlerManager().flushHandlerForStream(this); 
     108} 
     109 
    97110int StreamProcessor::getBufferFill() { 
    98111    return m_data_buffer->getBufferFill(); 
     
    112125    // pass before these packets are processed. Adding this extra term makes that 
    113126    // the period boundary is signalled later 
    114     time_at_period = addTicks(time_at_period, m_manager->getSyncSource().getSyncDelay()); 
    115  
    116     uint64_t cycle_timer=m_parent.get1394Service().getCycleTimerTicks(); 
     127    time_at_period = addTicks(time_at_period, m_Parent.getDeviceManager().getStreamProcessorManager().getSyncSource().getSyncDelay()); 
     128 
     129    uint64_t cycle_timer=m_Parent.get1394Service().getCycleTimerTicks(); 
    117130 
    118131    // calculate the time until the next period 
     
    146159{ 
    147160    if (getType() == ePT_Receive) { 
    148         ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromHead(m_manager->getPeriodSize()); 
     161        ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromHead(m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize()); 
    149162     
    150163        #ifdef DEBUG 
     
    159172        return (uint64_t)next_period_boundary; 
    160173    } else { 
    161         ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromTail((m_manager->getNbBuffers()-1) * m_manager->getPeriodSize()); 
     174        ffado_timestamp_t next_period_boundary=m_data_buffer->getTimestampFromTail((m_Parent.getDeviceManager().getStreamProcessorManager().getNbBuffers()-1) * m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize()); 
    162175     
    163176        #ifdef DEBUG 
     
    423436    // we the packet we are constructing will be sent out 
    424437    // on 'cycle', not 'now'. 
    425     unsigned int ctr = m_parent.get1394Service().getCycleTimer(); 
     438    unsigned int ctr = m_Parent.get1394Service().getCycleTimer(); 
    426439    int now_cycles = (int)CYCLE_TIMER_GET_CYCLES(ctr); 
    427440 
     
    615628    // use the ts parameter. It specifies the time of the block's  
    616629    // last sample. 
    617     float srate = m_manager->getSyncSource().getTicksPerFrame(); 
     630    float srate = m_Parent.getDeviceManager().getStreamProcessorManager().getSyncSource().getTicksPerFrame(); 
    618631    assert(srate != 0.0); 
    619632    int64_t this_block_length_in_ticks = (int64_t)(((float)nbframes) * srate); 
     
    801814    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "init...\n"); 
    802815 
     816    if(!m_Parent.get1394Service().getIsoHandlerManager().registerStream(this)) { 
     817        debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register stream processor with the Iso manager\n"); 
     818        return false; 
     819    } 
     820    if(!m_Parent.getDeviceManager().getStreamProcessorManager().registerProcessor(this)) { 
     821        debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register stream processor with the SP manager\n"); 
     822        return false; 
     823    } 
     824 
    803825    // initialization can be done without requesting it 
    804826    // from the packet loop 
     
    810832{ 
    811833    debugOutput( DEBUG_LEVEL_VERBOSE, "Prepare SP (%p)...\n", this); 
    812     if(!m_manager) { 
    813         debugFatal("Not attached to a manager!\n"); 
    814         return false; 
    815     } 
    816834 
    817835    // make the scratch buffer one period of frames long 
    818     m_scratch_buffer_size_bytes = m_manager->getPeriodSize() * getEventsPerFrame() * getEventSize(); 
     836    m_scratch_buffer_size_bytes = m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize() * getEventsPerFrame() * getEventSize(); 
    819837    debugOutput( DEBUG_LEVEL_VERBOSE, " Allocate scratch buffer of %d quadlets\n"); 
    820838    if(m_scratch_buffer) delete[] m_scratch_buffer; 
     
    832850    debugOutput( DEBUG_LEVEL_VERBOSE, "Prepared for:\n"); 
    833851    debugOutput( DEBUG_LEVEL_VERBOSE, " Samplerate: %d\n", 
    834              m_manager->getNominalRate()); 
     852             m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
    835853    debugOutput( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n", 
    836              m_manager->getPeriodSize(), m_manager->getNbBuffers()); 
     854             m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize(), m_Parent.getDeviceManager().getStreamProcessorManager().getNbBuffers()); 
    837855    debugOutput( DEBUG_LEVEL_VERBOSE, " Port: %d, Channel: %d\n", 
    838              getPort(), m_channel); 
     856             m_Parent.get1394Service().getPort(), m_channel); 
    839857 
    840858    // initialization can be done without requesting it 
     
    873891    uint64_t tx; 
    874892    if (t < 0) { 
    875         tx = addTicks(m_parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
     893        tx = addTicks(m_Parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
    876894    } else { 
    877895        tx = t; 
    878896    } 
     897    uint64_t start_handler_ticks = substractTicks(tx, 100 * TICKS_PER_CYCLE); 
     898 
    879899    debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 
    880     uint64_t now = m_parent.get1394Service().getCycleTimerTicks(); 
     900    uint64_t now = m_Parent.get1394Service().getCycleTimerTicks(); 
    881901    debugOutput(DEBUG_LEVEL_VERBOSE,"  Now                   : %011llu (%03us %04uc %04ut)\n", 
    882902                          now, 
     
    890910                          (unsigned int)TICKS_TO_OFFSET(tx)); 
    891911    if (m_state == ePS_Stopped) { 
     912        if(!m_Parent.get1394Service().getIsoHandlerManager().startHandlerForStream( 
     913                                        this, TICKS_TO_CYCLES(start_handler_ticks))) { 
     914            debugError("Could not start handler for SP %p\n", this); 
     915            return false; 
     916        } 
    892917        return scheduleStateTransition(ePS_WaitingForStream, tx); 
    893918    } else if (m_state == ePS_Running) { 
     
    902927    uint64_t tx; 
    903928    if (t < 0) { 
    904         tx = addTicks(m_parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
     929        tx = addTicks(m_Parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
    905930    } else { 
    906931        tx = t; 
    907932    } 
    908933    debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 
    909     uint64_t now = m_parent.get1394Service().getCycleTimerTicks(); 
     934    uint64_t now = m_Parent.get1394Service().getCycleTimerTicks(); 
    910935    debugOutput(DEBUG_LEVEL_VERBOSE,"  Now                   : %011llu (%03us %04uc %04ut)\n", 
    911936                          now, 
     
    924949    uint64_t tx; 
    925950    if (t < 0) { 
    926         tx = addTicks(m_parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
     951        tx = addTicks(m_Parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
    927952    } else { 
    928953        tx = t; 
    929954    } 
    930955    debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 
    931     uint64_t now = m_parent.get1394Service().getCycleTimerTicks(); 
     956    uint64_t now = m_Parent.get1394Service().getCycleTimerTicks(); 
    932957    debugOutput(DEBUG_LEVEL_VERBOSE,"  Now                   : %011llu (%03us %04uc %04ut)\n", 
    933958                          now, 
     
    940965                          (unsigned int)TICKS_TO_CYCLES(tx), 
    941966                          (unsigned int)TICKS_TO_OFFSET(tx)); 
     967 
    942968    return scheduleStateTransition(ePS_Stopped, tx); 
    943969} 
     
    946972    uint64_t tx; 
    947973    if (t < 0) { 
    948         tx = addTicks(m_parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
     974        tx = addTicks(m_Parent.get1394Service().getCycleTimerTicks(), 200 * TICKS_PER_CYCLE); 
    949975    } else { 
    950976        tx = t; 
    951977    } 
    952978    debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 
    953     uint64_t now = m_parent.get1394Service().getCycleTimerTicks(); 
     979    uint64_t now = m_Parent.get1394Service().getCycleTimerTicks(); 
    954980    debugOutput(DEBUG_LEVEL_VERBOSE,"  Now                   : %011llu (%03us %04uc %04ut)\n", 
    955981                          now, 
     
    10321058{ 
    10331059    float ticks_per_frame; 
    1034     unsigned int ringbuffer_size_frames = (m_manager->getNbBuffers() + 1) * m_manager->getPeriodSize(); 
     1060    unsigned int ringbuffer_size_frames = (m_Parent.getDeviceManager().getStreamProcessorManager().getNbBuffers() + 1) * m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize(); 
    10351061 
    10361062    debugOutput(DEBUG_LEVEL_VERBOSE, "Enter from state: %s\n", ePSToString(m_state)); 
     
    10441070 
    10451071            // prepare the framerate estimate 
    1046             ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_manager->getNominalRate()); 
     1072            ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
    10471073            m_ticks_per_frame = ticks_per_frame; 
    10481074            debugOutput(DEBUG_LEVEL_VERBOSE,"Initializing remote ticks/frame to %f\n", ticks_per_frame); 
     
    10561082                result &= m_data_buffer->setUpdatePeriod( getNominalFramesPerPacket() ); 
    10571083            } else { 
    1058                 result &= m_data_buffer->setUpdatePeriod( m_manager->getPeriodSize() ); 
     1084                result &= m_data_buffer->setUpdatePeriod( m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize() ); 
    10591085            } 
    10601086            result &= m_data_buffer->setNominalRate(ticks_per_frame); 
     
    10701096            { 
    10711097                debugOutput(DEBUG_LEVEL_VERBOSE, "Setting up port %s\n",(*it)->getName().c_str()); 
    1072                 if(!(*it)->setBufferSize(m_manager->getPeriodSize())) { 
    1073                     debugFatal("Could not set buffer size to %d\n",m_manager->getPeriodSize()); 
     1098                if(!(*it)->setBufferSize(m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize())) { 
     1099                    debugFatal("Could not set buffer size to %d\n",m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize()); 
    10741100                    return false; 
    10751101                } 
     
    11251151            break; 
    11261152        case ePS_DryRunning: 
    1127             // what to do here? 
     1153            if(!m_Parent.get1394Service().getIsoHandlerManager().stopHandlerForStream(this)) { 
     1154                debugError("Could not stop handler for SP %p\n", this); 
     1155                return false; 
     1156            } 
    11281157            break; 
    11291158        default: 
     
    12511280            } 
    12521281            if (getType() == ePT_Transmit) { 
    1253                 ringbuffer_size_frames = m_manager->getNbBuffers() * m_manager->getPeriodSize(); 
     1282                ringbuffer_size_frames = m_Parent.getDeviceManager().getStreamProcessorManager().getNbBuffers() * m_Parent.getDeviceManager().getStreamProcessorManager().getPeriodSize(); 
    12541283                debugOutput(DEBUG_LEVEL_VERBOSE, "Prefill transmit SP %p with %u frames\n", this, ringbuffer_size_frames); 
    12551284                // prefill the buffer 
     
    15301559{ 
    15311560    debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor %p information\n", this); 
    1532     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %d, %d\n", getPort(), m_channel); 
     1561    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Port, Channel  : %d, %d\n", m_Parent.get1394Service().getPort(), m_channel); 
    15331562    debugOutputShort( DEBUG_LEVEL_NORMAL, "  StreamProcessor info:\n"); 
    1534     if (m_handler) { 
    1535         uint64_t now = m_parent.get1394Service().getCycleTimerTicks(); 
    1536         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Now                   : %011llu (%03us %04uc %04ut)\n", 
    1537                           now, 
    1538                           (unsigned int)TICKS_TO_SECS(now), 
    1539                           (unsigned int)TICKS_TO_CYCLES(now), 
    1540                           (unsigned int)TICKS_TO_OFFSET(now)); 
    1541     } 
     1563    uint64_t now = m_Parent.get1394Service().getCycleTimerTicks(); 
     1564    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Now                   : %011llu (%03us %04uc %04ut)\n", 
     1565                        now, 
     1566                        (unsigned int)TICKS_TO_SECS(now), 
     1567                        (unsigned int)TICKS_TO_CYCLES(now), 
     1568                        (unsigned int)TICKS_TO_OFFSET(now)); 
    15421569    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Xruns                 : %s\n", (m_in_xrun ? "True":"False")); 
    15431570    debugOutputShort( DEBUG_LEVEL_NORMAL, "  State                 : %s\n", ePSToString(m_state)); 
     
    15451572    debugOutputShort( DEBUG_LEVEL_NORMAL, "    transition at       : %u\n", m_cycle_to_switch_state); 
    15461573    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Buffer                : %p\n", m_data_buffer); 
    1547     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Nominal framerate     : %u\n", m_manager->getNominalRate()); 
     1574    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Nominal framerate     : %u\n", m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
    15481575    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Device framerate      : Sync: %f, Buffer %f\n", 
    1549         24576000.0/m_manager->getSyncSource().m_data_buffer->getRate(), 
     1576        24576000.0/m_Parent.getDeviceManager().getStreamProcessorManager().getSyncSource().m_data_buffer->getRate(), 
    15501577        24576000.0/m_data_buffer->getRate() 
    15511578        ); 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.h

    r748 r750  
    2626 
    2727#include "ffadodevice.h" 
    28 #include "libieee1394/ieee1394service.h" 
    2928 
    3029#include "PortManager.h" 
    31 #include "../util/IsoHandler.h" 
    3230 
    3331#include "libutil/StreamStatistics.h" 
     
    5452                        public Util::OptionContainer 
    5553{ 
    56  
    5754    friend class StreamProcessorManager; // FIXME: get rid of this 
    5855 
     
    136133    virtual ~StreamProcessor(); 
    137134protected: 
    138     FFADODevice&    m_parent; 
     135    FFADODevice&    m_Parent; 
    139136 
    140137public: // the public receive/transmit functions 
     
    179176     */ 
    180177    bool putSilenceFrames(unsigned int nbframes, int64_t ts); 
    181      
     178 
    182179    /** 
    183180     * @brief Shifts the stream with the specified number of frames 
     
    191188     */ 
    192189    bool shiftStream(int nframes); 
     190 
     191    /** 
     192     * @brief tries to fill/sink the stream as far as possible 
     193     */ 
     194    void flush(); 
     195 
    193196protected: // the helper receive/transmit functions 
    194197    enum eChildReturnValue { 
     
    260263    bool setChannel(int c) 
    261264        {m_channel = c; return true;}; 
    262     int getPort() {return m_parent.get1394Service().getPort();}; 
     265 
     266    virtual unsigned int getNbPacketsIsoXmitBuffer() 
     267        {return (getPacketsPerPeriod() * 750)/1000;}; 
    263268    virtual unsigned int getPacketsPerPeriod(); 
    264269    virtual unsigned int getMaxPacketSize() = 0; 
    265     // do we need the handler? 
    266     void setHandler( IsoHandler * h) {m_handler = h;}; 
    267     void clearHandler() {m_handler = NULL;}; 
    268270private: 
    269271    int m_channel; 
    270 protected: 
    271     IsoHandler *m_handler; // needed for local id and cycle counter 
    272272 
    273273protected: // FIXME: move to private 
     
    298298    byte_t*         m_scratch_buffer; 
    299299    size_t          m_scratch_buffer_size_bytes; 
     300 
    300301protected: 
    301     StreamProcessorManager *m_manager; 
    302  
    303302    // frame counter & sync stuff 
    304303    public: 
     
    442441    private: 
    443442        bool m_in_xrun; 
    444  
    445 protected: // SPM related 
    446     void setManager(StreamProcessorManager *manager) {m_manager=manager;}; 
    447     void clearManager() {m_manager=NULL;}; 
    448443 
    449444public: 
  • trunk/libffado/src/libstreaming/motu/MotuReceiveStreamProcessor.cpp

    r748 r750  
    2626#include "MotuPort.h" 
    2727#include "../StreamProcessorManager.h" 
    28  
     28#include "devicemanager.h" 
     29 
     30#include "libieee1394/ieee1394service.h" 
     31#include "libieee1394/IsoHandlerManager.h" 
    2932#include "libieee1394/cycletimer.h" 
    3033 
     
    7477unsigned int 
    7578MotuReceiveStreamProcessor::getMaxPacketSize() { 
    76     int framerate = m_manager->getNominalRate(); 
     79    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
    7780    return framerate<=48000?616:(framerate<=96000?1032:1160); 
    7881} 
     
    8083unsigned int 
    8184MotuReceiveStreamProcessor::getNominalFramesPerPacket() { 
    82     int framerate = m_manager->getNominalRate(); 
     85    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
    8386    return framerate<=48000?8:(framerate<=96000?16:32); 
    8487} 
     
    9093    // prepare the framerate estimate 
    9194    // FIXME: not needed anymore? 
    92     //m_ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_manager->getNominalRate()); 
     95    //m_ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate()); 
    9396 
    9497    return true; 
     
    137140        // we can just pick it straight from the packet. 
    138141        uint32_t last_sph = ntohl(*(quadlet_t *)(data+8+(n_events-1)*event_length)); 
    139         m_last_timestamp = sphRecvToFullTicks(last_sph, m_parent.get1394Service().getCycleTimer()); 
     142        m_last_timestamp = sphRecvToFullTicks(last_sph, m_Parent.get1394Service().getCycleTimer()); 
    140143        return eCRV_OK; 
    141144    } else { 
     
    178181    #ifdef DEBUG 
    179182    if(isRunning()) { 
    180         debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"STMP: %lluticks | buff=%d, tpf=%f\n", 
    181             m_last_timestamp, m_handler->getWakeupInterval(), getTicksPerFrame()); 
     183        debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"STMP: %lluticks | tpf=%f\n", 
     184            m_last_timestamp, getTicksPerFrame()); 
    182185    } 
    183186    #endif 
  • trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp

    r749 r750  
    2626#include "MotuPort.h" 
    2727#include "../StreamProcessorManager.h" 
    28  
     28#include "devicemanager.h" 
     29 
     30#include "libieee1394/ieee1394service.h" 
     31#include "libieee1394/IsoHandlerManager.h" 
    2932#include "libieee1394/cycletimer.h" 
    3033 
     
    6770unsigned int 
    6871MotuTransmitStreamProcessor::getMaxPacketSize() { 
    69     int framerate = m_manager->getNominalRate(); 
     72    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
    7073    return framerate<=48000?616:(framerate<=96000?1032:1160); 
    7174} 
     
    7376unsigned int 
    7477MotuTransmitStreamProcessor::getNominalFramesPerPacket() { 
    75     int framerate = m_manager->getNominalRate(); 
     78    int framerate = m_Parent.getDeviceManager().getStreamProcessorManager().getNominalRate(); 
    7679    return framerate<=48000?8:(framerate<=96000?16:32); 
    7780} 
     
    285288 
    286289    if (m_data_buffer->readFrames(n_events, (char *)(data + 8))) { 
    287         float ticks_per_frame = m_manager->getSyncSource().getActualRate(); 
     290        float ticks_per_frame = m_Parent.getDeviceManager().getStreamProcessorManager().getSyncSource().getActualRate(); 
    288291 
    289292#if TESTTONE 
     
    378381    // present.  For data-less packets the dbc is the same as the previously 
    379382    // transmitted block. 
    380     *quadlet = htonl(0x00000400 | ((m_handler->getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
     383    *quadlet = htonl(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
    381384    quadlet++; 
    382385    *quadlet = htonl(0x8222ffff); 
     
    395398    // present.  For data-less packets the dbc is the same as the previously 
    396399    // transmitted block. 
    397     *quadlet = htonl(0x00000400 | ((m_handler->getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
     400    *quadlet = htonl(0x00000400 | ((m_Parent.get1394Service().getLocalNodeId()&0x3f)<<24) | m_tx_dbc | (dbs<<16)); 
    398401    quadlet++; 
    399402    *quadlet = htonl(0x8222ffff); 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r748 r750  
    4545 
    4646IMPL_DEBUG_MODULE( StreamProcessorManager, StreamProcessorManager, DEBUG_LEVEL_VERBOSE ); 
     47 
     48StreamProcessorManager::StreamProcessorManager() 
     49    : m_is_slave( false ) 
     50    , m_SyncSource(NULL) 
     51    , m_nb_buffers( 0 ) 
     52    , m_period( 0 ) 
     53    , m_nominal_framerate ( 0 ) 
     54    , m_xruns(0) 
     55    , m_xrun_happened( false ) 
     56    , m_nbperiods(0) 
     57{ 
     58    addOption(Util::OptionContainer::Option("slaveMode",false)); 
     59} 
    4760 
    4861StreamProcessorManager::StreamProcessorManager(unsigned int period, unsigned int framerate, unsigned int nb_buffers) 
     
    5366    , m_nominal_framerate ( framerate ) 
    5467    , m_xruns(0) 
    55     , m_isoManager(0
     68    , m_xrun_happened( false
    5669    , m_nbperiods(0) 
    5770{ 
     
    6073 
    6174StreamProcessorManager::~StreamProcessorManager() { 
    62     if (m_isoManager) delete m_isoManager; 
    6375} 
    6476 
     
    7890    debugOutput( DEBUG_LEVEL_VERBOSE, "Registering processor (%p)\n",processor); 
    7991    assert(processor); 
    80     assert(m_isoManager); 
    81  
    8292    if (processor->getType() == StreamProcessor::ePT_Receive) { 
    8393        processor->setVerboseLevel(getDebugLevel()); // inherit debug level 
    84  
    8594        m_ReceiveProcessors.push_back(processor); 
    86         processor->setManager(this); 
    8795        return true; 
    8896    } 
     
    9098    if (processor->getType() == StreamProcessor::ePT_Transmit) { 
    9199        processor->setVerboseLevel(getDebugLevel()); // inherit debug level 
    92  
    93100        m_TransmitProcessors.push_back(processor); 
    94         processor->setManager(this); 
    95101        return true; 
    96102    } 
     
    113119            if ( *it == processor ) { 
    114120                m_ReceiveProcessors.erase(it); 
    115                 processor->clearManager(); 
    116                 if(!m_isoManager->unregisterStream(processor)) { 
    117                     debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor from the Iso manager\n"); 
    118                     return false; 
    119                 } 
    120121                return true; 
    121122            } 
     
    130131            if ( *it == processor ) { 
    131132                m_TransmitProcessors.erase(it); 
    132                 processor->clearManager(); 
    133                 if(!m_isoManager->unregisterStream(processor)) { 
    134                     debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor from the Iso manager\n"); 
    135                     return false; 
    136                 } 
    137133                return true; 
    138134            } 
     
    147143    debugOutput( DEBUG_LEVEL_VERBOSE, "Setting sync source to (%p)\n", s); 
    148144    m_SyncSource=s; 
    149     return true; 
    150 } 
    151  
    152 bool StreamProcessorManager::init() 
    153 { 
    154     debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); 
    155     m_isoManager = new IsoHandlerManager(m_thread_realtime, m_thread_priority + 1); 
    156     if(!m_isoManager) { 
    157         debugFatal("Could not create IsoHandlerManager\n"); 
    158         return false; 
    159     } 
    160     m_isoManager->setVerboseLevel(getDebugLevel()); 
    161      
    162     // try to queue up 75% of the frames in the transmit buffer 
    163     unsigned int nb_frames = (getNbBuffers() - 1) * getPeriodSize() * 1000 / 2000; 
    164     m_isoManager->setTransmitBufferNbFrames(nb_frames); 
    165  
    166     if(!m_isoManager->init()) { 
    167         debugFatal("Could not initialize IsoHandlerManager\n"); 
    168         return false; 
    169     } 
    170  
    171     m_xrun_happened=false; 
    172145    return true; 
    173146} 
     
    528501bool StreamProcessorManager::start() { 
    529502    debugOutput( DEBUG_LEVEL_VERBOSE, "Starting Processors...\n"); 
    530     assert(m_isoManager); 
    531  
    532     debugOutput( DEBUG_LEVEL_VERBOSE, "Creating handlers for the StreamProcessors...\n"); 
    533     debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); 
    534     for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    535           it != m_ReceiveProcessors.end(); 
    536           ++it ) 
    537     { 
    538         if (!m_isoManager->registerStream(*it)) { 
    539             debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register receive stream processor (%p) with the Iso manager\n",*it); 
    540             return false; 
    541         } 
    542     } 
    543     debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n"); 
    544     for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    545           it != m_TransmitProcessors.end(); 
    546           ++it ) 
    547     { 
    548         if (!m_isoManager->registerStream(*it)) { 
    549             debugOutput(DEBUG_LEVEL_VERBOSE,"Could not register transmit stream processor (%p) with the Iso manager\n",*it); 
    550             return false; 
    551         } 
    552     } 
    553  
    554     debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing IsoHandlerManager...\n"); 
    555     if (!m_isoManager->prepare()) { 
    556         debugFatal("Could not prepare isoManager\n"); 
    557         return false; 
    558     } 
    559  
    560     debugOutput( DEBUG_LEVEL_VERBOSE, "Starting IsoHandlers...\n"); 
    561     if (!m_isoManager->startHandlers(0)) { 
    562         debugFatal("Could not start handlers...\n"); 
    563         return false; 
    564     } 
    565503 
    566504    // put all SP's into dry-running state 
     
    575513        return false; 
    576514    } 
    577  
    578     // dump the iso stream information when in verbose mode 
    579     if(getDebugLevel()>=DEBUG_LEVEL_VERBOSE) { 
    580         m_isoManager->dumpInfo(); 
    581     } 
    582  
    583515    return true; 
    584516} 
     
    586518bool StreamProcessorManager::stop() { 
    587519    debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping...\n"); 
    588     assert(m_isoManager); 
    589520 
    590521    debugOutput( DEBUG_LEVEL_VERBOSE, " scheduling stop for all SP's...\n"); 
    591  
    592522    // switch SP's over to the dry-running state 
    593523    for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     
    668598        debugOutput(DEBUG_LEVEL_VERBOSE, " Timeout waiting for the SP's to stop\n"); 
    669599        return false; 
    670     } 
    671  
    672     debugOutput( DEBUG_LEVEL_VERBOSE, "Stopping handlers...\n"); 
    673     if(!m_isoManager->stopHandlers()) { 
    674        debugFatal("Could not stop ISO handlers\n"); 
    675        return false; 
    676     } 
    677  
    678     debugOutput( DEBUG_LEVEL_VERBOSE, "Unregistering processors from handlers...\n"); 
    679     // now unregister all streams from iso manager 
    680     debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); 
    681     for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    682           it != m_ReceiveProcessors.end(); 
    683           ++it ) { 
    684         if (!m_isoManager->unregisterStream(*it)) { 
    685             debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister receive stream processor (%p) from the Iso manager\n",*it); 
    686             return false; 
    687         } 
    688     } 
    689     debugOutput( DEBUG_LEVEL_VERBOSE, " Transmit processors...\n"); 
    690     for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    691           it != m_TransmitProcessors.end(); 
    692           ++it ) { 
    693         if (!m_isoManager->unregisterStream(*it)) { 
    694             debugOutput(DEBUG_LEVEL_VERBOSE,"Could not unregister transmit stream processor (%p) from the Iso manager\n",*it); 
    695             return false; 
    696         } 
    697600    } 
    698601    return true; 
     
    806709    #endif 
    807710    bool ready_for_transfer = false; 
     711    bool ready; 
    808712    xrun_occurred = false; 
    809713    while (!ready_for_transfer && !xrun_occurred) { 
     
    812716            it != m_ReceiveProcessors.end(); 
    813717            ++it ) { 
    814             ready_for_transfer &= ((*it)->canClientTransferFrames(m_period)); 
     718            ready = ((*it)->canClientTransferFrames(m_period)); 
     719            ready_for_transfer &= ready; 
     720            if (!ready) (*it)->flush(); 
    815721            xrun_occurred |= (*it)->xrunOccurred(); 
    816722        } 
     
    818724            it != m_TransmitProcessors.end(); 
    819725            ++it ) { 
    820             ready_for_transfer &= ((*it)->canClientTransferFrames(m_period)); 
     726            ready = ((*it)->canClientTransferFrames(m_period)); 
     727            ready_for_transfer &= ready; 
     728            if (!ready) (*it)->flush(); 
    821729            xrun_occurred |= (*it)->xrunOccurred(); 
    822730        } 
    823731        if (!ready_for_transfer) { 
     732             
    824733            usleep(125); // MAGIC: one cycle sleep... 
    825734 
     735            #if 0 
    826736            // in order to avoid this in the future, we increase the sync delay of the sync source SP 
    827737            int d = m_SyncSource->getSyncDelay() + TICKS_PER_CYCLE; 
    828738            m_SyncSource->setSyncDelay(d); 
     739            #endif 
    829740 
    830741            #ifdef DEBUG 
     
    1048959    } 
    1049960 
    1050     debugOutputShort( DEBUG_LEVEL_NORMAL, "Iso handler info:\n"); 
    1051     m_isoManager->dumpInfo(); 
    1052961    debugOutputShort( DEBUG_LEVEL_NORMAL, "----------------------------------------------------\n"); 
    1053962 
     
    1056965void StreamProcessorManager::setVerboseLevel(int l) { 
    1057966    setDebugLevel(l); 
    1058  
    1059     if (m_isoManager) m_isoManager->setVerboseLevel(l); 
    1060967 
    1061968    debugOutput( DEBUG_LEVEL_VERBOSE, " Receive processors...\n"); 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.h

    r742 r750  
    2727#include "generic/Port.h" 
    2828#include "generic/StreamProcessor.h" 
    29 #include "util/IsoHandlerManager.h" 
    3029 
    3130#include "debugmodule/debugmodule.h" 
     
    3938 
    4039class StreamProcessor; 
    41 class IsoHandlerManager; 
    4240 
    4341typedef std::vector<StreamProcessor *> StreamProcessorVector; 
     
    5351public: 
    5452 
     53    StreamProcessorManager(); 
    5554    StreamProcessorManager(unsigned int period, unsigned int rate, unsigned int nb_buffers); 
    5655    virtual ~StreamProcessorManager(); 
    5756 
    58     bool init(); ///< to be called immediately after the construction 
    5957    bool prepare(); ///< to be called after the processors are registered 
    6058 
     
    6967    bool unregisterProcessor(StreamProcessor *processor); ///< stop managing a streamprocessor 
    7068 
    71     void setPeriodSize(unsigned int period); 
    72     void setPeriodSize(unsigned int period, unsigned int nb_buffers); 
    73     unsigned int getPeriodSize() {return m_period;}; 
     69    void setPeriodSize(unsigned int period) 
     70            {m_period = period;}; 
     71    unsigned int getPeriodSize() 
     72            {return m_period;}; 
    7473 
    75     void setNbBuffers(unsigned int nb_buffers); 
    76     int getNbBuffers() {return m_nb_buffers;}; 
     74    void setNbBuffers(unsigned int nb_buffers) 
     75            {m_nb_buffers = nb_buffers;}; 
     76    int getNbBuffers()  
     77            {return m_nb_buffers;}; 
    7778 
    7879    int getPortCount(enum Port::E_PortType, enum Port::E_Direction); 
     
    9495    int getXrunCount() {return m_xruns;}; 
    9596 
     97    void setNominalRate(unsigned int r) {m_nominal_framerate = r;}; 
    9698    unsigned int getNominalRate() {return m_nominal_framerate;}; 
    9799    uint64_t getTimeOfLastTransfer() { return m_time_of_transfer;}; 
     
    128130    // thread sync primitives 
    129131    bool m_xrun_happened; 
    130  
    131132    bool m_thread_realtime; 
    132133    int m_thread_priority; 
     
    141142    unsigned int m_xruns; 
    142143 
    143     IsoHandlerManager *m_isoManager; 
    144  
    145144    unsigned int m_nbperiods; 
    146145 
  • trunk/libffado/src/libutil/PosixThread.cpp

    r742 r750  
    7474    } 
    7575 
    76     debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: start\n"); 
     76    debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: start %p\n", obj); 
    7777 
    7878    // If Init succeed start the thread loop 
     
    8383    } 
    8484 
    85     debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: exit\n"); 
     85    debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: exit %p\n", obj); 
    8686    return 0; 
    8787} 
     
    9494    if (fRealTime) { 
    9595 
    96         debugOutput( DEBUG_LEVEL_VERBOSE, "Create RT thread with priority %d\n", fPriority); 
     96        debugOutput( DEBUG_LEVEL_VERBOSE, "Create RT thread %p with priority %d\n", this, fPriority); 
    9797 
    9898        /* Get the client thread to run as an RT-FIFO 
     
    138138        return 0; 
    139139    } else { 
    140         debugOutput( DEBUG_LEVEL_VERBOSE, "Create non RT thread\n"); 
     140        debugOutput( DEBUG_LEVEL_VERBOSE, "Create non RT thread %p\n", this); 
    141141 
    142142        if ((res = pthread_create(&fThread, 0, ThreadHandler, this))) { 
     
    152152{ 
    153153    if (fThread) { // If thread has been started 
    154         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Kill\n"); 
     154        debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Kill %p\n", this); 
    155155        void* status; 
    156156        pthread_cancel(fThread); 
    157157        pthread_join(fThread, &status); 
     158        debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Killed %p\n", this); 
    158159        return 0; 
    159160    } else { 
     
    165166{ 
    166167    if (fThread) { // If thread has been started 
    167         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Stop\n"); 
     168        debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Stop %p\n", this); 
    168169        void* status; 
    169170        fRunning = false; // Request for the thread to stop 
    170171        pthread_join(fThread, &status); 
     172        debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Stopped %p\n", this); 
    171173        return 0; 
    172174    } else { 
  • trunk/libffado/src/maudio/maudio_avdevice.cpp

    r742 r750  
    4040namespace MAudio { 
    4141 
    42 AvDevice::AvDevice(std::auto_ptr<ConfigRom>( configRom )) 
    43     : BeBoB::AvDevice( configRom) 
     42AvDevice::AvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     43    : BeBoB::AvDevice( d, configRom) 
    4444    , m_model ( NULL ) 
    4545{ 
     
    8181 
    8282FFADODevice * 
    83 AvDevice::createDevice(std::auto_ptr<ConfigRom>( configRom )) 
     83AvDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
    8484{ 
    85     return new AvDevice(configRom ); 
     85    return new AvDevice( d, configRom ); 
    8686} 
    8787 
  • trunk/libffado/src/maudio/maudio_avdevice.h

    r742 r750  
    5454class AvDevice : public BeBoB::AvDevice { 
    5555public: 
    56     AvDevice(std::auto_ptr<ConfigRom>( configRom )); 
     56    AvDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    5757    virtual ~AvDevice(); 
    5858 
    5959    static bool probe( ConfigRom& configRom ); 
    60     static FFADODevice * createDevice(std::auto_ptr<ConfigRom>( configRom )); 
     60    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    6161    virtual bool discover(); 
    6262 
  • trunk/libffado/src/motu/motu_avdevice.cpp

    r748 r750  
    186186}; 
    187187 
    188 MotuDevice::MotuDevice( std::auto_ptr<ConfigRom>( configRom )) 
    189     : FFADODevice( configRom ) 
     188MotuDevice::MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     189    : FFADODevice( d, configRom ) 
    190190    , m_motu_model( MOTUFW_MODEL_NONE ) 
    191191    , m_iso_recv_channel ( -1 ) 
     
    239239 
    240240FFADODevice * 
    241 MotuDevice::createDevice(std::auto_ptr<ConfigRom>( configRom )) 
    242 { 
    243     return new MotuDevice(configRom); 
     241MotuDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
     242{ 
     243    return new MotuDevice(d, configRom); 
    244244} 
    245245 
  • trunk/libffado/src/motu/motu_avdevice.h

    r742 r750  
    125125public: 
    126126 
    127     MotuDevice(std::auto_ptr<ConfigRom>( configRom )); 
     127    MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) ); 
    128128    virtual ~MotuDevice(); 
    129129 
    130130    static bool probe( ConfigRom& configRom ); 
    131     static FFADODevice * createDevice(std::auto_ptr<ConfigRom>( configRom )); 
     131    static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )); 
    132132    static int getConfigurationId( ); 
    133133    virtual bool discover(); 
  • trunk/libffado/src/SConscript

    r747 r750  
    6262        libieee1394/ieee1394service.cpp \ 
    6363        libieee1394/IEC61883.cpp \ 
     64        libieee1394/IsoHandler.cpp \ 
     65        libieee1394/IsoHandlerManager.cpp \ 
    6466        libstreaming/StreamProcessorManager.cpp \ 
    6567        libstreaming/util/cip.c \ 
    66         libstreaming/util/IsoHandler.cpp \ 
    67         libstreaming/util/IsoHandlerManager.cpp \ 
    6868        libstreaming/generic/StreamProcessor.cpp \ 
    6969        libstreaming/generic/Port.cpp \ 
  • trunk/libffado/support/firmware/fireworks-downloader.cpp

    r742 r750  
    3030 
    3131#include "debugmodule/debugmodule.h" 
     32 
     33#include "devicemanager.h" 
    3234 
    3335#include <argp.h> 
     
    165167        return -1; 
    166168    } 
    167  
    168     Device *dev = new Device( std::auto_ptr<ConfigRom>(configRom) ); 
     169     
     170    DeviceManager d = DeviceManager(); 
     171    Device *dev = new Device(d, std::auto_ptr<ConfigRom>(configRom) ); 
    169172    if (dev == NULL) { 
    170173        debugError("Could not create FireWorks::Device\n"); 
  • trunk/libffado/tests/streaming/teststreaming3.c

    r742 r750  
    5252{ 
    5353 
    54         #define PERIOD_SIZE 256 
     54        #define PERIOD_SIZE 1024 
    5555 
    5656        int samplesread=0; 
     
    8888        dev_options.packetizer_priority=70; 
    8989         
    90         dev_options.verbose=5
     90        dev_options.verbose = 6
    9191         
    9292        dev_options.slave_mode=0;