Show
Ignore:
Timestamp:
02/27/07 03:31:33 (17 years ago)
Author:
pieterpalmers
Message:

- The library can now be started in 'slave mode', creating a BounceSlaveDevice?.

On a discovering node, this slave device is discovered as a BounceDevice?.
Streaming does not work yet, something wrong with the timestamps.

- Implemented the 'snoop mode', that allows a client to 'snoop' the streams

between another host and a device. It is only implemented for BeBoB devices.
The channel numbers and stream configuration are automatically detected.
Note that it currently relies on a rather hackish support for reading the
{i,o}PCR plugs by using private functions of libiec61883

- changed jack backend to support these two new features

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/bebob/bebob_avdevice.cpp

    r420 r424  
    725725AvDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency ) 
    726726{ 
    727  
    728     AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
    729     if ( !plug ) { 
    730         debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    731         return false; 
    732     } 
    733  
    734     if ( !setSamplingFrequencyPlug( *plug, 
    735                                     AvPlug::eAPD_Input, 
    736                                     samplingFrequency ) ) 
    737     { 
    738         debugError( "setSampleRate: Setting sample rate failed\n" ); 
    739         return false; 
    740     } 
    741  
    742     plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output,  0 ); 
    743     if ( !plug ) { 
    744         debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
    745         return false; 
    746     } 
    747  
    748     if ( !setSamplingFrequencyPlug( *plug, 
    749                                     AvPlug::eAPD_Output, 
    750                                     samplingFrequency ) ) 
    751     { 
    752         debugError( "setSampleRate: Setting sample rate failed\n" ); 
    753         return false; 
    754     } 
    755  
    756  
    757     debugOutput( DEBUG_LEVEL_VERBOSE, 
    758                  "setSampleRate: Set sample rate to %d\n", 
    759                  convertESamplingFrequency( samplingFrequency ) ); 
    760     return true; 
     727    bool snoopMode=false; 
     728    if(!getOption("snoopMode", snoopMode)) { 
     729        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     730    } 
     731     
     732    if(snoopMode) { 
     733        int current_sr=getSamplingFrequency(); 
     734        if (current_sr != convertESamplingFrequency( samplingFrequency ) ) { 
     735            debugError("In snoop mode it is impossible to set the sample rate.\n"); 
     736            debugError("Please start the client with the correct setting.\n"); 
     737            return false; 
     738        } 
     739        return true; 
     740    } else { 
     741        AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
     742        if ( !plug ) { 
     743            debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
     744            return false; 
     745        } 
     746     
     747        if ( !setSamplingFrequencyPlug( *plug, 
     748                                        AvPlug::eAPD_Input, 
     749                                        samplingFrequency ) ) 
     750        { 
     751            debugError( "setSampleRate: Setting sample rate failed\n" ); 
     752            return false; 
     753        } 
     754     
     755        plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output,  0 ); 
     756        if ( !plug ) { 
     757            debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     758            return false; 
     759        } 
     760     
     761        if ( !setSamplingFrequencyPlug( *plug, 
     762                                        AvPlug::eAPD_Output, 
     763                                        samplingFrequency ) ) 
     764        { 
     765            debugError( "setSampleRate: Setting sample rate failed\n" ); 
     766            return false; 
     767        } 
     768     
     769        debugOutput( DEBUG_LEVEL_VERBOSE, 
     770                     "setSampleRate: Set sample rate to %d\n", 
     771                     convertESamplingFrequency( samplingFrequency ) ); 
     772        return true; 
     773    } 
     774    // not executable 
     775    return false; 
    761776} 
    762777 
     
    955970bool 
    956971AvDevice::lock() { 
     972    bool snoopMode=false; 
     973    if(!getOption("snoopMode", snoopMode)) { 
     974        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     975    } 
     976 
     977    if (snoopMode) { 
     978        // don't lock 
     979    } else { 
     980     
     981    } 
    957982 
    958983    return true; 
    959984} 
    960985 
    961  
    962986bool 
    963987AvDevice::unlock() { 
    964  
     988    bool snoopMode=false; 
     989    if(!getOption("snoopMode", snoopMode)) { 
     990        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     991    } 
     992 
     993    if (snoopMode) { 
     994        // don't unlock 
     995    } else { 
     996     
     997    } 
    965998    return true; 
    966999} 
     
    9721005        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
    9731006    } 
    974  
     1007     
    9751008    /////////// 
    9761009    // get plugs 
     
    9891022    int samplerate=outputPlug->getSampleRate(); 
    9901023     
     1024    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing receive processor...\n"); 
    9911025    // create & add streamprocessors 
    9921026    Streaming::StreamProcessor *p; 
     
    10131047 
    10141048    // do the transmit processor 
     1049    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing transmit processor%s...\n", 
     1050            (snoopMode?" in snoop mode":"")); 
    10151051    if (snoopMode) { 
    10161052        // we are snooping, so this is receive too. 
     
    10391075            return false; 
    10401076        } 
    1041         m_receiveProcessors.push_back(p); 
    10421077    } else { 
    10431078        if (!addPlugToProcessor(*inputPlug,p, 
     
    10461081            return false; 
    10471082        } 
    1048         m_transmitProcessors.push_back(p); 
    1049     } 
     1083    } 
     1084     
     1085    // we put this SP into the transmit SP vector, 
     1086    // no matter if we are in snoop mode or not 
     1087    // this allows us to find out what direction 
     1088    // a certain stream should have. 
     1089    m_transmitProcessors.push_back(p); 
    10501090 
    10511091    return true; 
     
    11571197AvDevice::startStreamByIndex(int i) { 
    11581198    int iso_channel=-1; 
    1159      
     1199    bool snoopMode=false; 
     1200    if(!getOption("snoopMode", snoopMode)) { 
     1201        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     1202    } 
     1203 
    11601204    if (i<(int)m_receiveProcessors.size()) { 
    11611205        int n=i; 
    11621206        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
    11631207         
    1164         iso_channel=m_p1394Service->allocateIsoChannelCMP( 
    1165             m_pConfigRom->getNodeId() | 0xffc0, 0,  
    1166             m_p1394Service->getLocalNodeId()| 0xffc0, -1); 
    1167          
     1208        if(snoopMode) { // a stream from the device to another host 
     1209            // FIXME: put this into a decent framework! 
     1210            // we should check the oPCR[n] on the device 
     1211            struct iec61883_oPCR opcr; 
     1212            if (iec61883_get_oPCRX( 
     1213                    m_p1394Service->getHandle(),  
     1214                    m_pConfigRom->getNodeId() | 0xffc0, 
     1215                    (quadlet_t *)&opcr, 
     1216                    n)) { 
     1217                     
     1218                debugWarning("Error getting the channel for SP %d\n",i); 
     1219                return false; 
     1220            } 
     1221             
     1222            iso_channel=opcr.channel; 
     1223        } else { 
     1224            iso_channel=m_p1394Service->allocateIsoChannelCMP( 
     1225                m_pConfigRom->getNodeId() | 0xffc0, n,  
     1226                m_p1394Service->getLocalNodeId()| 0xffc0, -1); 
     1227        } 
    11681228        if (iso_channel<0) { 
    11691229            debugError("Could not allocate ISO channel for SP %d\n",i); 
    11701230            return false; 
    11711231        } 
     1232         
     1233        debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 
    11721234         
    11731235        p->setChannel(iso_channel); 
     
    11781240        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
    11791241         
    1180         iso_channel=m_p1394Service->allocateIsoChannelCMP( 
    1181             m_p1394Service->getLocalNodeId()| 0xffc0, -1, 
    1182             m_pConfigRom->getNodeId() | 0xffc0, 0); 
     1242        if(snoopMode) { // a stream from another host to the device  
     1243            // FIXME: put this into a decent framework! 
     1244            // we should check the iPCR[n] on the device 
     1245            struct iec61883_iPCR ipcr; 
     1246            if (iec61883_get_iPCRX( 
     1247                    m_p1394Service->getHandle(),  
     1248                    m_pConfigRom->getNodeId() | 0xffc0, 
     1249                    (quadlet_t *)&ipcr, 
     1250                    n)) { 
     1251                     
     1252                debugWarning("Error getting the channel for SP %d\n",i); 
     1253                return false; 
     1254            } 
     1255             
     1256            iso_channel=ipcr.channel; 
     1257             
     1258        } else { 
     1259            iso_channel=m_p1394Service->allocateIsoChannelCMP( 
     1260                m_p1394Service->getLocalNodeId()| 0xffc0, -1, 
     1261                m_pConfigRom->getNodeId() | 0xffc0, n); 
     1262        } 
    11831263         
    11841264        if (iso_channel<0) { 
     
    11871267        } 
    11881268         
     1269        debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 
     1270         
    11891271        p->setChannel(iso_channel); 
    11901272        return true; 
     
    11971279bool 
    11981280AvDevice::stopStreamByIndex(int i) { 
    1199    if (i<(int)m_receiveProcessors.size()) { 
     1281    bool snoopMode=false; 
     1282    if(!getOption("snoopMode", snoopMode)) { 
     1283        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     1284    } 
     1285 
     1286    if (i<(int)m_receiveProcessors.size()) { 
    12001287        int n=i; 
    12011288        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
    12021289 
    1203         // deallocate ISO channel 
    1204         if(!m_p1394Service->freeIsoChannel(p->getChannel())) { 
    1205             debugError("Could not deallocate iso channel for SP %d\n",i); 
    1206             return false; 
     1290        if(snoopMode) { 
     1291 
     1292        } else { 
     1293            // deallocate ISO channel 
     1294            if(!m_p1394Service->freeIsoChannel(p->getChannel())) { 
     1295                debugError("Could not deallocate iso channel for SP %d\n",i); 
     1296                return false; 
     1297            } 
    12071298        } 
    12081299        p->setChannel(-1); 
     
    12141305        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
    12151306         
    1216         // deallocate ISO channel 
    1217         if(!m_p1394Service->freeIsoChannel(p->getChannel())) { 
    1218             debugError("Could not deallocate iso channel for SP %d\n",i); 
    1219             return false; 
     1307        if(snoopMode) { 
     1308 
     1309        } else { 
     1310            // deallocate ISO channel 
     1311            if(!m_p1394Service->freeIsoChannel(p->getChannel())) { 
     1312                debugError("Could not deallocate iso channel for SP %d\n",i); 
     1313                return false; 
     1314            } 
    12201315        } 
    12211316        p->setChannel(-1); 
  • branches/streaming-rework/src/bounce/bounce_avdevice.cpp

    r420 r424  
    4545static VendorModelEntry supportedDeviceList[] = 
    4646{ 
    47     {0x0B0001, 0x0B0001, 0x0B0001, "FreeBoB", "Bounce"}, 
     47    {0x0B0001LU, 0x0B0001LU, 0x0B0001LU, "FreeBoB", "Bounce"}, 
    4848}; 
    4949 
     
    5858    , m_p1394Service( &ieee1394service ) 
    5959    , m_nodeId( nodeId ) 
    60     , m_verboseLevel( verboseLevel ) 
     60//     , m_verboseLevel( verboseLevel ) 
     61    , m_verboseLevel( DEBUG_LEVEL_VERBOSE ) 
    6162    , m_samplerate (44100) 
    6263    , m_model( NULL ) 
     
    8586BounceDevice::probe( ConfigRom& configRom ) 
    8687{ 
     88 
     89    debugOutput( DEBUG_LEVEL_VERBOSE, "probing BounceDevice\n"); 
    8790//     unsigned int vendorId = configRom.getNodeVendorId(); 
    8891    unsigned int modelId = configRom.getModelId(); 
    8992    unsigned int unitSpecifierId = configRom.getUnitSpecifierId(); 
     93    debugOutput( DEBUG_LEVEL_VERBOSE, "modelId = 0x%08X, specid = 0x%08X\n", modelId, unitSpecifierId); 
    9094 
    9195    for ( unsigned int i = 0; 
     
    109113BounceDevice::discover() 
    110114{ 
    111 //      unsigned int resp_len=0; 
    112 //      quadlet_t request[6]; 
    113 //      quadlet_t *resp; 
    114  
     115    debugOutput( DEBUG_LEVEL_VERBOSE, "discovering BounceDevice (NodeID %d)\n", 
     116                 m_nodeId ); 
     117                  
    115118//     unsigned int vendorId = m_configRom->getNodeVendorId(); 
    116119    unsigned int modelId = m_configRom->getModelId(); 
     
    135138        return true; 
    136139    } 
    137      
    138     debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering...\n" ); 
    139  
    140         std::string vendor=std::string(FREEBOB_BOUNCE_SERVER_VENDORNAME); 
    141         std::string model=std::string(FREEBOB_BOUNCE_SERVER_MODELNAME); 
    142  
    143         if (!(m_configRom->getVendorName().compare(0,vendor.length(),vendor,0,vendor.length())==0) 
    144             || !(m_configRom->getModelName().compare(0,model.length(),model,0,model.length())==0)) { 
    145                 return false; 
    146         } 
    147 /* 
    148 // AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT 
    149         request[0] = htonl( AVC1394_CTYPE_STATUS | (AVC1394_SUBUNIT_TYPE_FREEBOB_BOUNCE_SERVER << 19) | (0 << 16) 
    150                         | AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT | 0x00); 
    151  
    152         request[1] =  0xFFFFFFFF; 
    153         resp = m_p1394Service->transactionBlock( m_nodeId, 
    154                                                        request, 
    155                                                        2, 
    156                                                                &resp_len ); 
    157 //      hexDump((unsigned char *)request,6*4); 
    158         if(resp) { 
    159                 char *buffer=(char *)&resp[1]; 
    160                 resp[resp_len-1]=0; 
    161                 xmlDescription=buffer; 
    162 //              hexDump((unsigned char *)resp,6*4); 
    163         } 
    164 */ 
    165         return true; 
     140    return false; 
    166141} 
    167142 
     
    212187    debugOutput(DEBUG_LEVEL_NORMAL, "Node              :  %d\n", m_nodeId); 
    213188    debugOutput(DEBUG_LEVEL_NORMAL, "GUID              :  0x%016llX\n", m_configRom->getGuid()); 
    214     debugOutput(DEBUG_LEVEL_NORMAL, "AVC test response :  %s\n", xmlDescription.c_str()); 
    215189    debugOutput(DEBUG_LEVEL_NORMAL, "\n" ); 
    216190} 
     
    434408        // write value of ISO_CHANNEL register 
    435409        reg_isoch=isochannel; 
    436         if(!writeReg(BOUNCE_REGISTER_TX_ISOCHANNEL, reg_isoch)) { 
     410        if(!writeReg(BOUNCE_REGISTER_RX_ISOCHANNEL, reg_isoch)) { 
    437411            debugError("Could not write ISO_CHANNEL register\n"); 
    438412            p->setChannel(-1); 
     
    451425bool 
    452426BounceDevice::stopStreamByIndex(int i) { 
    453  
    454         return false; 
     427    if (i<(int)m_receiveProcessors.size()) { 
     428        int n=i; 
     429        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
     430        unsigned int isochannel=p->getChannel(); 
     431         
     432        fb_quadlet_t reg_isoch; 
     433        // check value of ISO_CHANNEL register 
     434        if(!readReg(BOUNCE_REGISTER_TX_ISOCHANNEL, &reg_isoch)) { 
     435            debugError("Could not read ISO_CHANNEL register\n"); 
     436            return false; 
     437        } 
     438        if(reg_isoch != isochannel) { 
     439            debugError("ISO_CHANNEL register != 0x%08X (=0x%08X)\n", isochannel, reg_isoch); 
     440            return false; 
     441        } 
     442         
     443        // write value of ISO_CHANNEL register 
     444        reg_isoch=0xFFFFFFFFUL; 
     445        if(!writeReg(BOUNCE_REGISTER_TX_ISOCHANNEL, reg_isoch)) { 
     446            debugError("Could not write ISO_CHANNEL register" ); 
     447            return false; 
     448        } 
     449         
     450        // deallocate ISO channel 
     451        if(!deallocateIsoChannel(isochannel)) { 
     452            debugError("Could not deallocate iso channel for SP\n",i); 
     453            return false; 
     454        } 
     455         
     456        p->setChannel(-1); 
     457        return true; 
     458         
     459    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 
     460        int n=i-m_receiveProcessors.size(); 
     461        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
     462         
     463        unsigned int isochannel=p->getChannel(); 
     464         
     465        fb_quadlet_t reg_isoch; 
     466        // check value of ISO_CHANNEL register 
     467        if(!readReg(BOUNCE_REGISTER_RX_ISOCHANNEL, &reg_isoch)) { 
     468            debugError("Could not read ISO_CHANNEL register\n"); 
     469            return false; 
     470        } 
     471        if(reg_isoch != isochannel) { 
     472            debugError("ISO_CHANNEL register != 0x%08X (=0x%08X)\n", isochannel, reg_isoch); 
     473            return false; 
     474        } 
     475         
     476        // write value of ISO_CHANNEL register 
     477        reg_isoch=0xFFFFFFFFUL; 
     478        if(!writeReg(BOUNCE_REGISTER_RX_ISOCHANNEL, reg_isoch)) { 
     479            debugError("Could not write ISO_CHANNEL register\n"); 
     480            return false; 
     481        } 
     482         
     483        // deallocate ISO channel 
     484        if(!deallocateIsoChannel(isochannel)) { 
     485            debugError("Could not deallocate iso channel for SP (%d)\n",i); 
     486            return false; 
     487        } 
     488         
     489        p->setChannel(-1); 
     490        return true; 
     491    } 
     492     
     493    debugError("SP index %d out of range!\n",i); 
     494    return false; 
    455495} 
    456496 
  • branches/streaming-rework/src/bounce/bounce_avdevice.h

    r420 r424  
    5151// struct to define the supported devices 
    5252struct VendorModelEntry { 
    53     unsigned int vendor_id; 
    54     unsigned int model_id; 
    55     unsigned int unit_specifier_id; 
     53    uint32_t vendor_id; 
     54    uint32_t model_id; 
     55    uint32_t unit_specifier_id; 
    5656    char *vendor_name; 
    5757    char *model_name; 
     
    6969 
    7070    static bool probe( ConfigRom& configRom ); 
    71     virtual bool discover(); 
    72     virtual ConfigRom& getConfigRom() const; 
     71    bool discover(); 
     72    ConfigRom& getConfigRom() const; 
    7373     
    74     virtual bool addXmlDescription( xmlNodePtr deviceNode ); 
     74    bool addXmlDescription( xmlNodePtr deviceNode ); 
    7575     
    76     virtual bool setSamplingFrequency( ESamplingFrequency samplingFrequency ); 
    77        virtual int getSamplingFrequency( ); 
     76    bool setSamplingFrequency( ESamplingFrequency samplingFrequency ); 
     77    int getSamplingFrequency( ); 
    7878     
    79        virtual bool prepare(); 
     79    bool prepare(); 
    8080    bool lock(); 
    8181    bool unlock(); 
    82          
    83        virtual int getStreamCount(); 
    84          
    85        virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i); 
    86          
     82 
     83    int getStreamCount(); 
     84 
     85    Streaming::StreamProcessor *getStreamProcessorByIndex(int i); 
     86 
    8787    bool startStreamByIndex(int i); 
    8888    bool stopStreamByIndex(int i); 
    8989     
    90     virtual void showDevice() const; 
    91     virtual bool setId(unsigned int id); 
     90    void showDevice() const; 
     91    bool setId(unsigned int id); 
    9292 
    9393protected: 
     
    9797    int              m_verboseLevel; 
    9898 
    99 private: 
    10099        std::string xmlDescription; 
    101100 
     
    117116    int allocateIsoChannel(unsigned int packet_size); 
    118117    bool deallocateIsoChannel(int channel); 
    119      
    120 private: // I/O helpers 
     118 
     119protected: // I/O helpers 
    121120    // quadlet read/write routines 
    122121    bool readReg(fb_nodeaddr_t, fb_quadlet_t *); 
  • branches/streaming-rework/src/bounce/bounce_slave_avdevice.cpp

    r422 r424  
    2626 * 
    2727 */ 
    28  
    29 #include "BounceSlaveDevice.h" 
     28#include "libieee1394/configrom.h" 
     29#include "libieee1394/ieee1394service.h" 
     30 
     31#include "bounce_slave_avdevice.h" 
     32#include "libfreebob/freebob_bounce.h" 
     33 
     34#include <libraw1394/raw1394.h> 
     35#include <libavc1394/rom1394.h> 
    3036 
    3137namespace Bounce { 
    3238 
    33 IMPL_DEBUG_MODULE( BounceSlaveDevice, BounceSlaveDevice, DEBUG_LEVEL_NORMAL ); 
    34  
    35 BounceSlaveDevice::BounceSlaveDevice() { 
    36  
     39static VendorModelEntry supportedDeviceList[] = 
     40
     41  //{vendor_id, model_id, unit_specifier_id, vendor_name, model_name}, 
     42    {0x0B0001, 0x0B0001, 0x0B0001, "FreeBoB", "Bounce Slave"}, 
     43}; 
     44 
     45IMPL_DEBUG_MODULE( BounceSlaveDevice, BounceSlaveDevice, DEBUG_LEVEL_VERBOSE ); 
     46 
     47BounceSlaveDevice::BounceSlaveDevice( std::auto_ptr< ConfigRom >( configRom ), 
     48                            Ieee1394Service& ieee1394service, 
     49                            int verboseLevel ) 
     50    : BounceDevice( configRom, 
     51                    ieee1394service, 
     52                    ieee1394service.getLocalNodeId(), 
     53//                     verboseLevel ) 
     54                    DEBUG_LEVEL_VERBOSE ) 
     55
     56    addOption(Util::OptionContainer::Option("isoTimeoutSecs",(int64_t)120)); 
    3757} 
    3858 
     
    4161} 
    4262 
     63bool 
     64BounceSlaveDevice::probe( ConfigRom& configRom ) 
     65{ 
     66    // we are always capable of constructing a slave device 
     67    return true; 
     68} 
     69 
     70bool 
     71BounceSlaveDevice::discover() 
     72{ 
     73    m_model = &(supportedDeviceList[0]); 
     74    if (m_model != NULL) { 
     75        debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
     76                m_model->vendor_name, m_model->model_name); 
     77        return true; 
     78    } 
     79    return false; 
     80} 
     81 
     82bool BounceSlaveDevice::initMemSpace() { 
     83    debugOutput(DEBUG_LEVEL_VERBOSE, "Initializing memory space...\n"); 
     84    fb_quadlet_t result=0xFFFFFFFFLU; 
     85     
     86    // initialize the ISO channel registers 
     87    // this will write to our own registers 
     88    if (!writeReg(BOUNCE_REGISTER_TX_ISOCHANNEL, result)) { 
     89        debugError("Could not initalize ISO channel register for TX\n"); 
     90        return false; 
     91    } 
     92    if (!writeReg(BOUNCE_REGISTER_RX_ISOCHANNEL, result)) { 
     93        debugError("Could not initalize ISO channel register for TX\n"); 
     94        return false; 
     95    } 
     96     
     97    // set everything such that we can be discovered 
     98    m_original_config_rom=save_config_rom( m_p1394Service->getHandle() ); 
     99     
     100    if ( init_config_rom( m_p1394Service->getHandle() ) < 0 ) { 
     101        debugError("Could not initalize local config rom\n"); 
     102        return false; 
     103    } 
     104     
     105    // refresh our config rom cache 
     106    if ( !m_configRom->initialize() ) { 
     107        // \todo If a PHY on the bus is in power safe mode then 
     108        // the config rom is missing. So this might be just 
     109        // such this case and we can safely skip it. But it might 
     110        // be there is a real software problem on our side. 
     111        // This should be handled more carefuly. 
     112        debugError( "Could not reread config rom from device (node id %d).\n", 
     113                     m_nodeId ); 
     114        return false; 
     115    } 
     116    return true; 
     117} 
     118 
     119bool BounceSlaveDevice::restoreMemSpace() { 
     120    debugOutput(DEBUG_LEVEL_VERBOSE, "Restoring memory space...\n"); 
     121    restore_config_rom( m_p1394Service->getHandle(), m_original_config_rom); 
     122    return true; 
     123} 
     124 
     125bool 
     126BounceSlaveDevice::lock() { 
     127    debugOutput(DEBUG_LEVEL_VERBOSE, "Locking %s %s at node %d\n",  
     128        m_model->vendor_name, m_model->model_name, m_nodeId); 
     129     
     130    // get a notifier to handle device notifications 
     131    nodeaddr_t notify_address; 
     132    notify_address = m_p1394Service->findFreeARMBlock( 
     133                        BOUNCE_REGISTER_BASE, 
     134                        BOUNCE_REGISTER_LENGTH, 
     135                        BOUNCE_REGISTER_LENGTH); 
     136     
     137    if (notify_address == 0xFFFFFFFFFFFFFFFFLLU) { 
     138        debugError("Could not find free ARM block for notification\n"); 
     139        return false; 
     140    } 
     141     
     142    m_Notifier=new BounceSlaveDevice::BounceSlaveNotifier(this, notify_address); 
     143     
     144    if(!m_Notifier) { 
     145        debugError("Could not allocate notifier\n"); 
     146        return false; 
     147    } 
     148     
     149    if (!m_p1394Service->registerARMHandler(m_Notifier)) { 
     150        debugError("Could not register notifier\n"); 
     151        delete m_Notifier; 
     152        m_Notifier=NULL; 
     153        return false; 
     154    } 
     155     
     156    // (re)initialize the memory space 
     157    if (!initMemSpace()) { 
     158        debugError("Could not initialize memory space\n"); 
     159        return false; 
     160    } 
     161     
     162    return true; 
     163} 
     164 
     165bool 
     166BounceSlaveDevice::unlock() { 
     167    // (re)initialize the memory space 
     168    if (!restoreMemSpace()) { 
     169        debugError("Could not restore memory space\n"); 
     170        return false; 
     171    } 
     172    m_p1394Service->unregisterARMHandler(m_Notifier); 
     173    delete m_Notifier; 
     174    m_Notifier=NULL; 
     175 
     176    return true; 
     177} 
     178 
     179bool 
     180BounceSlaveDevice::prepare() { 
     181    // snooping does not make sense for a slave device 
     182    setOption("snoopMode", false); 
     183     
     184    // prepare the base class 
     185    // FIXME: when doing proper discovery this won't work anymore 
     186    //        as it relies on a completely symmetric transmit/receive 
     187    if(!BounceDevice::prepare()) { 
     188        debugError("Base class preparation failed\n"); 
     189        return false; 
     190    } 
     191     
     192    // do any customisations here 
     193     
     194    return true; 
     195} 
     196 
     197// this has to wait until the ISO channel numbers are written 
     198bool 
     199BounceSlaveDevice::startStreamByIndex(int i) { 
     200     
     201    if (i<(int)m_receiveProcessors.size()) { 
     202        int n=i; 
     203        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
     204         
     205        // the other side sends on this channel 
     206        nodeaddr_t iso_channel_offset = BOUNCE_REGISTER_RX_ISOCHANNEL; 
     207        iso_channel_offset += ((unsigned)n)*4; 
     208         
     209        if (!waitForRegisterNotEqualTo(iso_channel_offset, 0xFFFFFFFFLU)) { 
     210            debugError("Timeout waiting for stream %d to get an ISO channel\n",i); 
     211            return false; 
     212        } 
     213         
     214        fb_quadlet_t result; 
     215        // this will read from our own registers 
     216        if (!readReg(iso_channel_offset, &result)) { 
     217            debugError("Could not read ISO channel register for stream %d\n",i); 
     218            return false; 
     219        } 
     220         
     221        // set ISO channel 
     222        p->setChannel(result); 
     223 
     224        return true; 
     225         
     226    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 
     227        int n=i-m_receiveProcessors.size(); 
     228        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
     229         
     230        // the other side sends on this channel 
     231        nodeaddr_t iso_channel_offset = BOUNCE_REGISTER_TX_ISOCHANNEL; 
     232        iso_channel_offset += ((unsigned)n)*4; 
     233         
     234        if (!waitForRegisterNotEqualTo(iso_channel_offset, 0xFFFFFFFF)) { 
     235            debugError("Timeout waiting for stream %d to get an ISO channel\n",i); 
     236            return false; 
     237        } 
     238         
     239        fb_quadlet_t result; 
     240        // this will read from our own registers 
     241        if (!readReg(iso_channel_offset, &result)) { 
     242            debugError("Could not read ISO channel register for stream %d\n",i); 
     243            return false; 
     244        } 
     245         
     246        // set ISO channel 
     247        p->setChannel(result); 
     248 
     249        return true; 
     250 
     251    } 
     252     
     253    debugError("SP index %d out of range!\n",i); 
     254     
     255    return false; 
     256} 
     257 
     258bool 
     259BounceSlaveDevice::stopStreamByIndex(int i) { 
     260    // nothing special to do I guess... 
     261    return false; 
     262} 
     263 
     264// helpers 
     265bool 
     266BounceSlaveDevice::waitForRegisterNotEqualTo(nodeaddr_t offset, fb_quadlet_t v) { 
     267    debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for StreamProcessor streams to start running...\n"); 
     268    // we have to wait until all streamprocessors indicate that they are running 
     269    // i.e. that there is actually some data stream flowing 
     270    int timeoutSecs=120; 
     271    if(!getOption("isoTimeoutSecs", timeoutSecs)) { 
     272        debugWarning("Could not retrieve isoTimeoutSecs parameter, defauling to 120secs\n"); 
     273    } 
     274     
     275    int wait_cycles=timeoutSecs*10; // two seconds 
     276     
     277    fb_quadlet_t reg=v; 
     278     
     279    while ((v == reg) && wait_cycles) { 
     280        wait_cycles--; 
     281        if (!readReg(offset,&reg)) { 
     282            debugError("Could not read register\n"); 
     283            return false; 
     284        } 
     285        usleep(100000); 
     286    } 
     287 
     288    if(!wait_cycles) { // timout has occurred 
     289        return false; 
     290    } 
     291     
     292    return true; 
     293} 
     294 
     295// configrom helpers 
     296// FIXME: should be changed into a better framework 
     297 
     298 
     299struct BounceSlaveDevice::configrom_backup  
     300BounceSlaveDevice::save_config_rom(raw1394handle_t handle) 
     301{ 
     302    int retval; 
     303    struct configrom_backup tmp; 
     304    /* get the current rom image */ 
     305    retval=raw1394_get_config_rom(handle, tmp.rom, 0x100, &tmp.rom_size, &tmp.rom_version); 
     306//      tmp.rom_size=rom1394_get_size(tmp.rom); 
     307//     printf("save_config_rom get_config_rom returned %d, romsize %d, rom_version %d:\n",retval,tmp.rom_size,tmp.rom_version); 
     308 
     309    return tmp; 
     310} 
     311 
     312int  
     313BounceSlaveDevice::restore_config_rom(raw1394handle_t handle, struct BounceSlaveDevice::configrom_backup old) 
     314{ 
     315    int retval; 
     316//     int i; 
     317     
     318    quadlet_t current_rom[0x100]; 
     319    size_t current_rom_size; 
     320    unsigned char current_rom_version; 
     321 
     322    retval=raw1394_get_config_rom(handle, current_rom, 0x100, &current_rom_size, &current_rom_version); 
     323//     printf("restore_config_rom get_config_rom returned %d, romsize %d, rom_version %d:\n",retval,current_rom_size,current_rom_version); 
     324 
     325//     printf("restore_config_rom restoring to romsize %d, rom_version %d:\n",old.rom_size,old.rom_version); 
     326 
     327    retval = raw1394_update_config_rom(handle, old.rom, old.rom_size, current_rom_version); 
     328//     printf("restore_config_rom update_config_rom returned %d\n",retval); 
     329 
     330    /* get the current rom image */ 
     331    retval=raw1394_get_config_rom(handle, current_rom, 0x100, &current_rom_size, &current_rom_version); 
     332    current_rom_size = rom1394_get_size(current_rom); 
     333//     printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,current_rom_size,current_rom_version); 
     334//     for (i = 0; i < current_rom_size; i++) 
     335//     { 
     336//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
     337//         printf(" %08x", ntohl(current_rom[i])); 
     338//     } 
     339//     printf("\n"); 
     340 
     341    return retval; 
     342} 
     343 
     344int  
     345BounceSlaveDevice::init_config_rom(raw1394handle_t handle) 
     346{ 
     347    int retval, i; 
     348    quadlet_t rom[0x100]; 
     349    size_t rom_size; 
     350    unsigned char rom_version; 
     351    rom1394_directory dir; 
     352    char *leaf; 
     353     
     354    /* get the current rom image */ 
     355    retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); 
     356    rom_size = rom1394_get_size(rom); 
     357//     printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); 
     358//     for (i = 0; i < rom_size; i++) 
     359//     { 
     360//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
     361//         printf(" %08x", ntohl(rom[i])); 
     362//     } 
     363//     printf("\n"); 
     364     
     365    /* get the local directory */ 
     366    rom1394_get_directory( handle, raw1394_get_local_id(handle) & 0x3f, &dir); 
     367     
     368    /* change the vendor description for kicks */ 
     369    i = strlen(dir.textual_leafs[0]); 
     370    strncpy(dir.textual_leafs[0], FREEBOB_BOUNCE_SERVER_VENDORNAME "                                          ", i); 
     371     
     372    dir.vendor_id=FREEBOB_BOUNCE_SERVER_VENDORID; 
     373    dir.model_id=FREEBOB_BOUNCE_SERVER_MODELID; 
     374     
     375    /* update the rom */ 
     376    retval = rom1394_set_directory(rom, &dir); 
     377//     printf("rom1394_set_directory returned %d, romsize %d:",retval,rom_size); 
     378//     for (i = 0; i < rom_size; i++) 
     379//     { 
     380//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
     381//         printf(" %08x", ntohl(rom[i])); 
     382//     } 
     383//     printf("\n"); 
     384     
     385    /* free the allocated mem for the textual leaves */ 
     386    rom1394_free_directory( &dir); 
     387     
     388    /* add an AV/C unit directory */ 
     389    dir.unit_spec_id    = FREEBOB_BOUNCE_SERVER_SPECID; 
     390    dir.unit_sw_version = 0x00010001; 
     391    leaf = FREEBOB_BOUNCE_SERVER_MODELNAME; 
     392    dir.nr_textual_leafs = 1; 
     393    dir.textual_leafs = &leaf; 
     394     
     395    /* manipulate the rom */ 
     396    retval = rom1394_add_unit( rom, &dir); 
     397     
     398    /* get the computed size of the rom image */ 
     399    rom_size = rom1394_get_size(rom); 
     400     
     401//     printf("rom1394_add_unit_directory returned %d, romsize %d:",retval,rom_size); 
     402//     for (i = 0; i < rom_size; i++) 
     403//     { 
     404//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
     405//         printf(" %08x", ntohl(rom[i])); 
     406//     } 
     407//     printf("\n"); 
     408//      
     409    /* convert computed rom size from quadlets to bytes before update */ 
     410    rom_size *= sizeof(quadlet_t); 
     411    retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version); 
     412//     printf("update_config_rom returned %d\n",retval); 
     413     
     414    retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); 
     415//     printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); 
     416//     for (i = 0; i < rom_size; i++) 
     417//     { 
     418//         if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); 
     419//         printf(" %08x", ntohl(rom[i])); 
     420//     } 
     421//     printf("\n"); 
     422     
     423//      printf("You need to reload your ieee1394 modules to reset the rom.\n"); 
     424     
     425    return 0; 
     426} 
     427 
     428 
     429// the notifier 
     430 
     431BounceSlaveDevice::BounceSlaveNotifier::BounceSlaveNotifier(BounceSlaveDevice *d, nodeaddr_t start) 
     432 : ARMHandler(start, BOUNCE_REGISTER_LENGTH,  
     433              RAW1394_ARM_READ | RAW1394_ARM_WRITE, // allowed operations 
     434              0, //RAW1394_ARM_READ | RAW1394_ARM_WRITE, // operations to be notified of 
     435              0)                                    // operations that are replied to by us (instead of kernel) 
     436 , m_bounceslavedevice(d) 
     437{ 
     438 
     439} 
     440 
     441BounceSlaveDevice::BounceSlaveNotifier::~BounceSlaveNotifier()  
     442{ 
     443 
     444} 
     445 
    43446} // end of namespace Bounce 
  • branches/streaming-rework/src/bounce/bounce_slave_avdevice.h

    r422 r424  
    2929#define __FREEBOB_BOUNCESLAVEDEVICE__ 
    3030 
    31 #include "../debugmodule/debugmodule.h" 
     31#include "debugmodule/debugmodule.h" 
     32#include "bounce_avdevice.h" 
    3233 
    3334namespace Bounce { 
    3435 
    35 class BounceSlaveDevice
    36  
     36class BounceSlaveDevice : public BounceDevice
     37    class BounceSlaveNotifier; 
    3738public: 
    3839 
    39         BounceSlaveDevice(); 
    40         virtual ~BounceSlaveDevice(); 
     40    BounceSlaveDevice( std::auto_ptr<ConfigRom>( configRom ), 
     41          Ieee1394Service& ieee1394Service, 
     42          int verboseLevel ); 
     43    virtual ~BounceSlaveDevice(); 
     44     
     45    static bool probe( ConfigRom& configRom ); 
     46    bool discover(); 
     47    bool prepare(); 
     48    bool lock(); 
     49    bool unlock(); 
     50     
     51    bool startStreamByIndex(int i); 
     52    bool stopStreamByIndex(int i); 
     53     
    4154 
    4255protected: 
    4356    DECLARE_DEBUG_MODULE; 
     57private: 
     58    bool waitForRegisterNotEqualTo(nodeaddr_t offset, fb_quadlet_t v); 
     59    bool initMemSpace(); 
     60    bool restoreMemSpace(); 
     61     
     62private: // configrom shit 
    4463 
     64    struct configrom_backup { 
     65        quadlet_t rom[0x100]; 
     66        size_t rom_size; 
     67        unsigned char rom_version; 
     68    }; 
     69    struct configrom_backup m_original_config_rom; 
     70     
     71    struct configrom_backup  
     72        save_config_rom(raw1394handle_t handle); 
     73    int restore_config_rom(raw1394handle_t handle, struct configrom_backup old); 
     74    int init_config_rom(raw1394handle_t handle); 
     75     
     76private: 
     77    BounceSlaveNotifier *m_Notifier; 
     78    /** 
     79     * this class reacts on the ohter side writing to the  
     80     * hosts address space 
     81     */ 
     82    class BounceSlaveNotifier : public ARMHandler 
     83    { 
     84    public: 
     85        BounceSlaveNotifier(BounceSlaveDevice *, nodeaddr_t start); 
     86        virtual ~BounceSlaveNotifier(); 
     87         
     88    private: 
     89        BounceSlaveDevice *m_bounceslavedevice; 
     90    }; 
    4591}; 
    4692 
  • branches/streaming-rework/src/devicemanager.cpp

    r419 r424  
    4343#ifdef ENABLE_BOUNCE 
    4444    #include "bounce/bounce_avdevice.h" 
     45    #include "bounce/bounce_slave_avdevice.h" 
    4546#endif 
    4647 
     
    6869    : m_1394Service( 0 ) 
    6970{ 
    70  
     71    addOption(Util::OptionContainer::Option("slaveMode",false)); 
     72    addOption(Util::OptionContainer::Option("snoopMode",false)); 
    7173} 
    7274 
     
    105107DeviceManager::discover( int verboseLevel ) 
    106108{ 
     109    bool slaveMode=false; 
     110    if(!getOption("slaveMode", slaveMode)) { 
     111        debugWarning("Could not retrieve slaveMode parameter, defauling to false\n"); 
     112    } 
     113    bool snoopMode=false; 
     114    if(!getOption("snoopMode", snoopMode)) { 
     115        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     116    } 
    107117 
    108118    setDebugLevel( verboseLevel ); 
     
    117127    m_avDevices.clear(); 
    118128 
    119     for ( fb_nodeid_t nodeId = 0; 
    120           nodeId < m_1394Service->getNodeCount(); 
    121           ++nodeId ) 
    122     { 
    123         debugOutput( DEBUG_LEVEL_VERBOSE, "Probing node %d...\n", nodeId ); 
    124  
    125         if (nodeId == m_1394Service->getLocalNodeId()) { 
    126             debugOutput( DEBUG_LEVEL_VERBOSE, "Skipping local node (%d)...\n", nodeId ); 
    127             continue; 
    128         } 
     129    if (!slaveMode) { 
     130        for ( fb_nodeid_t nodeId = 0; 
     131              nodeId < m_1394Service->getNodeCount(); 
     132              ++nodeId ) 
     133        { 
     134            debugOutput( DEBUG_LEVEL_VERBOSE, "Probing node %d...\n", nodeId ); 
     135     
     136            if (nodeId == m_1394Service->getLocalNodeId()) { 
     137                debugOutput( DEBUG_LEVEL_VERBOSE, "Skipping local node (%d)...\n", nodeId ); 
     138                continue; 
     139            } 
     140     
     141            std::auto_ptr<ConfigRom> configRom = 
     142                std::auto_ptr<ConfigRom>( new ConfigRom( *m_1394Service, 
     143                                                         nodeId ) ); 
     144            if ( !configRom->initialize() ) { 
     145                // \todo If a PHY on the bus is in power safe mode then 
     146                // the config rom is missing. So this might be just 
     147                // such this case and we can safely skip it. But it might 
     148                // be there is a real software problem on our side. 
     149                // This should be handled more carefuly. 
     150                debugOutput( DEBUG_LEVEL_NORMAL, 
     151                             "Could not read config rom from device (node id %d). " 
     152                             "Skip device discovering for this node\n", 
     153                             nodeId ); 
     154                continue; 
     155            } 
     156     
     157            IAvDevice* avDevice = getDriverForDevice( configRom, 
     158                                                      nodeId, 
     159                                                      verboseLevel ); 
     160            if ( avDevice ) { 
     161                debugOutput( DEBUG_LEVEL_NORMAL, 
     162                             "discover: driver found for device %d\n", 
     163                             nodeId ); 
     164 
     165                if ( !avDevice->discover() ) { 
     166                    debugError( "discover: could not discover device\n" ); 
     167                    delete avDevice; 
     168                    continue; 
     169                } 
     170 
     171                if ( !avDevice->setId( m_avDevices.size() ) ) { 
     172                    debugError( "setting Id failed\n" ); 
     173                } 
     174                 
     175                if (snoopMode) { 
     176                    debugOutput( DEBUG_LEVEL_VERBOSE, 
     177                                 "Enabling snoop mode on node %d...\n", nodeId ); 
     178 
     179                    if(!avDevice->setOption("snoopMode", snoopMode)) { 
     180                        debugWarning("Could not set snoop mode for device on node %d\n",nodeId); 
     181                        delete avDevice; 
     182                        continue; 
     183                    } 
     184                } 
     185                 
     186                avDevice->setVerboseLevel( verboseLevel ); 
     187                 
     188                if ( verboseLevel ) { 
     189                    avDevice->showDevice(); 
     190                } 
     191 
     192                m_avDevices.push_back( avDevice ); 
     193            } 
     194        } 
     195        return true; 
     196         
     197    } else { // slave mode 
     198        fb_nodeid_t nodeId = m_1394Service->getLocalNodeId(); 
     199        debugOutput( DEBUG_LEVEL_VERBOSE, "Starting in slave mode on node %d...\n", nodeId ); 
    129200 
    130201        std::auto_ptr<ConfigRom> configRom = 
     
    141212                         "Skip device discovering for this node\n", 
    142213                         nodeId ); 
    143             continue; 
    144         } 
    145  
    146         IAvDevice* avDevice = getDriverForDevice( configRom, 
    147                                                   nodeId, 
    148                                                   verboseLevel ); 
     214            return false; 
     215        } 
     216 
     217        IAvDevice* avDevice = getSlaveDriver( configRom, verboseLevel ); 
    149218        if ( avDevice ) { 
    150219            debugOutput( DEBUG_LEVEL_NORMAL, 
     
    155224                debugError( "discover: could not discover device\n" ); 
    156225                delete avDevice; 
    157                 continue; 
     226                return false; 
    158227            } 
    159228 
     
    167236            m_avDevices.push_back( avDevice ); 
    168237        } 
    169     } 
    170  
    171     return true; 
     238     
     239        return true; 
     240    } 
    172241} 
    173242 
     
    178247{ 
    179248#ifdef ENABLE_BEBOB 
     249    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying BeBoB...\n" ); 
    180250    if ( BeBoB::AvDevice::probe( *configRom.get() ) ) { 
    181251        return new BeBoB::AvDevice( configRom, *m_1394Service, id, level ); 
     
    184254 
    185255#ifdef ENABLE_BEBOB 
     256    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying M-Audio...\n" ); 
    186257    if ( MAudio::AvDevice::probe( *configRom.get() ) ) { 
    187258        return new MAudio::AvDevice( configRom, *m_1394Service, id, level ); 
     
    190261 
    191262#ifdef ENABLE_MOTU 
     263    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Motu...\n" ); 
    192264    if ( Motu::MotuDevice::probe( *configRom.get() ) ) { 
    193265        return new Motu::MotuDevice( configRom, *m_1394Service, id, level ); 
     
    196268 
    197269#ifdef ENABLE_DICE 
     270    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Dice...\n" ); 
    198271    if ( Dice::DiceAvDevice::probe( *configRom.get() ) ) { 
    199272        return new Dice::DiceAvDevice( configRom, *m_1394Service, id, level ); 
     
    202275 
    203276#ifdef ENABLE_METRIC_HALO 
     277    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Metric Halo...\n" ); 
    204278    if ( MetricHalo::MHAvDevice::probe( *configRom.get() ) ) { 
    205279        return new MetricHalo::MHAvDevice( configRom, *m_1394Service, id, level ); 
     
    208282 
    209283#ifdef ENABLE_RME 
     284    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying RME...\n" ); 
    210285    if ( Rme::RmeDevice::probe( *configRom.get() ) ) { 
    211286        return new Rme::RmeDevice( configRom, *m_1394Service, id, level ); 
     
    214289 
    215290#ifdef ENABLE_BOUNCE 
     291    debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Bounce...\n" ); 
    216292    if ( Bounce::BounceDevice::probe( *configRom.get() ) ) { 
    217293        return new Bounce::BounceDevice( configRom, *m_1394Service, id, level ); 
     294    } 
     295#endif 
     296 
     297    return 0; 
     298} 
     299 
     300IAvDevice* 
     301DeviceManager::getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ), int level ) 
     302{ 
     303 
     304#ifdef ENABLE_BOUNCE 
     305    if ( Bounce::BounceSlaveDevice::probe( *configRom.get() ) ) { 
     306        return new Bounce::BounceSlaveDevice( configRom, *m_1394Service, level ); 
    218307    } 
    219308#endif 
     
    300389DeviceManager::getSyncSource() { 
    301390    IAvDevice* device = getAvDeviceByIndex(0); 
    302     return device->getStreamProcessorByIndex(0); 
    303      
     391 
     392    bool slaveMode=false; 
     393    if(!getOption("slaveMode", slaveMode)) { 
     394        debugWarning("Could not retrieve slaveMode parameter, defauling to false\n"); 
     395    } 
     396    
    304397    #warning TEST CODE FOR BOUNCE DEVICE !! 
    305     if (device->getConfigRom().getNodeId()==0) { 
     398    // this makes the bounce slave use the xmit SP as sync source 
     399    if (slaveMode) { 
     400        return device->getStreamProcessorByIndex(1); 
     401    } else { 
    306402        return device->getStreamProcessorByIndex(0); 
    307     } else { 
    308         return device->getStreamProcessorByIndex(1); 
    309403    } 
    310404     
  • branches/streaming-rework/src/devicemanager.h

    r419 r424  
    2525 
    2626#include "libfreebob/xmlparser.h" 
     27#include "libutil/OptionContainer.h" 
    2728 
    2829#include <glibmm/ustring.h> 
     
    4243 
    4344 
    44 class DeviceManager
     45class DeviceManager : public Util::OptionContainer
    4546 public: 
    4647    DeviceManager(); 
     
    7172                                   int id, 
    7273                                   int level ); 
     74    IAvDevice* getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ), 
     75                                   int level ); 
    7376 
    7477protected: 
  • branches/streaming-rework/src/freebob_streaming.cpp

    r419 r424  
    109109                return 0; 
    110110        } 
    111  
     111         
     112        // set slave mode option 
     113        bool slaveMode=(dev->options.slave_mode != 0); 
     114        debugOutput(DEBUG_LEVEL_VERBOSE, "setting slave mode to %d\n", slaveMode); 
     115        if(!dev->m_deviceManager->setOption("slaveMode", slaveMode)) { 
     116                debugWarning("Failed to set slave mode option\n"); 
     117        } 
     118        // set snoop mode option 
     119        bool snoopMode=(dev->options.snoop_mode != 0); 
     120        debugOutput(DEBUG_LEVEL_VERBOSE, "setting snoop mode to %d\n", snoopMode); 
     121        if(!dev->m_deviceManager->setOption("snoopMode", snoopMode)) { 
     122                debugWarning("Failed to set snoop mode option\n"); 
     123        } 
     124         
    112125        // discover the devices on the bus 
    113126        if(!dev->m_deviceManager->discover(DEBUG_LEVEL_NORMAL)) { 
    114127                debugFatal("Could not discover devices\n"); 
     128                delete dev->processorManager; 
     129                delete dev->m_deviceManager; 
     130                delete dev; 
     131                return 0; 
     132        } 
     133         
     134        // are there devices on the bus? 
     135        if(dev->m_deviceManager->getAvDeviceCount()==0) { 
     136                debugFatal("There are no devices on the bus\n"); 
    115137                delete dev->processorManager; 
    116138                delete dev->m_deviceManager; 
     
    177199 
    178200int freebob_streaming_prepare(freebob_device_t *dev) { 
    179         debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
    180          
    181         if (!dev->processorManager->prepare()) { 
     201    debugOutput(DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
     202         
     203    if (!dev->processorManager->prepare()) { 
    182204        debugFatal("Could not prepare streaming...\n"); 
    183205        return false; 
    184        
    185  
    186         return true; 
     206   
     207 
     208    return true; 
    187209} 
    188210 
  • branches/streaming-rework/src/iavdevice.h

    r420 r424  
    216216        virtual bool stopStreamByIndex(int i) = 0; 
    217217 
     218    /** 
     219     * set verbosity level 
     220     */ 
     221    virtual void setVerboseLevel(int l) {setDebugLevel(l);}; 
    218222}; 
    219223 
  • branches/streaming-rework/src/libieee1394/ieee1394service.cpp

    r415 r424  
    117117    m_default_arm_handler = raw1394_set_arm_tag_handler( m_resetHandle, 
    118118                                   this->armHandlerLowLevel ); 
     119     
    119120    startRHThread(); 
    120121 
  • branches/streaming-rework/src/libieee1394/ieee1394service.h

    r415 r424  
    2828#include "debugmodule/debugmodule.h" 
    2929 
     30#include "IEC61883.h" 
     31 
    3032#include <libraw1394/raw1394.h> 
    3133#include <pthread.h> 
     
    3537class ARMHandler; 
    3638 
    37 class Ieee1394Service
     39class Ieee1394Service : public IEC61883
    3840public: 
    3941    Ieee1394Service(); 
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp

    r419 r424  
    12111211        } 
    12121212 
    1213  
    1214         debugOutput( DEBUG_LEVEL_VERBOSE, "Prepared for:\n"); 
    1215         debugOutput( DEBUG_LEVEL_VERBOSE, " Samplerate: %d, DBS: %d, SYT: %d\n", 
    1216                      m_framerate,m_dimension,m_syt_interval); 
    1217         debugOutput( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n", 
    1218                      m_period,m_nb_buffers); 
    1219         debugOutput( DEBUG_LEVEL_VERBOSE, " Port: %d, Channel: %d\n", 
    1220                      m_port,m_channel); 
    1221        return true; 
     1213    debugOutput( DEBUG_LEVEL_VERBOSE, "Prepared for:\n"); 
     1214    debugOutput( DEBUG_LEVEL_VERBOSE, " Samplerate: %d, DBS: %d, SYT: %d\n", 
     1215             m_framerate,m_dimension,m_syt_interval); 
     1216    debugOutput( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n", 
     1217             m_period,m_nb_buffers); 
     1218    debugOutput( DEBUG_LEVEL_VERBOSE, " Port: %d, Channel: %d\n", 
     1219             m_port,m_channel); 
     1220     
     1221    return true; 
    12221222 
    12231223} 
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.h

    r419 r424  
    145145    int encodeSilencePortToMBLAEvents(AmdtpAudioPort *, quadlet_t *data, 
    146146                                unsigned int offset, unsigned int nevents); 
    147  
     147    void updatePreparedState(); 
     148     
    148149    unsigned long m_last_timestamp; 
    149150 
     
    216217     
    217218    int decodeMBLAEventsToPort(AmdtpAudioPort *, quadlet_t *data, unsigned int offset, unsigned int nevents); 
     219    void updatePreparedState(); 
    218220 
    219221    int m_dimension; 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.cpp

    r419 r424  
    185185 
    186186bool StreamProcessor::isRunning() { 
    187        return m_running; 
     187    return m_running; 
    188188} 
    189189 
     
    215215 
    216216    m_disabled=false; 
    217      
    218217    return true; 
    219218} 
    220219 
    221220bool StreamProcessor::disable()  { 
    222      
    223221    m_disabled=true; 
    224  
    225     return true; 
    226  
     222    return true; 
    227223} 
    228224 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.h

    r419 r424  
    3737 
    3838#include "libutil/StreamStatistics.h" 
    39  
    4039#include "libutil/TimestampedBuffer.h" 
     40#include "libutil/OptionContainer.h" 
    4141 
    4242namespace Streaming { 
     
    5454class StreamProcessor : public IsoStream,  
    5555                        public PortManager,  
    56                         public Util::TimestampedBufferClient { 
     56                        public Util::TimestampedBufferClient, 
     57                        public Util::OptionContainer { 
    5758 
    5859    friend class StreamProcessorManager; 
     
    112113    Util::TimestampedBuffer *m_data_buffer; 
    113114 
    114 protected: 
    115  
     115protected: // SPM related 
    116116    void setManager(StreamProcessorManager *manager) {m_manager=manager;}; 
    117117    void clearManager() {m_manager=0;}; 
    118  
     118     
     119protected: 
    119120    unsigned int m_nb_buffers; ///< cached from manager->getNbBuffers(), the number of periods to buffer 
    120121    unsigned int m_period; ///< cached from manager->getPeriod(), the period size 
  • branches/streaming-rework/src/libstreaming/StreamProcessorManager.cpp

    r419 r424  
    4848 
    4949StreamProcessorManager::StreamProcessorManager(unsigned int period, unsigned int nb_buffers) 
    50         : m_SyncSource(NULL), m_nb_buffers(nb_buffers), m_period(period), m_xruns(0),  
    51         m_isoManager(0), m_nbperiods(0) { 
    52  
     50    : m_is_slave( false ) 
     51    , m_SyncSource(NULL) 
     52    , m_nb_buffers(nb_buffers) 
     53    , m_period(period) 
     54    , m_xruns(0) 
     55    , m_isoManager(0) 
     56    , m_nbperiods(0) 
     57
     58    addOption(Util::OptionContainer::Option("slaveMode",false)); 
    5359} 
    5460 
     
    195201        debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n"); 
    196202         
    197         // if no sync source is set, select one here 
    198         if(m_SyncSource == NULL) { 
    199            debugWarning("Sync Source is not set. Defaulting to first StreamProcessor.\n"); 
    200         } 
    201          
    202         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    203                 it != m_ReceiveProcessors.end(); 
    204                 ++it ) { 
    205                         if(m_SyncSource == NULL) { 
    206                                 debugWarning(" => Sync Source is %p.\n", *it); 
    207                                 m_SyncSource = *it; 
    208                         } 
    209         } 
    210  
    211         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    212                 it != m_TransmitProcessors.end(); 
    213                 ++it ) { 
    214                         if(m_SyncSource == NULL) { 
    215                                 debugWarning(" => Sync Source is %p.\n", *it); 
    216                                 m_SyncSource = *it; 
    217                         } 
    218         } 
    219  
    220         // now do the actual preparation 
    221         debugOutput( DEBUG_LEVEL_VERBOSE, "Prepare Receive processors...\n"); 
    222         for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    223                 it != m_ReceiveProcessors.end(); 
    224                 ++it ) { 
    225                         if(!(*it)->setSyncSource(m_SyncSource)) { 
    226                                 debugFatal(  " could not set sync source (%p)...\n",(*it)); 
    227                                 return false; 
    228                         } 
    229                          
    230                         if(!(*it)->prepare()) { 
    231                                 debugFatal(  " could not prepare (%p)...\n",(*it)); 
    232                                 return false; 
    233                         } 
    234         } 
    235  
    236         debugOutput( DEBUG_LEVEL_VERBOSE, "Prepare Transmit processors...\n"); 
    237         for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    238                 it != m_TransmitProcessors.end(); 
    239                 ++it ) { 
    240                         if(!(*it)->setSyncSource(m_SyncSource)) { 
    241                                 debugFatal(  " could not set sync source (%p)...\n",(*it)); 
    242                                 return false; 
    243                         }                
    244                         if(!(*it)->prepare()) { 
    245                                 debugFatal( " could not prepare (%p)...\n",(*it)); 
    246                                 return false; 
    247                         } 
    248         } 
     203    m_is_slave=false; 
     204    if(!getOption("snoopMode", m_is_slave)) { 
     205        debugWarning("Could not retrieve slaveMode parameter, defauling to false\n"); 
     206    } 
     207 
     208    // if no sync source is set, select one here 
     209    if(m_SyncSource == NULL) { 
     210       debugWarning("Sync Source is not set. Defaulting to first StreamProcessor.\n"); 
     211    } 
     212 
     213    for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     214        it != m_ReceiveProcessors.end(); 
     215        ++it ) { 
     216            if(m_SyncSource == NULL) { 
     217                debugWarning(" => Sync Source is %p.\n", *it); 
     218                m_SyncSource = *it; 
     219            } 
     220    } 
     221     
     222    for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     223        it != m_TransmitProcessors.end(); 
     224        ++it ) { 
     225            if(m_SyncSource == NULL) { 
     226                debugWarning(" => Sync Source is %p.\n", *it); 
     227                m_SyncSource = *it; 
     228            } 
     229    } 
     230 
     231    // now do the actual preparation 
     232    debugOutput( DEBUG_LEVEL_VERBOSE, "Prepare Receive processors...\n"); 
     233    for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     234        it != m_ReceiveProcessors.end(); 
     235        ++it ) { 
     236         
     237        if(!(*it)->setSyncSource(m_SyncSource)) { 
     238            debugFatal(  " could not set sync source (%p)...\n",(*it)); 
     239            return false; 
     240        } 
     241 
     242        if(!(*it)->setOption("slaveMode", m_is_slave)) { 
     243            debugOutput(DEBUG_LEVEL_VERBOSE, " note: could not set slaveMode option for (%p)...\n",(*it)); 
     244        } 
     245 
     246        if(!(*it)->prepare()) { 
     247            debugFatal(  " could not prepare (%p)...\n",(*it)); 
     248            return false; 
     249        } 
     250    } 
     251 
     252    debugOutput( DEBUG_LEVEL_VERBOSE, "Prepare Transmit processors...\n"); 
     253    for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     254        it != m_TransmitProcessors.end(); 
     255        ++it ) { 
     256        if(!(*it)->setSyncSource(m_SyncSource)) { 
     257            debugFatal(  " could not set sync source (%p)...\n",(*it)); 
     258            return false; 
     259        } 
     260        if(!(*it)->setOption("slaveMode", m_is_slave)) { 
     261            debugOutput(DEBUG_LEVEL_VERBOSE, " note: could not set slaveMode option for (%p)...\n",(*it)); 
     262        } 
     263        if(!(*it)->prepare()) { 
     264            debugFatal( " could not prepare (%p)...\n",(*it)); 
     265            return false; 
     266        } 
     267    } 
    249268 
    250269    // if there are no stream processors registered,  
     
    818837        xmt_bf = (*it)->getBufferFill(); 
    819838    } 
    820     debugOutput( DEBUG_LEVEL_VERBOSE, "XF at %011llu ticks, RBF=%d, XBF=%d, SUM=%d...\n",  
     839    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "XF at %011llu ticks, RBF=%d, XBF=%d, SUM=%d...\n",  
    821840        m_time_of_transfer,rcv_bf,xmt_bf,rcv_bf+xmt_bf); 
    822841     
  • branches/streaming-rework/src/libstreaming/StreamProcessorManager.h

    r419 r424  
    2929#define __FREEBOB_STREAMPROCESSORMANAGER__ 
    3030 
    31 #include "../debugmodule/debugmodule.h" 
    32 #include "../libutil/Thread.h" 
     31#include "debugmodule/debugmodule.h" 
     32#include "libutil/Thread.h" 
     33#include "libutil/OptionContainer.h" 
    3334#include <semaphore.h> 
    3435#include "Port.h" 
     
    5051  
    5152*/ 
    52 class StreamProcessorManager { 
    53  
     53class StreamProcessorManager : public Util::OptionContainer { 
     54    friend class StreamProcessor; 
     55     
    5456public: 
    5557 
     
    108110    virtual void setVerboseLevel(int l); 
    109111    void dumpInfo(); 
    110      
     112 
     113private: // slaving support 
     114    bool m_is_slave; 
    111115     
    112116    // the sync source stuff 
     
    118122    StreamProcessor * getSyncSource(); 
    119123 
    120      
    121124protected: 
     125 
    122126    // thread sync primitives 
    123127    bool m_xrun_happened;  
  • branches/streaming-rework/src/Makefile.am

    r420 r424  
    3535    libieee1394/configrom.h libieee1394/csr1212.h \ 
    3636    libieee1394/ieee1394service.h libieee1394/ARMHandler.h \ 
     37    libieee1394/IEC61883.h \ 
    3738    debugmodule/debugmodule.h \ 
    3839        devicemanager.h fbtypes.h iavdevice.h threads.h bebob/bebob_avdevice.h \ 
    3940        bebob/bebob_avdevice_subunit.h bebob/bebob_avplug.h bebob/bebob_dl_bcd.h bebob/bebob_dl_codes.h \ 
    40         bebob/bebob_dl_mgr.h bebob/bebob_functionblock.h bounce/bounce_avdevice.h
     41        bebob/bebob_dl_mgr.h bebob/bebob_functionblock.h bounce/bounce_avdevice.h bounce/bounce_slave_avdevice.h
    4142        maudio/maudio_avdevice.h motu/motu_avdevice.h rme/rme_avdevice.h \ 
    4243        metrichalo/mh_avdevice.h dice/dice_avdevice.h \ 
     
    8384        libieee1394/csr1212.c \ 
    8485        libieee1394/ieee1394service.cpp \ 
     86        libieee1394/IEC61883.cpp \ 
    8587        libstreaming/cip.c \ 
    8688        libstreaming/IsoHandler.cpp \ 
     
    126128 
    127129bounce_src = \ 
    128         bounce/bounce_avdevice.cpp 
     130        bounce/bounce_avdevice.cpp \ 
     131        bounce/bounce_slave_avdevice.cpp 
    129132 
    130133metric_halo_src = \