Changeset 524

Show
Ignore:
Timestamp:
08/17/07 06:49:43 (17 years ago)
Author:
ppalmers
Message:

echo discovery works, audio I/O works, still some issues with midi and channel naming

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/echoaudio/src/bebob/bebob_avdevice.cpp

    r509 r524  
    9494} 
    9595 
     96AVC::Subunit*  
     97BeBoB::AvDevice::createSubunit(AVC::Unit& unit, 
     98                               AVC::ESubunitType type, 
     99                               AVC::subunit_t id )  
     100{ 
     101    switch (type) { 
     102        case AVC::eST_Audio: 
     103            return new BeBoB::SubunitAudio(unit, id ); 
     104        case AVC::eST_Music: 
     105            return new BeBoB::SubunitMusic(unit, id ); 
     106        default: 
     107            return NULL; 
     108    } 
     109} 
     110 
     111AVC::Plug * 
     112BeBoB::AvDevice::createPlug( AVC::Unit* unit, 
     113                     AVC::Subunit* subunit, 
     114                     AVC::function_block_type_t functionBlockType, 
     115                     AVC::function_block_type_t functionBlockId, 
     116                     AVC::Plug::EPlugAddressType plugAddressType, 
     117                     AVC::Plug::EPlugDirection plugDirection, 
     118                     AVC::plug_id_t plugId ) 
     119{ 
     120 
     121    return new BeBoB::Plug( unit, 
     122                     subunit, 
     123                     functionBlockType, 
     124                     functionBlockId, 
     125                     plugAddressType, 
     126                     plugDirection, 
     127                     plugId ); 
     128} 
     129 
    96130void 
    97131AvDevice::setVerboseLevel(int l) 
     
    166200//     } 
    167201 
    168     // bebob specific discovery procedure 
    169     if ( !discoverPlugs() ) { 
    170         debugError( "Detecting plugs failed\n" ); 
    171         return false; 
    172     } 
    173  
    174     if ( !discoverPlugConnections() ) { 
    175         debugError( "Detecting plug connections failed\n" ); 
    176         return false; 
    177     } 
    178  
    179     if ( !discoverSubUnitsPlugConnections() ) { 
    180         debugError( "Detecting plug connnection failed\n" ); 
    181         return false; 
    182     } 
    183  
    184     if ( !discoverSyncModes() ) { 
    185         debugError( "Detecting sync modes failed\n" ); 
    186         return false; 
    187     } 
    188  
    189202    // create a GenericMixer and add it as an OSC child node 
    190203    //  remove if already there 
     
    206219        } 
    207220    } 
    208     return true; 
    209 } 
    210  
    211 bool 
    212 AvDevice::enumerateSubUnits() 
    213 { 
    214     SubUnitInfoCmd subUnitInfoCmd( get1394Service() ); 
    215     subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    216  
    217     // NOTE: BeBoB has always exactly one audio and one music subunit. This 
    218     // means is fits into the first page of the SubUnitInfo command. 
    219     // So there is no need to do more than needed 
    220  
    221     subUnitInfoCmd.m_page = 0; 
    222     subUnitInfoCmd.setNodeId( getConfigRom().getNodeId() ); 
    223     subUnitInfoCmd.setVerbose( getDebugLevel() ); 
    224     if ( !subUnitInfoCmd.fire() ) { 
    225         debugError( "Subunit info command failed\n" ); 
    226         // shouldn't this be an error situation? 
    227         return false; 
    228     } 
    229  
    230     for ( int i = 0; i < subUnitInfoCmd.getNrOfValidEntries(); ++i ) { 
    231         subunit_type_t subunit_type 
    232             = subUnitInfoCmd.m_table[i].m_subunit_type; 
    233  
    234         unsigned int subunitId = getNrOfSubunits( subunit_type ); 
    235  
    236         debugOutput( DEBUG_LEVEL_VERBOSE, 
    237                      "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    238                      subunitId, 
    239                      subunit_type, 
    240                      subunitTypeToString( subunit_type ) ); 
    241  
    242         AVC::Subunit* subunit = 0; 
    243         switch( subunit_type ) { 
    244         case eST_Audio: 
    245             subunit = new BeBoB::SubunitAudio( *this, 
    246                                                subunitId ); 
    247             if ( !subunit ) { 
    248                 debugFatal( "Could not allocate SubunitAudio\n" ); 
    249                 return false; 
    250             } 
    251              
    252             if ( !subunit->discover() ) { 
    253                 debugError( "enumerateSubUnits: Could not discover " 
    254                             "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    255                             subunitId, 
    256                             subunit_type, 
    257                             subunitTypeToString( subunit_type ) ); 
    258                 delete subunit; 
    259                 return false; 
    260             } else { 
    261                 m_subunits.push_back( subunit ); 
    262             } 
    263              
    264             break; 
    265         case eST_Music: 
    266             subunit = new BeBoB::SubunitMusic( *this, 
    267                                                subunitId ); 
    268             if ( !subunit ) { 
    269                 debugFatal( "Could not allocate SubunitMusic\n" ); 
    270                 return false; 
    271             } 
    272             if ( !subunit->discover() ) { 
    273                 debugError( "enumerateSubUnits: Could not discover " 
    274                             "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    275                             subunitId, 
    276                             subunit_type, 
    277                             subunitTypeToString( subunit_type ) ); 
    278                 delete subunit; 
    279                 return false; 
    280             } else { 
    281                 m_subunits.push_back( subunit ); 
    282             } 
    283  
    284             break; 
    285         default: 
    286             debugOutput( DEBUG_LEVEL_NORMAL, 
    287                          "Unsupported subunit found, subunit_type = %d (%s)\n", 
    288                          subunit_type, 
    289                          subunitTypeToString( subunit_type ) ); 
    290             continue; 
    291  
    292         } 
    293     } 
    294  
    295     return true; 
    296 } 
    297  
    298 bool 
    299 AvDevice::discoverPlugs() 
    300 { 
    301     debugOutput( DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 
    302  
    303     ////////////////////////////////////////////// 
    304     // Get number of available isochronous input 
    305     // and output plugs of unit 
    306  
    307     PlugInfoCmd plugInfoCmd( *m_p1394Service ); 
    308     plugInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    309     plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    310     plugInfoCmd.setVerbose( m_verboseLevel ); 
    311  
    312     if ( !plugInfoCmd.fire() ) { 
    313         debugError( "plug info command failed\n" ); 
    314         return false; 
    315     } 
    316  
    317     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n", 
    318                  plugInfoCmd.m_serialBusIsochronousInputPlugs ); 
    319     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n", 
    320                  plugInfoCmd.m_serialBusIsochronousOutputPlugs ); 
    321     debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n", 
    322                  plugInfoCmd.m_externalInputPlugs ); 
    323     debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n", 
    324                  plugInfoCmd.m_externalOutputPlugs ); 
    325  
    326     if ( !discoverPlugsPCR( Plug::eAPD_Input, 
    327                             plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) 
    328     { 
    329         debugError( "pcr input plug discovering failed\n" ); 
    330         return false; 
    331     } 
    332  
    333     if ( !discoverPlugsPCR( Plug::eAPD_Output, 
    334                             plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) 
    335     { 
    336         debugError( "pcr output plug discovering failed\n" ); 
    337         return false; 
    338     } 
    339  
    340     if ( !discoverPlugsExternal( Plug::eAPD_Input, 
    341                                  plugInfoCmd.m_externalInputPlugs ) ) 
    342     { 
    343         debugError( "external input plug discovering failed\n" ); 
    344         return false; 
    345     } 
    346  
    347     if ( !discoverPlugsExternal( Plug::eAPD_Output, 
    348                                  plugInfoCmd.m_externalOutputPlugs ) ) 
    349     { 
    350         debugError( "external output plug discovering failed\n" ); 
    351         return false; 
    352     } 
    353  
    354     return true; 
    355 } 
    356  
    357 bool 
    358 AvDevice::discoverPlugsPCR( Plug::EPlugDirection plugDirection, 
    359                             plug_id_t plugMaxId ) 
    360 { 
    361     debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plugs, direction %d...\n",plugDirection); 
    362     for ( int plugId = 0; 
    363           plugId < plugMaxId; 
    364           ++plugId ) 
    365     { 
    366         AVC::Plug* plug  = new Plug( this, 
    367                                 NULL, 
    368                                 0xff, 
    369                                 0xff, 
    370                                 Plug::eAPA_PCR, 
    371                                 plugDirection, 
    372                                 plugId ); 
    373         if ( !plug || !plug->discover() ) { 
    374             debugError( "plug discovering failed\n" ); 
    375             delete plug; 
    376             return false; 
    377         } 
    378  
    379         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    380                      plug->getName() ); 
    381         m_pcrPlugs.push_back( plug ); 
    382     } 
    383  
    384     return true; 
    385 } 
    386  
    387 bool 
    388 AvDevice::discoverPlugsExternal( Plug::EPlugDirection plugDirection, 
    389                                  plug_id_t plugMaxId ) 
    390 { 
    391     debugOutput( DEBUG_LEVEL_NORMAL, "Discovering Externals plugs, direction %d...\n",plugDirection); 
    392     for ( int plugId = 0; 
    393           plugId < plugMaxId; 
    394           ++plugId ) 
    395     { 
    396         AVC::Plug* plug  = new Plug( this, NULL, 
    397                                 0xff, 
    398                                 0xff, 
    399                                 Plug::eAPA_ExternalPlug, 
    400                                 plugDirection, 
    401                                 plugId ); 
    402         if ( !plug || !plug->discover() ) { 
    403             debugError( "plug discovering failed\n" ); 
    404             return false; 
    405         } 
    406  
    407         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    408                      plug->getName() ); 
    409         m_externalPlugs.push_back( plug ); 
    410     } 
    411  
    412     return true; 
    413 } 
    414  
    415 bool 
    416 AvDevice::discoverPlugConnections() 
    417 { 
    418     for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
    419           it != m_pcrPlugs.end(); 
    420           ++it ) 
    421     { 
    422         BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it); 
    423         if(!plug) { 
    424             debugError("BUG: not a bebob plug\n"); 
    425             return false; 
    426         } 
    427         if ( !plug->discoverConnections() ) { 
    428             debugError( "Could not discover plug connections\n" ); 
    429             return false; 
    430         } 
    431     } 
    432     for ( PlugVector::iterator it = m_externalPlugs.begin(); 
    433           it != m_externalPlugs.end(); 
    434           ++it ) 
    435     { 
    436         BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it); 
    437         if(!plug) { 
    438             debugError("BUG: not a bebob plug\n"); 
    439             return false; 
    440         } 
    441         if ( !plug->discoverConnections() ) { 
    442             debugError( "Could not discover plug connections\n" ); 
    443             return false; 
    444         } 
    445     } 
    446  
    447     return true; 
    448 } 
    449  
    450 bool 
    451 AvDevice::discoverSubUnitsPlugConnections() 
    452 { 
    453     for ( SubunitVector::iterator it = m_subunits.begin(); 
    454           it != m_subunits.end(); 
    455           ++it ) 
    456     { 
    457         BeBoB::Subunit* subunit = dynamic_cast<BeBoB::Subunit*>(*it); 
    458         if (subunit==NULL) { 
    459             debugError("BUG: subunit is not a BeBoB::Subunit\n"); 
    460             return false; 
    461         } 
    462  
    463         if ( !subunit->discoverConnections() ) { 
    464             debugError( "Subunit '%s'  plug connections failed\n", 
    465                         subunit->getName() ); 
    466             return false; 
    467         } 
    468     } 
    469     return true; 
    470 } 
    471  
    472 bool 
    473 AvDevice::discoverSyncModes() 
    474 { 
    475     // Following possible sync plugs exists: 
    476     // - Music subunit sync output plug = internal sync (CSP) 
    477     // - Unit input plug 0 = SYT match 
    478     // - Unit input plut 1 = Sync stream 
    479     // 
    480     // If last sync mode is reported it is mostelikely not 
    481     // implemented *sic* 
    482     // 
    483     // Following sync sources are device specific: 
    484     // - All unit external input plugs which have a 
    485     //   sync information (WS, SPDIF, ...) 
    486  
    487     // First we have to find the sync input and output plug 
    488     // in the music subunit. 
    489  
    490     // Note PCR input means 1394bus-to-device where as 
    491     // MSU input means subunit-to-device 
    492  
    493     PlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    494                                                      Plug::eAPD_Input, 
    495                                                      Plug::eAPT_Sync ); 
    496     if ( !syncPCRInputPlugs.size() ) { 
    497         debugWarning( "No PCR sync input plug found\n" ); 
    498     } 
    499  
    500     PlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    501                                                       Plug::eAPD_Output, 
    502                                                       Plug::eAPT_Sync ); 
    503     if ( !syncPCROutputPlugs.size() ) { 
    504         debugWarning( "No PCR sync output plug found\n" ); 
    505     } 
    506  
    507     PlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    508                                                     Plug::eAPD_Input, 
    509                                                     Plug::eAPT_IsoStream ); 
    510     if ( !isoPCRInputPlugs.size() ) { 
    511         debugWarning( "No PCR iso input plug found\n" ); 
    512  
    513     } 
    514  
    515     PlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    516                                                     Plug::eAPD_Output, 
    517                                                     Plug::eAPT_IsoStream ); 
    518     if ( !isoPCROutputPlugs.size() ) { 
    519         debugWarning( "No PCR iso output plug found\n" ); 
    520  
    521     } 
    522  
    523     PlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 
    524                                                     Plug::eAPD_Input, 
    525                                                     Plug::eAPT_Digital ); 
    526  
    527     PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
    528         eST_Music, 
    529         0, 
    530         0xff, 
    531         0xff, 
    532         Plug::eAPA_SubunitPlug, 
    533         Plug::eAPD_Input, 
    534         Plug::eAPT_Sync ); 
    535     if ( !syncMSUInputPlugs.size() ) { 
    536         debugWarning( "No sync input plug for MSU subunit found\n" ); 
    537     } 
    538  
    539     PlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 
    540         eST_Music, 
    541         0, 
    542         0xff, 
    543         0xff, 
    544         Plug::eAPA_SubunitPlug, 
    545         Plug::eAPD_Output, 
    546         Plug::eAPT_Sync ); 
    547     if ( !syncMSUOutputPlugs.size() ) { 
    548         debugWarning( "No sync output plug for MSU subunit found\n" ); 
    549     } 
    550  
    551     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); 
    552     showPlugs( syncPCRInputPlugs ); 
    553     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); 
    554     showPlugs( syncPCROutputPlugs ); 
    555     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); 
    556     showPlugs( isoPCRInputPlugs ); 
    557     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); 
    558     showPlugs( isoPCROutputPlugs ); 
    559     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); 
    560     showPlugs( digitalPCRInputPlugs ); 
    561     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); 
    562     showPlugs( syncMSUInputPlugs ); 
    563     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); 
    564     showPlugs( syncMSUOutputPlugs ); 
    565  
    566     // Check all possible PCR input to MSU input connections 
    567     // -> sync stream input 
    568     checkSyncConnectionsAndAddToList( syncPCRInputPlugs, 
    569                                       syncMSUInputPlugs, 
    570                                       "Sync Stream Input" ); 
    571  
    572     // Check all possible MSU output to PCR output connections 
    573     // -> sync stream output 
    574     checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
    575                                       syncPCROutputPlugs, 
    576                                       "Sync Stream Output" ); 
    577  
    578     // Check all PCR iso input to MSU input connections 
    579     // -> SYT match 
    580     checkSyncConnectionsAndAddToList( isoPCRInputPlugs, 
    581                                       syncMSUInputPlugs, 
    582                                       "Syt Match" ); 
    583  
    584     // Check all MSU sync output to MSU input connections 
    585     // -> CSP 
    586     checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
    587                                       syncMSUInputPlugs, 
    588                                       "Internal (CSP)" ); 
    589  
    590     // Check all external PCR digital input to MSU input connections 
    591     // -> SPDIF/ADAT sync 
    592     checkSyncConnectionsAndAddToList( digitalPCRInputPlugs, 
    593                                       syncMSUInputPlugs, 
    594                                       "Digital Input Sync" ); 
    595  
    596     // Currently active connection signal source cmd, command type 
    597     // status, source unknown, destination MSU sync input plug 
    598  
    599     for ( PlugVector::const_iterator it = syncMSUInputPlugs.begin(); 
    600           it != syncMSUInputPlugs.end(); 
    601           ++it ) 
    602     { 
    603         AVC::Plug* msuPlug = *it; 
    604         for ( PlugVector::const_iterator jt = 
    605                   msuPlug->getInputConnections().begin(); 
    606               jt != msuPlug->getInputConnections().end(); 
    607               ++jt ) 
    608         { 
    609             AVC::Plug* plug = *jt; 
    610  
    611             for ( SyncInfoVector::iterator it = m_syncInfos.begin(); 
    612                   it != m_syncInfos.end(); 
    613                   ++it ) 
    614             { 
    615                 SyncInfo* pSyncInfo = &*it; 
    616                 if ( ( pSyncInfo->m_source == plug ) 
    617                      && ( pSyncInfo->m_destination == msuPlug ) ) 
    618                 { 
    619                     m_activeSyncInfo = pSyncInfo; 
    620                     break; 
    621                 } 
    622             } 
    623             debugOutput( DEBUG_LEVEL_NORMAL, 
    624                          "Active Sync Connection: '%s' -> '%s'\n", 
    625                          plug->getName(), 
    626                          msuPlug->getName() ); 
    627         } 
    628     } 
    629  
    630221    return true; 
    631222} 
     
    821412} 
    822413 
    823 bool 
    824 AvDevice::checkSyncConnectionsAndAddToList( PlugVector& plhs, 
    825                                             PlugVector& prhs, 
    826                                             std::string syncDescription ) 
    827 { 
    828     for ( PlugVector::iterator plIt = plhs.begin(); 
    829           plIt != plhs.end(); 
    830           ++plIt ) 
    831     { 
    832         AVC::Plug* pl = *plIt; 
    833         for ( PlugVector::iterator prIt = prhs.begin(); 
    834               prIt != prhs.end(); 
    835               ++prIt ) 
    836         { 
    837             AVC::Plug* pr = *prIt; 
    838             if ( pl->inquireConnnection( *pr ) ) { 
    839                 m_syncInfos.push_back( SyncInfo( *pl, *pr, syncDescription ) ); 
    840                 debugOutput( DEBUG_LEVEL_NORMAL, 
    841                              "Sync connection '%s' -> '%s'\n", 
    842                              pl->getName(), 
    843                              pr->getName() ); 
    844             } 
    845         } 
    846     } 
    847     return true; 
    848 } 
    849  
    850 bool AvDevice::setActiveSync(const SyncInfo& syncInfo) 
    851 { 
    852     return syncInfo.m_source->setConnection( *syncInfo.m_destination ); 
    853 } 
    854414 
    855415bool 
     
    863423        // don't lock 
    864424    } else { 
    865  
     425//         return Unit::reserve(4); 
    866426    } 
    867427 
     
    879439        // don't unlock 
    880440    } else { 
    881  
     441//         return Unit::reserve(0); 
    882442    } 
    883443    return true; 
     
    1018578                        // but bebob reports it starting from 1. Decide where 
    1019579                        // and how to handle this (pp: here) 
     580                        // note that the descriptor mechanism specifies indexing from 0 
    1020581                        channelInfo->m_streamPosition - 1, 
    1021582                        channelInfo->m_location - 1, 
     
    1028589                        portname.str(), 
    1029590                        direction, 
    1030                         // \todo: streaming backend expects indexing starting from 0 
    1031                         // but bebob reports it starting from 1. Decide where 
    1032                         // and how to handle this (pp: here) 
    1033                         channelInfo->m_streamPosition - 1, 
    1034                         channelInfo->m_location - 1, 
     591                        channelInfo->m_streamPosition, 
     592                        // Workaround for out-of-spec hardware 
     593                        // should be: 
     594                        // channelInfo->m_location-1, 
     595                        // but now we renumber the midi channels' location as they 
     596                        // are discovered 
     597                        processor->getPortCount(Streaming::Port::E_Midi), 
    1035598                        Streaming::AmdtpPortInfo::E_Midi 
    1036599                ); 
  • branches/echoaudio/src/bebob/bebob_avdevice.h

    r509 r524  
    8888    virtual void showDevice(); 
    8989 
    90     bool setActiveSync( const SyncInfo& syncInfo ); 
    91  
    9290    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    9391    static AvDevice* deserialize( Glib::ustring basePath, 
     
    10098    ConfigRom& getConfigRom() const  
    10199        { return FFADODevice::getConfigRom(); }; 
    102  
     100         
     101    virtual AVC::Subunit* createSubunit(AVC::Unit& unit, 
     102                                        AVC::ESubunitType type, 
     103                                        AVC::subunit_t id ); 
     104    virtual AVC::Plug *createPlug( AVC::Unit* unit, 
     105                                   AVC::Subunit* subunit, 
     106                                   AVC::function_block_type_t functionBlockType, 
     107                                   AVC::function_block_type_t functionBlockId, 
     108                                   AVC::Plug::EPlugAddressType plugAddressType, 
     109                                   AVC::Plug::EPlugDirection plugDirection, 
     110                                   AVC::plug_id_t plugId ); 
    103111protected: 
    104  
    105     bool enumerateSubUnits(); 
    106  
    107     bool discoverPlugs(); 
    108     bool discoverPlugsPCR( AVC::Plug::EPlugDirection plugDirection, 
    109                            AVC::plug_id_t plugMaxId ); 
    110     bool discoverPlugsExternal( AVC::Plug::EPlugDirection plugDirection, 
    111                                 AVC::plug_id_t plugMaxId ); 
    112     bool discoverPlugConnections(); 
    113     bool discoverSyncModes(); 
    114     bool discoverSubUnitsPlugConnections(); 
    115112 
    116113    bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, 
     
    121118                                   AVC::ESamplingFrequency samplingFrequency ); 
    122119 
    123     bool checkSyncConnectionsAndAddToList( AVC::PlugVector& plhs, 
    124                                            AVC::PlugVector& prhs, 
    125                                            std::string syncDescription ); 
     120 
    126121 
    127122protected: 
  • branches/echoaudio/src/bebob/bebob_avdevice_subunit.cpp

    r509 r524  
    3636using namespace AVC; 
    3737 
    38 IMPL_DEBUG_MODULE( BeBoB::Subunit, BeBoB::Subunit, DEBUG_LEVEL_VERBOSE ); 
    39 IMPL_DEBUG_MODULE( BeBoB::SubunitAudio, BeBoB::SubunitAudio, DEBUG_LEVEL_VERBOSE ); 
    40 IMPL_DEBUG_MODULE( BeBoB::SubunitMusic, BeBoB::SubunitMusic, DEBUG_LEVEL_VERBOSE ); 
    41  
    42 bool 
    43 BeBoB::Subunit::discover() 
    44 { 
    45     if ( !discoverPlugs() ) { 
    46         debugError( "plug discovering failed\n" ); 
    47         return false; 
    48     } 
    49  
    50     return true; 
    51 } 
    52  
    53 bool 
    54 BeBoB::Subunit::discoverPlugs() 
    55 { 
    56     PlugInfoCmd plugInfoCmd( getUnit().get1394Service(), 
    57                              PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug ); 
    58     plugInfoCmd.setNodeId( getUnit().getConfigRom().getNodeId() ); 
    59     plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    60     plugInfoCmd.setSubunitType( getSubunitType() ); 
    61     plugInfoCmd.setSubunitId( getSubunitId() ); 
    62     plugInfoCmd.setVerbose( getDebugLevel() ); 
    63  
    64     if ( !plugInfoCmd.fire() ) { 
    65         debugError( "plug info command failed\n" ); 
    66         return false; 
    67     } 
    68  
    69     debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n", 
    70                  plugInfoCmd.m_sourcePlugs ); 
    71     debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output " 
    72                  "plugs = %d\n", plugInfoCmd.m_destinationPlugs ); 
    73  
    74     if ( !discoverPlugs( Plug::eAPD_Input, 
    75                          plugInfoCmd.m_destinationPlugs ) ) 
    76     { 
    77         debugError( "destination plug discovering failed\n" ); 
    78         return false; 
    79     } 
    80  
    81     if ( !discoverPlugs(  Plug::eAPD_Output, 
    82                           plugInfoCmd.m_sourcePlugs ) ) 
    83     { 
    84         debugError( "source plug discovering failed\n" ); 
    85         return false; 
    86     } 
    87  
    88     return true; 
    89 } 
    90  
    91 bool 
    92 BeBoB::Subunit::discoverConnections() 
    93 { 
    94     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
    95      
    96     for ( PlugVector::iterator it = getPlugs().begin(); 
    97           it != getPlugs().end(); 
    98           ++it ) 
    99     { 
    100         BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it); 
    101         if(!plug) { 
    102             debugError("BUG: not a bebob plug\n"); 
    103             return false; 
    104         } 
    105         if ( !plug->discoverConnections() ) { 
    106             debugError( "plug connection discovering failed ('%s')\n", 
    107                         plug->getName() ); 
    108             return false; 
    109         } 
    110     } 
    111  
    112     return true; 
    113 } 
    114  
    115 bool 
    116 BeBoB::Subunit::discoverPlugs(Plug::EPlugDirection plugDirection, 
    117                                       plug_id_t plugMaxId ) 
    118 { 
    119     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 
    120     for ( int plugIdx = 0; 
    121           plugIdx < plugMaxId; 
    122           ++plugIdx ) 
    123     { 
    124         ESubunitType subunitType = 
    125             static_cast<ESubunitType>( getSubunitType() ); 
    126         BeBoB::Plug* plug = new BeBoB::Plug( &getUnit(), 
    127                                              &getSubunit(), 
    128                                              0xff, 
    129                                              0xff, 
    130                                              Plug::eAPA_SubunitPlug, 
    131                                              plugDirection, 
    132                                              plugIdx ); 
    133         if ( !plug ) { 
    134             debugError( "plug creation failed\n" ); 
    135             return false; 
    136         } 
    137          
    138         plug->setVerboseLevel(getDebugLevel()); 
    139          
    140         if ( !plug->discover() ) { 
    141             debugError( "plug discover failed\n" ); 
    142             return false; 
    143         } 
    144  
    145         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    146                      plug->getName() ); 
    147         getPlugs().push_back( plug ); 
    148     } 
    149     return true; 
    150 } 
    151  
    152  
    15338////////////////////////// 
    15439 
     
    15641                                   subunit_t id ) 
    15742    : AVC::SubunitAudio( avDevice, id ) 
    158     , BeBoB::Subunit() 
    15943{ 
    16044} 
     
    16852{ 
    16953 
     54} 
     55 
     56AVC::Plug * 
     57BeBoB::SubunitAudio::createPlug( AVC::Unit* unit, 
     58                     AVC::Subunit* subunit, 
     59                     AVC::function_block_type_t functionBlockType, 
     60                     AVC::function_block_type_t functionBlockId, 
     61                     AVC::Plug::EPlugAddressType plugAddressType, 
     62                     AVC::Plug::EPlugDirection plugDirection, 
     63                     AVC::plug_id_t plugId ) 
     64{ 
     65 
     66    return new BeBoB::Plug( unit, 
     67                     subunit, 
     68                     functionBlockType, 
     69                     functionBlockId, 
     70                     plugAddressType, 
     71                     plugDirection, 
     72                     plugId ); 
    17073} 
    17174 
     
    17982        return false; 
    18083    } 
    181      
    182     // do BeBoB subunit specific discovery 
    183     if ( !BeBoB::Subunit::discover() ) { 
    184         return false; 
    185     } 
    18684 
    18785    // do the remaining BeBoB audio subunit discovery 
     
    19896{ 
    19997    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
    200     if ( !BeBoB::Subunit::discoverConnections() ) { 
     98    if ( !Subunit::discoverConnections() ) { 
    20199        return false; 
    202100    } 
     
    488386                                   subunit_t id ) 
    489387    : AVC::SubunitMusic( avDevice, id ) 
    490     , BeBoB::Subunit() 
    491388{ 
    492389} 
     
    494391BeBoB::SubunitMusic::SubunitMusic() 
    495392    : AVC::SubunitMusic() 
    496     , BeBoB::Subunit() 
    497393{ 
    498394} 
     
    500396BeBoB::SubunitMusic::~SubunitMusic() 
    501397{ 
     398} 
     399 
     400AVC::Plug * 
     401BeBoB::SubunitMusic::createPlug( AVC::Unit* unit, 
     402                     AVC::Subunit* subunit, 
     403                     AVC::function_block_type_t functionBlockType, 
     404                     AVC::function_block_type_t functionBlockId, 
     405                     AVC::Plug::EPlugAddressType plugAddressType, 
     406                     AVC::Plug::EPlugDirection plugDirection, 
     407                     AVC::plug_id_t plugId ) 
     408{ 
     409 
     410    return new BeBoB::Plug( unit, 
     411                     subunit, 
     412                     functionBlockType, 
     413                     functionBlockId, 
     414                     plugAddressType, 
     415                     plugDirection, 
     416                     plugId ); 
    502417} 
    503418 
     
    511426        return false; 
    512427    } 
    513      
    514     // do BeBoB subunit specific discovery 
    515     if ( !BeBoB::Subunit::discover() ) { 
    516         return false; 
    517     } 
    518428 
    519429    // do the remaining BeBoB music subunit discovery 
  • branches/echoaudio/src/bebob/bebob_avdevice_subunit.h

    r509 r524  
    4444///////////////////////////// 
    4545 
    46 class Subunit { 
    47 public: 
    48     Subunit() {}; 
    49     virtual ~Subunit() {}; 
    50     virtual bool discover(); 
    51     virtual bool discoverConnections(); 
    52      
    53     // required functions 
    54     // implemented by the derived class 
    55     virtual const char* getName() = 0; 
    56     virtual AVC::subunit_t getSubunitId() = 0; 
    57     virtual AVC::ESubunitType getSubunitType() = 0; 
    58     virtual AVC::Unit& getUnit() const = 0; 
    59     virtual AVC::Subunit& getSubunit() = 0; 
    60     virtual AVC::PlugVector& getPlugs() = 0; 
    61  
    62 protected: 
    63     bool discoverPlugs(); 
    64     bool discoverPlugs(Plug::EPlugDirection plugDirection, 
    65                        AVC::plug_id_t plugMaxId ); 
    66 private: 
    67     DECLARE_DEBUG_MODULE; 
    68 }; 
    69  
    70 ///////////////////////////// 
    71  
    7246class SubunitAudio : public AVC::SubunitAudio 
    73                    , public BeBoB::Subunit 
    7447{ 
    7548public: 
     
    8255    virtual bool discoverConnections(); 
    8356 
    84     // required interface for BeBoB::Subunit 
     57    virtual AVC::Plug *createPlug( AVC::Unit* unit, 
     58                                   AVC::Subunit* subunit, 
     59                                   AVC::function_block_type_t functionBlockType, 
     60                                   AVC::function_block_type_t functionBlockId, 
     61                                   AVC::Plug::EPlugAddressType plugAddressType, 
     62                                   AVC::Plug::EPlugDirection plugDirection, 
     63                                   AVC::plug_id_t plugId ); 
     64 
    8565    virtual const char* getName(); 
    86     virtual AVC::subunit_t getSubunitId()  
    87         { return AVC::SubunitAudio::getSubunitId(); }; 
    88     virtual AVC::ESubunitType getSubunitType() 
    89         { return AVC::SubunitAudio::getSubunitType(); }; 
    90     virtual AVC::Unit& getUnit() const 
    91         { return AVC::SubunitAudio::getUnit(); }; 
    92     virtual AVC::Subunit& getSubunit() 
    93         { return *this; }; 
    94     virtual AVC::PlugVector& getPlugs() 
    95         { return AVC::SubunitAudio::getPlugs(); }; 
    9666 
    9767protected: 
     
    11181                                   Util::IODeserialize& deser, 
    11282                                   AVC::Unit& unit ); 
    113 private: 
    114     DECLARE_DEBUG_MODULE; 
     83 
    11584}; 
    11685 
     
    11887 
    11988class SubunitMusic : public AVC::SubunitMusic 
    120                    , public BeBoB::Subunit 
    12189{ 
    12290 public: 
     
    12694    virtual ~SubunitMusic(); 
    12795 
    128     // required interface for BeBoB::Subunit 
     96    virtual bool discover(); 
     97     
     98    virtual AVC::Plug *createPlug( AVC::Unit* unit, 
     99                                   AVC::Subunit* subunit, 
     100                                   AVC::function_block_type_t functionBlockType, 
     101                                   AVC::function_block_type_t functionBlockId, 
     102                                   AVC::Plug::EPlugAddressType plugAddressType, 
     103                                   AVC::Plug::EPlugDirection plugDirection, 
     104                                   AVC::plug_id_t plugId ); 
     105 
    129106    virtual const char* getName(); 
    130     virtual AVC::subunit_t getSubunitId()  
    131         { return AVC::SubunitMusic::getSubunitId(); }; 
    132     virtual AVC::ESubunitType getSubunitType() 
    133         { return AVC::SubunitMusic::getSubunitType(); }; 
    134     virtual AVC::Unit& getUnit() const 
    135         { return AVC::SubunitMusic::getUnit(); }; 
    136     virtual AVC::Subunit& getSubunit() 
    137         { return *this; }; 
    138     virtual AVC::PlugVector& getPlugs() 
    139         { return AVC::SubunitMusic::getPlugs(); }; 
    140  
    141      
    142     virtual bool discover(); 
    143107 
    144108protected: 
     
    148112                                   Util::IODeserialize& deser, 
    149113                                   AVC::Unit& unit ); 
    150 private: 
    151     DECLARE_DEBUG_MODULE; 
     114 
    152115}; 
    153116 
  • branches/echoaudio/src/bebob/bebob_avplug.cpp

    r509 r524  
    423423} 
    424424 
    425 bool 
    426 Plug::discoverStreamFormat() 
    427 
    428     ExtendedStreamFormatCmd extStreamFormatCmd = 
    429         setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
    430     extStreamFormatCmd.setVerbose( getDebugLevel() ); 
    431  
    432     if ( !extStreamFormatCmd.fire() ) { 
    433         debugError( "stream format command failed\n" ); 
    434         return false; 
    435     } 
    436  
    437     if ( ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NoStreamFormat ) 
    438          || ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NotUsed ) ) 
    439     { 
    440         debugOutput( DEBUG_LEVEL_VERBOSE, 
    441                      "No stream format information available\n" ); 
    442         return true; 
    443     } 
    444  
    445     if ( !extStreamFormatCmd.getFormatInformation() ) { 
    446         debugWarning( "No stream format information for plug found -> skip\n" ); 
    447         return true; 
    448     } 
    449  
    450     if ( extStreamFormatCmd.getFormatInformation()->m_root 
    451            != FormatInformation::eFHR_AudioMusic  ) 
    452     { 
    453         debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 
    454         return true; 
    455     } 
    456  
    457     FormatInformation* formatInfo = 
    458         extStreamFormatCmd.getFormatInformation(); 
    459     FormatInformationStreamsCompound* compoundStream 
    460         = dynamic_cast< FormatInformationStreamsCompound* > ( 
    461             formatInfo->m_streams ); 
    462     if ( compoundStream ) { 
    463         m_samplingFrequency = 
    464             compoundStream->m_samplingFrequency; 
    465         debugOutput( DEBUG_LEVEL_VERBOSE, 
    466                      "%s plug %d uses " 
    467                      "sampling frequency %d, nr of stream infos = %d\n", 
    468                      getName(), 
    469                      m_id, 
    470                      m_samplingFrequency, 
    471                      compoundStream->m_numberOfStreamFormatInfos ); 
    472  
    473         for ( int i = 1; 
    474               i <= compoundStream->m_numberOfStreamFormatInfos; 
    475               ++i ) 
    476         { 
    477             ClusterInfo* clusterInfo = 
    478                 const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 
    479  
    480             if ( !clusterInfo ) { 
    481                 debugError( "No matching cluster " 
    482                             "info found for index %d\n",  i ); 
    483                     return false; 
    484             } 
    485             StreamFormatInfo* streamFormatInfo = 
    486                 compoundStream->m_streamFormatInfos[ i - 1 ]; 
    487  
    488             debugOutput( DEBUG_LEVEL_VERBOSE, 
    489                          "number of channels = %d, stream format = %d\n", 
    490                          streamFormatInfo->m_numberOfChannels, 
    491                          streamFormatInfo->m_streamFormat ); 
    492  
    493             int nrOfChannels = clusterInfo->m_nrOfChannels; 
    494             if ( streamFormatInfo->m_streamFormat == 
    495                  FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 
    496             { 
    497                 // 8 logical midi channels fit into 1 channel 
    498                 nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 
    499             } 
    500             // sanity check 
    501             if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 
    502             { 
    503                 debugWarning( "Number of channels " 
    504                               "mismatch: '%s' plug discovering reported " 
    505                               "%d channels for cluster '%s', while stream " 
    506                               "format reported %d\n", 
    507                               getName(), 
    508                               nrOfChannels, 
    509                               clusterInfo->m_name.c_str(), 
    510                               streamFormatInfo->m_numberOfChannels); 
    511             } 
    512             clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 
    513  
    514             debugOutput( DEBUG_LEVEL_VERBOSE, 
    515                          "%s plug %d cluster info %d ('%s'): " 
    516                          "stream format %d\n", 
    517                          getName(), 
    518                          m_id, 
    519                          i, 
    520                          clusterInfo->m_name.c_str(), 
    521                          clusterInfo->m_streamFormat ); 
    522         } 
    523     } 
    524  
    525     FormatInformationStreamsSync* syncStream 
    526         = dynamic_cast< FormatInformationStreamsSync* > ( 
    527             formatInfo->m_streams ); 
    528     if ( syncStream ) { 
    529         m_samplingFrequency = 
    530             syncStream->m_samplingFrequency; 
    531         debugOutput( DEBUG_LEVEL_VERBOSE, 
    532                      "%s plug %d is sync stream with sampling frequency %d\n", 
    533                      getName(), 
    534                      m_id, 
    535                      m_samplingFrequency ); 
    536     } 
    537  
    538  
    539     if ( !compoundStream && !syncStream ) 
    540     { 
    541         debugError( "Unsupported stream format\n" ); 
    542         return false; 
    543     } 
    544  
    545     return true; 
    546 
    547  
    548 bool 
    549 Plug::discoverSupportedStreamFormats() 
    550 
    551     ExtendedStreamFormatCmd extStreamFormatCmd = 
    552         setPlugAddrToStreamFormatCmd( 
    553             ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 
    554     extStreamFormatCmd.setVerbose( getDebugLevel() ); 
    555  
    556     int i = 0; 
    557     bool cmdSuccess = false; 
    558  
    559     do { 
    560         extStreamFormatCmd.setIndexInStreamFormat( i ); 
    561         extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
    562         cmdSuccess = extStreamFormatCmd.fire(); 
    563         if ( cmdSuccess 
    564              && ( extStreamFormatCmd.getResponse() 
    565                   == AVCCommand::eR_Implemented ) ) 
    566         { 
    567             FormatInfo formatInfo; 
    568             formatInfo.m_index = i; 
    569             bool formatInfoIsValid = true; 
    570  
    571             FormatInformationStreamsSync* syncStream 
    572                 = dynamic_cast< FormatInformationStreamsSync* > 
    573                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
    574             if ( syncStream ) { 
    575                 formatInfo.m_samplingFrequency = 
    576                     syncStream->m_samplingFrequency; 
    577                 formatInfo.m_isSyncStream = true ; 
    578             } 
    579  
    580             FormatInformationStreamsCompound* compoundStream 
    581                 = dynamic_cast< FormatInformationStreamsCompound* > 
    582                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
    583             if ( compoundStream ) { 
    584                 formatInfo.m_samplingFrequency = 
    585                     compoundStream->m_samplingFrequency; 
    586                 formatInfo.m_isSyncStream = false; 
    587                 for ( int j = 0; 
    588                       j < compoundStream->m_numberOfStreamFormatInfos; 
    589                       ++j ) 
    590                 { 
    591                     switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 
    592                     case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 
    593                         formatInfo.m_audioChannels += 
    594                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    595                         break; 
    596                     case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 
    597                         formatInfo.m_audioChannels += 
    598                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    599                         break; 
    600                     case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 
    601                         formatInfo.m_midiChannels += 
    602                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    603                         break; 
    604                     default: 
    605                         formatInfoIsValid = false; 
    606                         debugWarning("unknown stream format (0x%02x) for channel " 
    607                                       "(%d)\n", 
    608                                      compoundStream->m_streamFormatInfos[j]->m_streamFormat, 
    609                                      j ); 
    610                     } 
    611                 } 
    612             } 
    613  
    614             if ( formatInfoIsValid ) { 
    615                 flushDebugOutput(); 
    616                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    617                              "[%s:%d] formatInfo[%d].m_samplingFrequency " 
    618                              "= %d\n", 
    619                              getName(), m_id, 
    620                              i, formatInfo.m_samplingFrequency ); 
    621                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    622                              "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 
    623                              getName(), m_id, 
    624                              i, formatInfo.m_isSyncStream ); 
    625                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    626                              "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 
    627                              getName(), m_id, 
    628                              i, formatInfo.m_audioChannels ); 
    629                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    630                              "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 
    631                              getName(), m_id, 
    632                              i, formatInfo.m_midiChannels ); 
    633                 m_formatInfos.push_back( formatInfo ); 
    634                 flushDebugOutput(); 
    635             } 
    636         } 
    637  
    638         ++i; 
    639     } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 
    640                               == ExtendedStreamFormatCmd::eR_Implemented ) ); 
    641  
    642     return true; 
    643 
     425// NOTE: currently in the generic AV/C unit 
     426// bool 
     427// Plug::discoverStreamFormat() 
     428// { 
     429//     ExtendedStreamFormatCmd extStreamFormatCmd = 
     430//         setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
     431//     extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     432//  
     433//     if ( !extStreamFormatCmd.fire() ) { 
     434//         debugError( "stream format command failed\n" ); 
     435//         return false; 
     436//     } 
     437//  
     438//     if ( ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NoStreamFormat ) 
     439//          || ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NotUsed ) ) 
     440//     { 
     441//         debugOutput( DEBUG_LEVEL_VERBOSE, 
     442//                      "No stream format information available\n" ); 
     443//         return true; 
     444//     } 
     445//  
     446//     if ( !extStreamFormatCmd.getFormatInformation() ) { 
     447//         debugWarning( "No stream format information for plug found -> skip\n" ); 
     448//         return true; 
     449//     } 
     450//  
     451//     if ( extStreamFormatCmd.getFormatInformation()->m_root 
     452//            != FormatInformation::eFHR_AudioMusic  ) 
     453//     { 
     454//         debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 
     455//         return true; 
     456//     } 
     457//  
     458//     FormatInformation* formatInfo = 
     459//         extStreamFormatCmd.getFormatInformation(); 
     460//     FormatInformationStreamsCompound* compoundStream 
     461//         = dynamic_cast< FormatInformationStreamsCompound* > ( 
     462//             formatInfo->m_streams ); 
     463//     if ( compoundStream ) { 
     464//         m_samplingFrequency = 
     465//             compoundStream->m_samplingFrequency; 
     466//         debugOutput( DEBUG_LEVEL_VERBOSE, 
     467//                      "%s plug %d uses " 
     468//                      "sampling frequency %d, nr of stream infos = %d\n", 
     469//                      getName(), 
     470//                      m_id, 
     471//                      m_samplingFrequency, 
     472//                      compoundStream->m_numberOfStreamFormatInfos ); 
     473//  
     474//         for ( int i = 1; 
     475//               i <= compoundStream->m_numberOfStreamFormatInfos; 
     476//               ++i ) 
     477//         { 
     478//             ClusterInfo* clusterInfo = 
     479//                 const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 
     480//  
     481//             if ( !clusterInfo ) { 
     482//                 debugError( "No matching cluster " 
     483//                             "info found for index %d\n",  i ); 
     484//                     return false; 
     485//             } 
     486//             StreamFormatInfo* streamFormatInfo = 
     487//                 compoundStream->m_streamFormatInfos[ i - 1 ]; 
     488//  
     489//             debugOutput( DEBUG_LEVEL_VERBOSE, 
     490//                          "number of channels = %d, stream format = %d\n", 
     491//                          streamFormatInfo->m_numberOfChannels, 
     492//                          streamFormatInfo->m_streamFormat ); 
     493//  
     494//             int nrOfChannels = clusterInfo->m_nrOfChannels; 
     495//             if ( streamFormatInfo->m_streamFormat == 
     496//                  FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 
     497//             { 
     498//                 // 8 logical midi channels fit into 1 channel 
     499//                 nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 
     500//             } 
     501//             // sanity check 
     502//             if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 
     503//             { 
     504//                 debugWarning( "Number of channels " 
     505//                               "mismatch: '%s' plug discovering reported " 
     506//                               "%d channels for cluster '%s', while stream " 
     507//                               "format reported %d\n", 
     508//                               getName(), 
     509//                               nrOfChannels, 
     510//                               clusterInfo->m_name.c_str(), 
     511//                               streamFormatInfo->m_numberOfChannels); 
     512//             } 
     513//             clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 
     514//  
     515//             debugOutput( DEBUG_LEVEL_VERBOSE, 
     516//                          "%s plug %d cluster info %d ('%s'): " 
     517//                          "stream format %d\n", 
     518//                          getName(), 
     519//                          m_id, 
     520//                          i, 
     521//                          clusterInfo->m_name.c_str(), 
     522//                          clusterInfo->m_streamFormat ); 
     523//         } 
     524//     } 
     525//  
     526//     FormatInformationStreamsSync* syncStream 
     527//         = dynamic_cast< FormatInformationStreamsSync* > ( 
     528//             formatInfo->m_streams ); 
     529//     if ( syncStream ) { 
     530//         m_samplingFrequency = 
     531//             syncStream->m_samplingFrequency; 
     532//         debugOutput( DEBUG_LEVEL_VERBOSE, 
     533//                      "%s plug %d is sync stream with sampling frequency %d\n", 
     534//                      getName(), 
     535//                      m_id, 
     536//                      m_samplingFrequency ); 
     537//     } 
     538//  
     539//  
     540//     if ( !compoundStream && !syncStream ) 
     541//     { 
     542//         debugError( "Unsupported stream format\n" ); 
     543//         return false; 
     544//     } 
     545//  
     546//     return true; 
     547// } 
     548//  
     549// bool 
     550// Plug::discoverSupportedStreamFormats() 
     551// { 
     552//     ExtendedStreamFormatCmd extStreamFormatCmd = 
     553//         setPlugAddrToStreamFormatCmd( 
     554//             ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 
     555//     extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     556//  
     557//     int i = 0; 
     558//     bool cmdSuccess = false; 
     559//  
     560//     do { 
     561//         extStreamFormatCmd.setIndexInStreamFormat( i ); 
     562//         extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
     563//         cmdSuccess = extStreamFormatCmd.fire(); 
     564//         if ( cmdSuccess 
     565//              && ( extStreamFormatCmd.getResponse() 
     566//                   == AVCCommand::eR_Implemented ) ) 
     567//         { 
     568//             FormatInfo formatInfo; 
     569//             formatInfo.m_index = i; 
     570//             bool formatInfoIsValid = true; 
     571//  
     572//             FormatInformationStreamsSync* syncStream 
     573//                 = dynamic_cast< FormatInformationStreamsSync* > 
     574//                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
     575//             if ( syncStream ) { 
     576//                 formatInfo.m_samplingFrequency = 
     577//                     syncStream->m_samplingFrequency; 
     578//                 formatInfo.m_isSyncStream = true ; 
     579//             } 
     580//  
     581//             FormatInformationStreamsCompound* compoundStream 
     582//                 = dynamic_cast< FormatInformationStreamsCompound* > 
     583//                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
     584//             if ( compoundStream ) { 
     585//                 formatInfo.m_samplingFrequency = 
     586//                     compoundStream->m_samplingFrequency; 
     587//                 formatInfo.m_isSyncStream = false; 
     588//                 for ( int j = 0; 
     589//                       j < compoundStream->m_numberOfStreamFormatInfos; 
     590//                       ++j ) 
     591//                 { 
     592//                     switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 
     593//                     case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 
     594//                         formatInfo.m_audioChannels += 
     595//                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     596//                         break; 
     597//                     case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 
     598//                         formatInfo.m_audioChannels += 
     599//                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     600//                         break; 
     601//                     case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 
     602//                         formatInfo.m_midiChannels += 
     603//                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     604//                         break; 
     605//                     default: 
     606//                         formatInfoIsValid = false; 
     607//                         debugWarning("unknown stream format (0x%02x) for channel " 
     608//                                       "(%d)\n", 
     609//                                      compoundStream->m_streamFormatInfos[j]->m_streamFormat, 
     610//                                      j ); 
     611//                     } 
     612//                 } 
     613//             } 
     614//  
     615//             if ( formatInfoIsValid ) { 
     616//                 flushDebugOutput(); 
     617//                 debugOutput( DEBUG_LEVEL_VERBOSE, 
     618//                              "[%s:%d] formatInfo[%d].m_samplingFrequency " 
     619//                              "= %d\n", 
     620//                              getName(), m_id, 
     621//                              i, formatInfo.m_samplingFrequency ); 
     622//                 debugOutput( DEBUG_LEVEL_VERBOSE, 
     623//                              "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 
     624//                              getName(), m_id, 
     625//                              i, formatInfo.m_isSyncStream ); 
     626//                 debugOutput( DEBUG_LEVEL_VERBOSE, 
     627//                              "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 
     628//                              getName(), m_id, 
     629//                              i, formatInfo.m_audioChannels ); 
     630//                 debugOutput( DEBUG_LEVEL_VERBOSE, 
     631//                              "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 
     632//                              getName(), m_id, 
     633//                              i, formatInfo.m_midiChannels ); 
     634//                 m_formatInfos.push_back( formatInfo ); 
     635//                 flushDebugOutput(); 
     636//             } 
     637//         } 
     638//  
     639//         ++i; 
     640//     } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 
     641//                               == ExtendedStreamFormatCmd::eR_Implemented ) ); 
     642//  
     643//     return true; 
     644// } 
    644645 
    645646 
     
    760761} 
    761762 
    762 ExtendedPlugInfoCmd 
    763 Plug::setPlugAddrToPlugInfoCmd() 
    764 
    765     ExtendedPlugInfoCmd extPlugInfoCmd( m_unit->get1394Service() ); 
    766  
    767     switch( getSubunitType() ) { 
    768     case eST_Unit: 
    769         { 
    770             UnitPlugAddress::EPlugType ePlugType = 
    771                 UnitPlugAddress::ePT_Unknown; 
    772             switch ( m_addressType ) { 
    773                 case eAPA_PCR: 
    774                     ePlugType = UnitPlugAddress::ePT_PCR; 
    775                     break; 
    776                 case eAPA_ExternalPlug: 
    777                     ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
    778                     break; 
    779                 case eAPA_AsynchronousPlug: 
    780                     ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
    781                     break; 
    782                 default: 
    783                     ePlugType = UnitPlugAddress::ePT_Unknown; 
    784             } 
    785             UnitPlugAddress unitPlugAddress( ePlugType, 
    786                                              m_id ); 
    787             extPlugInfoCmd.setPlugAddress( 
    788                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    789                              PlugAddress::ePAM_Unit, 
    790                              unitPlugAddress ) ); 
    791         } 
    792         break; 
    793     case eST_Music: 
    794     case eST_Audio: 
    795         { 
    796             switch( m_addressType ) { 
    797             case eAPA_SubunitPlug: 
    798             { 
    799                 SubunitPlugAddress subunitPlugAddress( m_id ); 
    800                 extPlugInfoCmd.setPlugAddress( 
    801                     PlugAddress( 
    802                         convertPlugDirection( getPlugDirection() ), 
    803                         PlugAddress::ePAM_Subunit, 
    804                         subunitPlugAddress ) ); 
    805             } 
    806             break; 
    807             case eAPA_FunctionBlockPlug: 
    808             { 
    809                 FunctionBlockPlugAddress functionBlockPlugAddress( 
    810                     m_functionBlockType, 
    811                     m_functionBlockId, 
    812                     m_id ); 
    813                 extPlugInfoCmd.setPlugAddress( 
    814                     PlugAddress( 
    815                         convertPlugDirection( getPlugDirection() ), 
    816                         PlugAddress::ePAM_FunctionBlock, 
    817                         functionBlockPlugAddress ) ); 
    818             } 
    819             break; 
    820             default: 
    821                 extPlugInfoCmd.setPlugAddress(PlugAddress()); 
    822             } 
    823         } 
    824         break; 
    825     default: 
    826         debugError( "Unknown subunit type\n" ); 
    827     } 
    828  
    829     extPlugInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    830     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    831     extPlugInfoCmd.setSubunitId( getSubunitId() ); 
    832     extPlugInfoCmd.setSubunitType( getSubunitType() ); 
    833  
    834     return extPlugInfoCmd; 
    835 
    836  
    837 ExtendedStreamFormatCmd 
    838 Plug::setPlugAddrToStreamFormatCmd( 
    839     ExtendedStreamFormatCmd::ESubFunction subFunction) 
    840 
    841     ExtendedStreamFormatCmd extStreamFormatInfoCmd( 
    842         m_unit->get1394Service(), 
    843         subFunction ); 
    844     switch( getSubunitType() ) { 
    845     case eST_Unit: 
    846     { 
    847             UnitPlugAddress::EPlugType ePlugType = 
    848                 UnitPlugAddress::ePT_Unknown; 
    849             switch ( m_addressType ) { 
    850                 case eAPA_PCR: 
    851                     ePlugType = UnitPlugAddress::ePT_PCR; 
    852                     break; 
    853                 case eAPA_ExternalPlug: 
    854                     ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
    855                     break; 
    856                 case eAPA_AsynchronousPlug: 
    857                     ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
    858                     break; 
    859                 default: 
    860                     ePlugType = UnitPlugAddress::ePT_Unknown; 
    861             } 
    862         UnitPlugAddress unitPlugAddress( ePlugType, 
    863                                          m_id ); 
    864         extStreamFormatInfoCmd.setPlugAddress( 
    865             PlugAddress( convertPlugDirection( getPlugDirection() ), 
    866                          PlugAddress::ePAM_Unit, 
    867                          unitPlugAddress ) ); 
    868         } 
    869         break; 
    870     case eST_Music: 
    871     case eST_Audio: 
    872     { 
    873         switch( m_addressType ) { 
    874         case eAPA_SubunitPlug: 
    875         { 
    876             SubunitPlugAddress subunitPlugAddress( m_id ); 
    877             extStreamFormatInfoCmd.setPlugAddress( 
    878                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    879                              PlugAddress::ePAM_Subunit, 
    880                              subunitPlugAddress ) ); 
    881         } 
    882         break; 
    883         case eAPA_FunctionBlockPlug: 
    884         { 
    885             FunctionBlockPlugAddress functionBlockPlugAddress( 
    886                 m_functionBlockType, 
    887                 m_functionBlockId, 
    888                 m_id ); 
    889             extStreamFormatInfoCmd.setPlugAddress( 
    890                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    891                              PlugAddress::ePAM_FunctionBlock, 
    892                              functionBlockPlugAddress ) ); 
    893         } 
    894         break; 
    895         default: 
    896             extStreamFormatInfoCmd.setPlugAddress(PlugAddress()); 
    897         } 
    898     } 
    899     break; 
    900     default: 
    901         debugError( "Unknown subunit type\n" ); 
    902     } 
    903  
    904     extStreamFormatInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    905     extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    906     extStreamFormatInfoCmd.setSubunitId( getSubunitId() ); 
    907     extStreamFormatInfoCmd.setSubunitType( getSubunitType() ); 
    908  
    909     return extStreamFormatInfoCmd; 
    910 
    911  
    912 
     763
  • branches/echoaudio/src/bebob/bebob_avplug.h

    r507 r524  
    7474    bool discoverChannelName(); 
    7575    bool discoverClusterInfo(); 
    76     bool discoverStreamFormat(); 
    77     bool discoverSupportedStreamFormats(); 
    7876    bool discoverConnectionsInput(); 
    7977    bool discoverConnectionsOutput(); 
    80  
    81     AVC::ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd(); 
    82  
    83     AVC::ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd( 
    84             AVC::ExtendedStreamFormatCmd::ESubFunction subFunction); 
    8578 
    8679private: 
  • branches/echoaudio/src/genericavc/avc_avdevice.cpp

    r504 r524  
    11/* 
    22 * Copyright (C) 2005-2007 by Pieter Palmers 
     3 * Copyright (C) 2005-2007 by Daniel Wagner 
    34 * 
    45 * This file is part of FFADO 
     
    3031 
    3132#include "libavc/avc_definitions.h" 
     33#include "libavc/general/avc_plug_info.h" 
    3234 
    3335#include "debugmodule/debugmodule.h" 
     
    4244#include <libraw1394/csr.h> 
    4345 
     46using namespace AVC; 
     47 
    4448namespace GenericAVC { 
     49 
     50IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); 
    4551 
    4652// to define the supported devices 
     
    105111    } 
    106112 
    107     if (m_model != NULL) { 
    108         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
    109                 m_model->vendor_name, m_model->model_name); 
    110         return true; 
    111     } 
    112  
    113     return false; 
     113    if (m_model == NULL) { 
     114        return false; 
     115    } 
     116    debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
     117            m_model->vendor_name, m_model->model_name); 
     118 
     119    if ( !Unit::discover() ) { 
     120        debugError( "Could not discover unit\n" ); 
     121        return false; 
     122    } 
     123 
     124    if((getAudioSubunit( 0 ) == NULL)) { 
     125        debugError( "Unit doesn't have an Audio subunit.\n"); 
     126        return false; 
     127    } 
     128    if((getMusicSubunit( 0 ) == NULL)) { 
     129        debugError( "Unit doesn't have a Music subunit.\n"); 
     130        return false; 
     131    } 
     132 
     133    return true; 
    114134} 
    115135 
    116136int 
    117137AvDevice::getSamplingFrequency( ) { 
    118     return 0; 
    119 
    120  
    121 bool 
    122 AvDevice::setSamplingFrequency( int samplingFrequency ) 
    123 
    124  
     138    AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
     139    if ( !inputPlug ) { 
     140        debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
     141        return false; 
     142    } 
     143    AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 
     144    if ( !outputPlug ) { 
     145        debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     146        return false; 
     147    } 
     148 
     149    int samplerate_playback=inputPlug->getSampleRate(); 
     150    int samplerate_capture=outputPlug->getSampleRate(); 
     151 
     152    if (samplerate_playback != samplerate_capture) { 
     153        debugWarning("Samplerates for capture and playback differ!\n"); 
     154    } 
     155    return samplerate_capture; 
     156
     157 
     158bool 
     159AvDevice::setSamplingFrequency( int s ) 
     160
     161    ESamplingFrequency samplingFrequency=parseSampleRate( s ); 
     162    bool snoopMode=false; 
     163    if(!getOption("snoopMode", snoopMode)) { 
     164        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     165    } 
     166 
     167    if(snoopMode) { 
     168        int current_sr=getSamplingFrequency(); 
     169        if (current_sr != convertESamplingFrequency( samplingFrequency ) ) { 
     170            debugError("In snoop mode it is impossible to set the sample rate.\n"); 
     171            debugError("Please start the client with the correct setting.\n"); 
     172            return false; 
     173        } 
     174        return true; 
     175    } else { 
     176        AVC::Plug* plug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
     177        if ( !plug ) { 
     178            debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
     179            return false; 
     180        } 
     181 
     182        if ( !plug->setSampleRate( convertESamplingFrequency( samplingFrequency ) ) ) 
     183        { 
     184            debugError( "setSampleRate: Setting sample rate failed\n" ); 
     185            return false; 
     186        } 
     187 
     188        plug = getPlugById( m_pcrPlugs, Plug::eAPD_Output,  0 ); 
     189        if ( !plug ) { 
     190            debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     191            return false; 
     192        } 
     193 
     194        if ( !plug->setSampleRate( convertESamplingFrequency( samplingFrequency ) ) ) 
     195        { 
     196            debugError( "setSampleRate: Setting sample rate failed\n" ); 
     197            return false; 
     198        } 
     199 
     200        debugOutput( DEBUG_LEVEL_VERBOSE, 
     201                     "setSampleRate: Set sample rate to %d\n", 
     202                     convertESamplingFrequency( samplingFrequency ) ); 
     203        return true; 
     204    } 
     205    // not executable 
    125206    return false; 
     207 
    126208} 
    127209 
    128210bool 
    129211AvDevice::lock() { 
     212    bool snoopMode=false; 
     213    if(!getOption("snoopMode", snoopMode)) { 
     214        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     215    } 
     216 
     217    if (snoopMode) { 
     218        // don't lock 
     219    } else { 
     220//         return Unit::reserve(4); 
     221    } 
    130222 
    131223    return true; 
    132224} 
    133225 
    134  
    135226bool 
    136227AvDevice::unlock() { 
    137  
     228    bool snoopMode=false; 
     229    if(!getOption("snoopMode", snoopMode)) { 
     230        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     231    } 
     232 
     233    if (snoopMode) { 
     234        // don't unlock 
     235    } else { 
     236//         return Unit::reserve(0); 
     237    } 
    138238    return true; 
    139239} 
     
    145245        "%s %s at node %d\n", m_model->vendor_name, m_model->model_name, 
    146246        m_nodeId); 
     247 
     248    m_pPlugManager->showPlugs(); 
     249    flushDebugOutput(); 
    147250} 
    148251 
    149252bool 
    150253AvDevice::prepare() { 
    151  
     254    bool snoopMode=false; 
     255    if(!getOption("snoopMode", snoopMode)) { 
     256        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     257    } 
     258 
     259    /////////// 
     260    // get plugs 
     261 
     262    AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
     263    if ( !inputPlug ) { 
     264        debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
     265        return false; 
     266    } 
     267    AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 
     268    if ( !outputPlug ) { 
     269        debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     270        return false; 
     271    } 
     272 
     273    int samplerate=outputPlug->getSampleRate(); 
     274 
     275    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing receive processor...\n"); 
     276    // create & add streamprocessors 
     277    Streaming::StreamProcessor *p; 
     278 
     279    p=new Streaming::AmdtpReceiveStreamProcessor( 
     280                             get1394Service().getPort(), 
     281                             samplerate, 
     282                             outputPlug->getNrOfChannels()); 
     283 
     284    if(!p->init()) { 
     285        debugFatal("Could not initialize receive processor!\n"); 
     286        delete p; 
     287        return false; 
     288    } 
     289 
     290    if (!addPlugToProcessor(*outputPlug,p, 
     291        Streaming::Port::E_Capture)) { 
     292        debugFatal("Could not add plug to processor!\n"); 
     293        delete p; 
     294        return false; 
     295    } 
     296 
     297    m_receiveProcessors.push_back(p); 
     298 
     299    // do the transmit processor 
     300    debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing transmit processor%s...\n", 
     301            (snoopMode?" in snoop mode":"")); 
     302    if (snoopMode) { 
     303        // we are snooping, so this is receive too. 
     304        p=new Streaming::AmdtpReceiveStreamProcessor( 
     305                                  get1394Service().getPort(), 
     306                                  samplerate, 
     307                                  inputPlug->getNrOfChannels()); 
     308    } else { 
     309        p=new Streaming::AmdtpTransmitStreamProcessor( 
     310                                get1394Service().getPort(), 
     311                                samplerate, 
     312                                inputPlug->getNrOfChannels()); 
     313    } 
     314 
     315    if(!p->init()) { 
     316        debugFatal("Could not initialize transmit processor %s!\n", 
     317            (snoopMode?" in snoop mode":"")); 
     318        delete p; 
     319        return false; 
     320    } 
     321 
     322    if (snoopMode) { 
     323        if (!addPlugToProcessor(*inputPlug,p, 
     324            Streaming::Port::E_Capture)) { 
     325            debugFatal("Could not add plug to processor!\n"); 
     326            return false; 
     327        } 
     328    } else { 
     329        if (!addPlugToProcessor(*inputPlug,p, 
     330            Streaming::Port::E_Playback)) { 
     331            debugFatal("Could not add plug to processor!\n"); 
     332            return false; 
     333        } 
     334    } 
     335 
     336    // we put this SP into the transmit SP vector, 
     337    // no matter if we are in snoop mode or not 
     338    // this allows us to find out what direction 
     339    // a certain stream should have. 
     340    m_transmitProcessors.push_back(p); 
     341 
     342    return true; 
     343
     344 
     345bool 
     346AvDevice::addPlugToProcessor( 
     347    AVC::Plug& plug, 
     348    Streaming::StreamProcessor *processor, 
     349    Streaming::AmdtpAudioPort::E_Direction direction) { 
     350         
     351    debugOutput(DEBUG_LEVEL_VERBOSE, " Adding plug %s to processor\n", plug.getName()); 
     352 
     353    std::string id=std::string("dev?"); 
     354    if(!getOption("id", id)) { 
     355        debugWarning("Could not retrieve id parameter, defauling to 'dev?'\n"); 
     356    } 
     357 
     358    Plug::ClusterInfoVector& clusterInfos = plug.getClusterInfos(); 
     359    for ( Plug::ClusterInfoVector::const_iterator it = clusterInfos.begin(); 
     360          it != clusterInfos.end(); 
     361          ++it ) 
     362    { 
     363        const Plug::ClusterInfo* clusterInfo = &( *it ); 
     364         
     365        debugOutput(DEBUG_LEVEL_VERBOSE, " Adding cluster %s\n", clusterInfo->m_name.c_str()); 
     366 
     367        Plug::ChannelInfoVector channelInfos = clusterInfo->m_channelInfos; 
     368        for ( Plug::ChannelInfoVector::const_iterator it = channelInfos.begin(); 
     369              it != channelInfos.end(); 
     370              ++it ) 
     371        { 
     372 
     373            const Plug::ChannelInfo* channelInfo = &( *it ); 
     374             
     375            std::ostringstream portname; 
     376 
     377            portname << id << "_" << channelInfo->m_name; 
     378 
     379            Streaming::Port *p=NULL; 
     380            switch(clusterInfo->m_portType) { 
     381            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Speaker: 
     382            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Headphone: 
     383            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Microphone: 
     384            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Line: 
     385            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Analog: 
     386                debugOutput(DEBUG_LEVEL_VERBOSE, " Adding audio channel %s (pos=0x%02X, loc=0x%02X)\n", 
     387                    channelInfo->m_name.c_str(), channelInfo->m_streamPosition, channelInfo->m_location); 
     388                p=new Streaming::AmdtpAudioPort( 
     389                        portname.str(), 
     390                        direction, 
     391                        channelInfo->m_streamPosition, 
     392                        channelInfo->m_location, 
     393                        Streaming::AmdtpPortInfo::E_MBLA 
     394                ); 
     395                break; 
     396 
     397            case ExtendedPlugInfoClusterInfoSpecificData::ePT_MIDI: 
     398                debugOutput(DEBUG_LEVEL_VERBOSE, " Adding MIDI channel %s (pos=0x%02X, loc=0x%02X)\n", 
     399                    channelInfo->m_name.c_str(), channelInfo->m_streamPosition, processor->getPortCount(Streaming::Port::E_Midi)); 
     400                p=new Streaming::AmdtpMidiPort( 
     401                        portname.str(), 
     402                        direction, 
     403                        // HACK: for audiofire2 only !!! 
     404                        (direction==Streaming::Port::E_Capture?4:6), 
     405//                         channelInfo->m_streamPosition, 
     406                        // Workaround for out-of-spec hardware 
     407                        // should be: 
     408                        // channelInfo->m_location, 
     409                        // but now we renumber the midi channels' location as they 
     410                        // are discovered 
     411                        processor->getPortCount(Streaming::Port::E_Midi), 
     412                        Streaming::AmdtpPortInfo::E_Midi 
     413                ); 
     414 
     415                break; 
     416            case ExtendedPlugInfoClusterInfoSpecificData::ePT_SPDIF: 
     417            case ExtendedPlugInfoClusterInfoSpecificData::ePT_ADAT: 
     418            case ExtendedPlugInfoClusterInfoSpecificData::ePT_TDIF: 
     419            case ExtendedPlugInfoClusterInfoSpecificData::ePT_MADI: 
     420            case ExtendedPlugInfoClusterInfoSpecificData::ePT_Digital: 
     421            case ExtendedPlugInfoClusterInfoSpecificData::ePT_NoType: 
     422            default: 
     423            // unsupported 
     424                break; 
     425            } 
     426 
     427            if (!p) { 
     428                debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",channelInfo->m_name.c_str()); 
     429            } else { 
     430 
     431                if (!processor->addPort(p)) { 
     432                    debugWarning("Could not register port with stream processor\n"); 
     433                    return false; 
     434                } 
     435            } 
     436         } 
     437    } 
    152438    return true; 
    153439} 
     
    155441int 
    156442AvDevice::getStreamCount() { 
    157     return 0
     443    return m_receiveProcessors.size() + m_transmitProcessors.size()
    158444} 
    159445 
     
    161447AvDevice::getStreamProcessorByIndex(int i) { 
    162448 
     449    if (i<(int)m_receiveProcessors.size()) { 
     450        return m_receiveProcessors.at(i); 
     451    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 
     452        return m_transmitProcessors.at(i-m_receiveProcessors.size()); 
     453    } 
     454 
    163455    return NULL; 
    164456} 
     
    166458bool 
    167459AvDevice::startStreamByIndex(int i) { 
     460    int iso_channel=-1; 
     461    bool snoopMode=false; 
     462    if(!getOption("snoopMode", snoopMode)) { 
     463        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     464    } 
     465 
     466    if (i<(int)m_receiveProcessors.size()) { 
     467        int n=i; 
     468        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
     469 
     470        if(snoopMode) { // a stream from the device to another host 
     471            // FIXME: put this into a decent framework! 
     472            // we should check the oPCR[n] on the device 
     473            struct iec61883_oPCR opcr; 
     474            if (iec61883_get_oPCRX( 
     475                    get1394Service().getHandle(), 
     476                    m_pConfigRom->getNodeId() | 0xffc0, 
     477                    (quadlet_t *)&opcr, 
     478                    n)) { 
     479 
     480                debugWarning("Error getting the channel for SP %d\n",i); 
     481                return false; 
     482            } 
     483 
     484            iso_channel=opcr.channel; 
     485        } else { 
     486            iso_channel=get1394Service().allocateIsoChannelCMP( 
     487                m_pConfigRom->getNodeId() | 0xffc0, n, 
     488                get1394Service().getLocalNodeId()| 0xffc0, -1); 
     489        } 
     490        if (iso_channel<0) { 
     491            debugError("Could not allocate ISO channel for SP %d\n",i); 
     492            return false; 
     493        } 
     494 
     495        debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 
     496 
     497        p->setChannel(iso_channel); 
     498        return true; 
     499 
     500    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 
     501        int n=i-m_receiveProcessors.size(); 
     502        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
     503 
     504        if(snoopMode) { // a stream from another host to the device 
     505            // FIXME: put this into a decent framework! 
     506            // we should check the iPCR[n] on the device 
     507            struct iec61883_iPCR ipcr; 
     508            if (iec61883_get_iPCRX( 
     509                    get1394Service().getHandle(), 
     510                    m_pConfigRom->getNodeId() | 0xffc0, 
     511                    (quadlet_t *)&ipcr, 
     512                    n)) { 
     513 
     514                debugWarning("Error getting the channel for SP %d\n",i); 
     515                return false; 
     516            } 
     517 
     518            iso_channel=ipcr.channel; 
     519 
     520        } else { 
     521            iso_channel=get1394Service().allocateIsoChannelCMP( 
     522                get1394Service().getLocalNodeId()| 0xffc0, -1, 
     523                m_pConfigRom->getNodeId() | 0xffc0, n); 
     524        } 
     525 
     526        if (iso_channel<0) { 
     527            debugError("Could not allocate ISO channel for SP %d\n",i); 
     528            return false; 
     529        } 
     530 
     531        debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 
     532 
     533        p->setChannel(iso_channel); 
     534        return true; 
     535    } 
     536 
     537    debugError("SP index %d out of range!\n",i); 
    168538    return false; 
    169539} 
     
    171541bool 
    172542AvDevice::stopStreamByIndex(int i) { 
     543    bool snoopMode=false; 
     544    if(!getOption("snoopMode", snoopMode)) { 
     545        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     546    } 
     547 
     548    if (i<(int)m_receiveProcessors.size()) { 
     549        int n=i; 
     550        Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 
     551 
     552        if(snoopMode) { 
     553 
     554        } else { 
     555            // deallocate ISO channel 
     556            if(!get1394Service().freeIsoChannel(p->getChannel())) { 
     557                debugError("Could not deallocate iso channel for SP %d\n",i); 
     558                return false; 
     559            } 
     560        } 
     561        p->setChannel(-1); 
     562 
     563        return true; 
     564 
     565    } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 
     566        int n=i-m_receiveProcessors.size(); 
     567        Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 
     568 
     569        if(snoopMode) { 
     570 
     571        } else { 
     572            // deallocate ISO channel 
     573            if(!get1394Service().freeIsoChannel(p->getChannel())) { 
     574                debugError("Could not deallocate iso channel for SP %d\n",i); 
     575                return false; 
     576            } 
     577        } 
     578        p->setChannel(-1); 
     579 
     580        return true; 
     581    } 
     582 
     583    debugError("SP index %d out of range!\n",i); 
    173584    return false; 
    174585} 
  • branches/echoaudio/src/genericavc/avc_avdevice.h

    r504 r524  
    11/* 
    22 * Copyright (C) 2005-2007 by Pieter Palmers 
     3 * Copyright (C) 2005-2007 by Daniel Wagner 
    34 * 
    45 * This file is part of FFADO 
     
    2829 
    2930#include "debugmodule/debugmodule.h" 
     31 
    3032#include "libavc/avc_definitions.h" 
     33#include "libavc/general/avc_unit.h" 
     34#include "libavc/general/avc_subunit.h" 
     35#include "libavc/general/avc_plug.h" 
     36 
     37#include "libstreaming/AmdtpStreamProcessor.h" 
     38#include "libstreaming/AmdtpPort.h" 
     39#include "libstreaming/AmdtpPortInfo.h" 
    3140 
    3241class ConfigRom; 
     
    4352}; 
    4453 
    45 class AvDevice : public FFADODevice
     54class AvDevice : public FFADODevice, public AVC::Unit
    4655public: 
    4756    AvDevice( std::auto_ptr<ConfigRom>( configRom ), 
     
    6776    bool startStreamByIndex(int i); 
    6877    bool stopStreamByIndex(int i); 
    69  
     78     
     79    // redefinition to resolve ambiguity 
     80    Ieee1394Service& get1394Service() 
     81        { return FFADODevice::get1394Service(); }; 
     82    ConfigRom& getConfigRom() const  
     83        { return FFADODevice::getConfigRom(); }; 
     84         
    7085protected: 
     86    bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, 
     87                             Streaming::AmdtpAudioPort::E_Direction direction); 
     88    bool setSamplingFrequencyPlug( AVC::Plug& plug, 
     89                                   AVC::Plug::EPlugDirection direction, 
     90                                   AVC::ESamplingFrequency samplingFrequency ); 
     91     
    7192    struct VendorModelEntry *m_model; 
    72  
     93     
     94    // streaming stuff 
     95    typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector; 
     96    StreamProcessorVector m_receiveProcessors; 
     97    StreamProcessorVector m_transmitProcessors; 
     98     
     99    DECLARE_DEBUG_MODULE; 
    73100}; 
    74101 
  • branches/echoaudio/src/libavc/avc_definitions.cpp

    r505 r524  
    2323 
    2424#include "avc_definitions.h" 
    25  
     25#include <libiec61883/iec61883.h> 
    2626 
    2727namespace AVC { 
     
    154154}; 
    155155 
    156  
    157 
     156enum ESubunitType byteToSubunitType(byte_t s) { 
     157    switch (s) { 
     158    case eST_Monitor: 
     159        return eST_Monitor; 
     160    case eST_Audio: 
     161        return eST_Audio; 
     162    case eST_Printer: 
     163        return eST_Printer; 
     164    case eST_Disc: 
     165        return eST_Disc; 
     166    case eST_VCR: 
     167        return eST_VCR; 
     168    case eST_Tuner: 
     169        return eST_Tuner; 
     170    case eST_CA: 
     171        return eST_CA; 
     172    case eST_Camera: 
     173        return eST_Camera; 
     174    case eST_Panel: 
     175        return eST_Panel; 
     176    case eST_BulltinBoard: 
     177        return eST_BulltinBoard; 
     178    case eST_CameraStorage: 
     179        return eST_CameraStorage; 
     180    case eST_Music: 
     181        return eST_Music; 
     182    case eST_VendorUnique: 
     183        return eST_VendorUnique; 
     184    case eST_Reserved: 
     185        return eST_Reserved; 
     186    case eST_Extended: 
     187        return eST_Extended; 
     188    default: 
     189    case eST_Unit: 
     190        return eST_Unit; 
     191    } 
     192
     193 
     194unsigned int fdfSfcToSampleRate(byte_t fdf) { 
     195    switch(fdf & 0x07) { 
     196        default:                       return 0; 
     197        case IEC61883_FDF_SFC_32KHZ:   return 32000; 
     198        case IEC61883_FDF_SFC_44K1HZ:  return 44100; 
     199        case IEC61883_FDF_SFC_48KHZ:   return 48000; 
     200        case IEC61883_FDF_SFC_88K2HZ:  return 88200; 
     201        case IEC61883_FDF_SFC_96KHZ:   return 96000; 
     202        case IEC61883_FDF_SFC_176K4HZ: return 176400; 
     203        case IEC61883_FDF_SFC_192KHZ:  return 192000; 
     204    } 
     205
     206 
     207byte_t sampleRateToFdfSfc(unsigned int rate) { 
     208    switch(rate) { 
     209        default:      return 0x07; 
     210        case 32000:   return IEC61883_FDF_SFC_32KHZ; 
     211        case 44100:   return IEC61883_FDF_SFC_44K1HZ; 
     212        case 48000:   return IEC61883_FDF_SFC_48KHZ; 
     213        case 88200:   return IEC61883_FDF_SFC_88K2HZ; 
     214        case 96000:   return IEC61883_FDF_SFC_96KHZ; 
     215        case 176400:  return IEC61883_FDF_SFC_176K4HZ; 
     216        case 192000:  return IEC61883_FDF_SFC_192KHZ; 
     217    } 
     218
     219 
     220
  • branches/echoaudio/src/libavc/avc_definitions.h

    r504 r524  
    2222 */ 
    2323 
    24 #ifndef AVDDEFINITIONS_H 
    25 #define AVDDEFINITIONS_H 
     24#ifndef AVCDEFINITIONS_H 
     25#define AVCDEFINITIONS_H 
    2626 
    2727#include <libavc1394/avc1394.h> 
     
    116116}; 
    117117 
     118enum ESubunitType byteToSubunitType(byte_t s); 
     119 
    118120/** 
    119121 * \brief the possible sampling frequencies 
     
    151153std::ostream& operator<<( std::ostream& stream, ESamplingFrequency samplingFrequency ); 
    152154 
     155/** 
     156 * \brief Convert from a FDF SFC field value to an integer sample rate 
     157 * @param fdf fdf sfc field value 
     158 * @return sample rate 
     159 */ 
     160unsigned int fdfSfcToSampleRate(byte_t fdf); 
     161 
     162/** 
     163 * \brief Convert from an integer sample rate to a78 FDF SFC field value 
     164 * @param rate integer sample rate 
     165 * @return fdf sfc field value 
     166 */ 
     167byte_t sampleRateToFdfSfc(unsigned int rate); 
     168 
    153169} 
    154170 
    155 #endif // AVDDEFINITIONS_H 
     171#endif // AVCDEFINITIONS_H 
  • branches/echoaudio/src/libavc/descriptors/avc_descriptor.cpp

    r503 r524  
    2525#include "avc_descriptor_cmd.h" 
    2626 
     27#include "../general/avc_unit.h" 
     28#include "../general/avc_subunit.h" 
     29 
    2730#include "../util/avc_serialize.h" 
    2831#include "libieee1394/ieee1394service.h" 
     32#include "libieee1394/configrom.h" 
    2933 
    3034namespace AVC { 
     
    101105 
    102106//---------------------- 
    103 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service
     107AVCDescriptor::AVCDescriptor( Unit* unit
    104108    : IBusData() 
    105     , m_p1394Service( &ieee1394service ) 
    106     , m_nodeId( 0 ) 
    107     , m_subunit_type( eST_Unit ) 
    108     , m_subunit_id( 0x07 ) 
     109    , m_unit( unit ) 
     110    , m_subunit ( NULL ) 
    109111    , m_specifier ( AVCDescriptorSpecifier::eInvalid ) 
    110112    , m_data ( NULL ) 
    111113    , m_descriptor_length(0) 
    112 
    113 
    114  
    115 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service, 
    116                               fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId
     114    , m_loaded ( false ) 
     115
     116
     117 
     118AVCDescriptor::AVCDescriptor( Unit* unit, Subunit* subunit
    117119    : IBusData() 
    118     , m_p1394Service( &ieee1394service ) 
    119     , m_nodeId( nodeId ) 
    120     , m_subunit_type( subunitType ) 
    121     , m_subunit_id( subunitId ) 
     120    , m_unit( unit ) 
     121    , m_subunit ( subunit ) 
    122122    , m_specifier ( AVCDescriptorSpecifier::eInvalid ) 
    123123    , m_data ( NULL ) 
    124124    , m_descriptor_length(0) 
    125 
    126 
    127  
    128 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service, 
    129                               fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId
     125    , m_loaded ( false ) 
     126
     127
     128 
     129AVCDescriptor::AVCDescriptor( Unit* unit, Subunit* subunit
    130130                              AVCDescriptorSpecifier s ) 
    131131    : IBusData() 
    132     , m_p1394Service( &ieee1394service ) 
    133     , m_nodeId( nodeId ) 
    134     , m_subunit_type( subunitType ) 
    135     , m_subunit_id( subunitId ) 
     132    , m_unit( unit ) 
     133    , m_subunit ( subunit ) 
    136134    , m_specifier ( s ) 
    137135    , m_data ( NULL ) 
    138136    , m_descriptor_length(0) 
     137    , m_loaded ( false ) 
    139138{ 
    140139} 
     
    144143    if (m_data != NULL) free(m_data); 
    145144} 
     145bool 
     146AVCDescriptor::reload() 
     147{ 
     148    m_loaded=false; 
     149    return load(); 
     150} 
    146151 
    147152bool 
     
    149154{ 
    150155    bool result; 
    151     OpenDescriptorCmd openDescCmd(*m_p1394Service); 
     156     
     157    if (m_loaded) { 
     158        debugOutput(DEBUG_LEVEL_VERBOSE, "Descriptor already loaded, not re-loading...\n" ); 
     159        return true; 
     160    } 
     161     
     162    OpenDescriptorCmd openDescCmd(m_unit->get1394Service()); 
    152163 
    153164    debugOutput(DEBUG_LEVEL_VERBOSE, " Open descriptor (%s)\n",getDescriptorName()); 
    154165    openDescCmd.setMode( OpenDescriptorCmd::eRead ); 
    155166    openDescCmd.m_specifier=&m_specifier; 
    156     openDescCmd.setNodeId( m_nodeId ); 
     167    openDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    157168    openDescCmd.setCommandType( AVCCommand::eCT_Control ); 
    158169    openDescCmd.setSubunitType( getSubunitType() ); 
     
    168179     
    169180    debugOutput(DEBUG_LEVEL_VERBOSE, " Read status descriptor\n"); 
    170     ReadDescriptorCmd readDescCmd(*m_p1394Service); 
     181    ReadDescriptorCmd readDescCmd(m_unit->get1394Service()); 
    171182    readDescCmd.m_specifier=&m_specifier; 
    172     readDescCmd.setNodeId( m_nodeId ); 
     183    readDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    173184    readDescCmd.setCommandType( AVCCommand::eCT_Control ); 
    174185    readDescCmd.setSubunitType( getSubunitType() ); 
     
    210221        readDescCmd.clear(); 
    211222        readDescCmd.m_specifier=&m_specifier; 
    212         readDescCmd.setNodeId( m_nodeId ); 
     223        readDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    213224        readDescCmd.setCommandType( AVCCommand::eCT_Control ); 
    214225        readDescCmd.setSubunitType( getSubunitType() ); 
     
    251262    openDescCmd.setMode( OpenDescriptorCmd::eClose ); 
    252263    openDescCmd.m_specifier=&m_specifier; 
    253     openDescCmd.setNodeId( m_nodeId ); 
     264    openDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    254265    openDescCmd.setCommandType( AVCCommand::eCT_Control ); 
    255266    openDescCmd.setSubunitType( getSubunitType() ); 
     
    289300    } 
    290301#endif 
     302    m_loaded=true; 
    291303    return true; 
    292304} 
     
    309321    return new AVCDescriptor( *this ); 
    310322} 
    311 bool 
    312 AVCDescriptor::setSubunitType(ESubunitType subunitType) 
    313 { 
    314     m_subunit_type = subunitType; 
    315     return true; 
    316 } 
    317  
    318 bool 
    319 AVCDescriptor::setNodeId( fb_nodeid_t nodeId ) 
    320 { 
    321     m_nodeId = nodeId; 
    322     return true; 
    323 } 
    324  
    325 bool 
    326 AVCDescriptor::setSubunitId(subunit_id_t subunitId) 
    327 { 
    328     m_subunit_id = subunitId & 0x7; 
    329     return true; 
    330 } 
    331323 
    332324ESubunitType 
    333 AVCDescriptor::getSubunitType() 
    334 { 
    335     return m_subunit_type; 
    336 } 
    337  
    338 subunit_id_t 
    339 AVCDescriptor::getSubunitId() 
    340 { 
    341     return m_subunit_id
    342 } 
    343  
    344 bool 
    345 AVCDescriptor::setVerbose( int verboseLevel ) 
     325AVCDescriptor::getSubunitType() const 
     326{ 
     327    return (m_subunit==NULL?eST_Unit:m_subunit->getSubunitType());  
     328} 
     329 
     330subunit_id_t  
     331AVCDescriptor::getSubunitId() const 
     332{ 
     333    return (m_subunit==NULL?0xFF:m_subunit->getSubunitId())
     334} 
     335 
     336bool 
     337AVCDescriptor::setVerboseLevel( int verboseLevel ) 
    346338{ 
    347339    setDebugLevel(verboseLevel); 
  • branches/echoaudio/src/libavc/descriptors/avc_descriptor.h

    r503 r524  
    4747 
    4848namespace AVC { 
     49 
     50class Unit; 
     51class Subunit; 
    4952 
    5053class IOSSerialize; 
     
    112115 
    113116    // note: in the end these have to be protected 
    114     AVCDescriptor( Ieee1394Service& ieee1394service ); 
    115     AVCDescriptor( Ieee1394Service& ieee1394service, 
    116                    fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId  ); 
    117     AVCDescriptor( Ieee1394Service& ieee1394service, 
    118                    fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId, 
    119                    AVCDescriptorSpecifier s ); 
     117    AVCDescriptor( Unit* unit ); 
     118    AVCDescriptor( Unit* unit, Subunit* subunit  ); 
     119    AVCDescriptor( Unit* unit, Subunit* subunit, AVCDescriptorSpecifier s ); 
    120120    virtual ~AVCDescriptor(); 
    121121     
     
    123123     
    124124    void setSpecifier(AVCDescriptorSpecifier s) {m_specifier=s;}; 
    125      
    126     bool setNodeId( fb_nodeid_t nodeId ); 
    127     bool setSubunitType( ESubunitType subunitType ); 
    128     bool setSubunitId( subunit_id_t subunitId ); 
    129  
    130     ESubunitType getSubunitType(); 
    131     subunit_id_t getSubunitId(); 
    132  
    133     bool setVerbose( int verboseLevel ); 
     125 
     126    ESubunitType getSubunitType() const; 
     127    subunit_id_t getSubunitId() const; 
     128 
     129    bool setVerboseLevel( int verboseLevel ); 
    134130    int getVerboseLevel(); 
    135131 
     
    138134     
    139135    bool load(); 
     136    bool reload(); 
    140137     
    141138protected: 
    142139 
    143     Ieee1394Service* m_p1394Service; 
    144     fb_nodeid_t      m_nodeId; 
    145     ESubunitType     m_subunit_type; 
    146     subunit_id_t     m_subunit_id; 
     140    Unit*            m_unit; 
     141    Subunit*         m_subunit; 
    147142     
    148143    AVCDescriptorSpecifier m_specifier; 
    149144     
    150     byte_t        *m_data; 
    151     uint16_t    m_descriptor_length; 
    152  
    153 private: 
    154  
    155      
     145    byte_t*          m_data; 
     146    uint16_t         m_descriptor_length; 
     147     
     148    bool             m_loaded; 
     149 
    156150}; 
    157151 
  • branches/echoaudio/src/libavc/general/avc_connect.cpp

    r505 r524  
    4545ConnectCmd::serialize( IOSSerialize& se ) 
    4646{ 
    47     AVCCommand::serialize( se ); 
    48     return true; 
     47    bool result=true; 
     48    result &= AVCCommand::serialize( se ); 
     49    return result; 
    4950} 
    5051 
     
    5253ConnectCmd::deserialize( IISDeserialize& de ) 
    5354{ 
    54     AVCCommand::deserialize( de ); 
    55     return true; 
     55    bool result=true; 
     56    result &= AVCCommand::deserialize( de ); 
     57    return result; 
    5658} 
    5759 
  • branches/echoaudio/src/libavc/general/avc_plug.cpp

    r509 r524  
    2525#include "avc_plug.h" 
    2626#include "avc_unit.h" 
     27#include "avc_signal_format.h" 
     28 
    2729#include "libieee1394/configrom.h" 
    2830 
     
    123125 
    124126bool 
     127Plug::discover() 
     128{ 
     129 
     130    if ( !initFromDescriptor() ) { 
     131        debugError( "discover: Could not init plug from descriptor (%d,%d,%d,%d,%d)\n", 
     132                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     133//         return false; 
     134    } 
     135 
     136    if ( !discoverPlugType() ) { 
     137        debugError( "discover: Could not discover plug type (%d,%d,%d,%d,%d)\n", 
     138                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     139        return false; 
     140    } 
     141 
     142    if ( !discoverName() ) { 
     143        debugError( "Could not discover name (%d,%d,%d,%d,%d)\n", 
     144                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     145        return false; 
     146    } 
     147 
     148    if ( !discoverNoOfChannels() ) { 
     149        debugError( "Could not discover number of channels " 
     150                    "(%d,%d,%d,%d,%d)\n", 
     151                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     152        return false; 
     153    } 
     154 
     155    if ( !discoverChannelPosition() ) { 
     156        debugError( "Could not discover channel positions " 
     157                    "(%d,%d,%d,%d,%d)\n", 
     158                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     159        return false; 
     160    } 
     161 
     162    if ( !discoverChannelName() ) { 
     163        debugError( "Could not discover channel name " 
     164                    "(%d,%d,%d,%d,%d)\n", 
     165                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     166        return false; 
     167    } 
     168 
     169    if ( !discoverClusterInfo() ) { 
     170        debugError( "Could not discover channel name " 
     171                    "(%d,%d,%d,%d,%d)\n", 
     172                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     173        return false; 
     174    } 
     175 
     176    if ( !discoverStreamFormat() ) { 
     177        debugError( "Could not discover stream format " 
     178                    "(%d,%d,%d,%d,%d)\n", 
     179                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     180//         return false; 
     181    } 
     182 
     183    if ( !discoverSupportedStreamFormats() ) { 
     184        debugError( "Could not discover supported stream formats " 
     185                    "(%d,%d,%d,%d,%d)\n", 
     186                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     187//         return false; 
     188    } 
     189 
     190    return m_unit->getPlugManager().addPlug( *this ); 
     191} 
     192 
     193bool 
     194Plug::initFromDescriptor() 
     195{ 
     196    if(getSubunitType()==eST_Unit) { 
     197        debugOutput(DEBUG_LEVEL_VERBOSE, "Not loading unit plug from descriptor.\n"); 
     198        return true; 
     199    } else { 
     200        return m_subunit->initPlugFromDescriptor(*this); 
     201    } 
     202} 
     203 
     204bool 
     205Plug::discoverConnections() 
     206{ 
     207    return discoverConnectionsInput() && discoverConnectionsOutput(); 
     208} 
     209 
     210bool 
     211Plug::discoverPlugType() 
     212{ 
     213 
     214    return true; 
     215} 
     216 
     217bool 
     218Plug::discoverName() 
     219{ 
     220    // name already set 
     221    if (m_name != "") return true; 
     222     
     223    m_name = plugAddressTypeToString(getPlugAddressType()); 
     224    m_name += " "; 
     225    m_name += plugTypeToString(getPlugType()); 
     226    m_name += " "; 
     227    m_name += plugDirectionToString(getPlugDirection()); 
     228 
     229    return true; 
     230} 
     231 
     232bool 
     233Plug::discoverNoOfChannels() 
     234{ 
     235 
     236    return true; 
     237} 
     238 
     239bool 
     240Plug::discoverChannelPosition() 
     241{ 
     242 
     243    return true; 
     244} 
     245 
     246bool 
     247Plug::discoverChannelName() 
     248{ 
     249     
     250    return true; 
     251} 
     252 
     253bool 
     254Plug::discoverClusterInfo() 
     255{ 
     256 
     257    return true; 
     258} 
     259 
     260bool 
     261Plug::discoverStreamFormat() 
     262{ 
     263    ExtendedStreamFormatCmd extStreamFormatCmd = 
     264        setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
     265    extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     266 
     267    if ( !extStreamFormatCmd.fire() ) { 
     268        debugError( "stream format command failed\n" ); 
     269        return false; 
     270    } 
     271 
     272    if ( ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NoStreamFormat ) 
     273         || ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NotUsed ) ) 
     274    { 
     275        debugOutput( DEBUG_LEVEL_VERBOSE, 
     276                     "No stream format information available\n" ); 
     277        return true; 
     278    } 
     279 
     280    if ( !extStreamFormatCmd.getFormatInformation() ) { 
     281        debugWarning( "No stream format information for plug found -> skip\n" ); 
     282        return true; 
     283    } 
     284 
     285    if ( extStreamFormatCmd.getFormatInformation()->m_root 
     286           != FormatInformation::eFHR_AudioMusic  ) 
     287    { 
     288        debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 
     289        return true; 
     290    } 
     291 
     292    FormatInformation* formatInfo = 
     293        extStreamFormatCmd.getFormatInformation(); 
     294    FormatInformationStreamsCompound* compoundStream 
     295        = dynamic_cast< FormatInformationStreamsCompound* > ( 
     296            formatInfo->m_streams ); 
     297    if ( compoundStream ) { 
     298        m_samplingFrequency = 
     299            compoundStream->m_samplingFrequency; 
     300        debugOutput( DEBUG_LEVEL_VERBOSE, 
     301                     "%s plug %d uses " 
     302                     "sampling frequency %d, nr of stream infos = %d\n", 
     303                     getName(), 
     304                     m_id, 
     305                     m_samplingFrequency, 
     306                     compoundStream->m_numberOfStreamFormatInfos ); 
     307 
     308        for ( int i = 1; 
     309              i <= compoundStream->m_numberOfStreamFormatInfos; 
     310              ++i ) 
     311        { 
     312            ClusterInfo* clusterInfo = 
     313                const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 
     314 
     315            if ( !clusterInfo ) { 
     316                debugError( "No matching cluster " 
     317                            "info found for index %d\n",  i ); 
     318                    return false; 
     319            } 
     320            StreamFormatInfo* streamFormatInfo = 
     321                compoundStream->m_streamFormatInfos[ i - 1 ]; 
     322 
     323            debugOutput( DEBUG_LEVEL_VERBOSE, 
     324                         "number of channels = %d, stream format = %d\n", 
     325                         streamFormatInfo->m_numberOfChannels, 
     326                         streamFormatInfo->m_streamFormat ); 
     327 
     328            int nrOfChannels = clusterInfo->m_nrOfChannels; 
     329            if ( streamFormatInfo->m_streamFormat == 
     330                 FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 
     331            { 
     332                // 8 logical midi channels fit into 1 channel 
     333                nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 
     334            } 
     335            // sanity check 
     336            if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 
     337            { 
     338                debugWarning( "Number of channels " 
     339                              "mismatch: '%s' plug discovering reported " 
     340                              "%d channels for cluster '%s', while stream " 
     341                              "format reported %d\n", 
     342                              getName(), 
     343                              nrOfChannels, 
     344                              clusterInfo->m_name.c_str(), 
     345                              streamFormatInfo->m_numberOfChannels); 
     346            } 
     347            clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 
     348 
     349            debugOutput( DEBUG_LEVEL_VERBOSE, 
     350                         "%s plug %d cluster info %d ('%s'): " 
     351                         "stream format %d\n", 
     352                         getName(), 
     353                         m_id, 
     354                         i, 
     355                         clusterInfo->m_name.c_str(), 
     356                         clusterInfo->m_streamFormat ); 
     357        } 
     358    } 
     359 
     360    FormatInformationStreamsSync* syncStream 
     361        = dynamic_cast< FormatInformationStreamsSync* > ( 
     362            formatInfo->m_streams ); 
     363    if ( syncStream ) { 
     364        m_samplingFrequency = 
     365            syncStream->m_samplingFrequency; 
     366        debugOutput( DEBUG_LEVEL_VERBOSE, 
     367                     "%s plug %d is sync stream with sampling frequency %d\n", 
     368                     getName(), 
     369                     m_id, 
     370                     m_samplingFrequency ); 
     371    } 
     372 
     373 
     374    if ( !compoundStream && !syncStream ) 
     375    { 
     376        debugError( "Unsupported stream format\n" ); 
     377        return false; 
     378    } 
     379 
     380    return true; 
     381} 
     382 
     383bool 
     384Plug::discoverSupportedStreamFormats() 
     385{ 
     386    ExtendedStreamFormatCmd extStreamFormatCmd = 
     387        setPlugAddrToStreamFormatCmd( 
     388            ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 
     389    extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     390 
     391    int i = 0; 
     392    bool cmdSuccess = false; 
     393 
     394    do { 
     395        extStreamFormatCmd.setIndexInStreamFormat( i ); 
     396        extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
     397        cmdSuccess = extStreamFormatCmd.fire(); 
     398        if ( cmdSuccess 
     399             && ( extStreamFormatCmd.getResponse() 
     400                  == AVCCommand::eR_Implemented ) ) 
     401        { 
     402            FormatInfo formatInfo; 
     403            formatInfo.m_index = i; 
     404            bool formatInfoIsValid = true; 
     405 
     406            FormatInformationStreamsSync* syncStream 
     407                = dynamic_cast< FormatInformationStreamsSync* > 
     408                ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
     409            if ( syncStream ) { 
     410                formatInfo.m_samplingFrequency = 
     411                    syncStream->m_samplingFrequency; 
     412                formatInfo.m_isSyncStream = true ; 
     413            } 
     414 
     415            FormatInformationStreamsCompound* compoundStream 
     416                = dynamic_cast< FormatInformationStreamsCompound* > 
     417                ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
     418            if ( compoundStream ) { 
     419                formatInfo.m_samplingFrequency = 
     420                    compoundStream->m_samplingFrequency; 
     421                formatInfo.m_isSyncStream = false; 
     422                for ( int j = 0; 
     423                      j < compoundStream->m_numberOfStreamFormatInfos; 
     424                      ++j ) 
     425                { 
     426                    switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 
     427                    case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 
     428                        formatInfo.m_audioChannels += 
     429                            compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     430                        break; 
     431                    case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 
     432                        formatInfo.m_audioChannels += 
     433                            compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     434                        break; 
     435                    case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 
     436                        formatInfo.m_midiChannels += 
     437                            compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
     438                        break; 
     439                    default: 
     440                        formatInfoIsValid = false; 
     441                        debugWarning("unknown stream format (0x%02x) for channel " 
     442                                      "(%d)\n", 
     443                                     compoundStream->m_streamFormatInfos[j]->m_streamFormat, 
     444                                     j ); 
     445                    } 
     446                } 
     447            } 
     448 
     449            if ( formatInfoIsValid ) { 
     450                flushDebugOutput(); 
     451                debugOutput( DEBUG_LEVEL_VERBOSE, 
     452                             "[%s:%d] formatInfo[%d].m_samplingFrequency " 
     453                             "= %d\n", 
     454                             getName(), m_id, 
     455                             i, formatInfo.m_samplingFrequency ); 
     456                debugOutput( DEBUG_LEVEL_VERBOSE, 
     457                             "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 
     458                             getName(), m_id, 
     459                             i, formatInfo.m_isSyncStream ); 
     460                debugOutput( DEBUG_LEVEL_VERBOSE, 
     461                             "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 
     462                             getName(), m_id, 
     463                             i, formatInfo.m_audioChannels ); 
     464                debugOutput( DEBUG_LEVEL_VERBOSE, 
     465                             "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 
     466                             getName(), m_id, 
     467                             i, formatInfo.m_midiChannels ); 
     468                m_formatInfos.push_back( formatInfo ); 
     469                flushDebugOutput(); 
     470            } 
     471        } 
     472 
     473        ++i; 
     474    } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 
     475                              == ExtendedStreamFormatCmd::eR_Implemented ) ); 
     476 
     477    return true; 
     478} 
     479 
     480bool 
     481Plug::discoverConnectionsInput() 
     482{ 
     483    debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering incoming connections...\n"); 
     484 
     485    int sourcePlugGlobalId=getSignalSource(); 
     486     
     487    if(sourcePlugGlobalId >= 0) { 
     488        Plug *p=m_unit->getPlugManager().getPlug(sourcePlugGlobalId); 
     489        if (p==NULL) { 
     490            debugError( "Plug with global id %d not found\n",sourcePlugGlobalId ); 
     491            return false; 
     492        } 
     493        // connected to another plug 
     494        debugOutput( DEBUG_LEVEL_VERBOSE, "Plug '%s' gets signal from '%s'...\n", 
     495            getName(), p->getName() ); 
     496 
     497 
     498 
     499        if ( p ) { 
     500            debugOutput( DEBUG_LEVEL_VERBOSE, 
     501                        "'(%d) %s' has a connection to '(%d) %s'\n", 
     502                        getGlobalId(), 
     503                        getName(), 
     504                        p->getGlobalId(), 
     505                        p->getName() ); 
     506            addPlugConnection( m_inputConnections, *p ); 
     507        } else { 
     508            debugError( "no corresponding plug found for '(%d) %s'\n", 
     509                        getGlobalId(), 
     510                        getName() ); 
     511            return false; 
     512        } 
     513             
     514    } 
     515 
     516    return true; 
     517} 
     518 
     519bool 
     520Plug::discoverConnectionsOutput() 
     521{ 
     522    debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering outgoing connections...\n"); 
     523     
     524//     int i=0; 
     525//     int nbPlugs=m_unit->getPlugManager().getPlugCount(); 
     526//     debugOutput( DEBUG_LEVEL_VERBOSE, "checking %d plugs\n", nbPlugs); 
     527//      
     528//     for (i=0;i<nbPlugs;i++) { 
     529//         Plug *p=m_unit->getPlugManager().getPlug(i); 
     530//          
     531//         if(p==NULL) { 
     532//             debugError("could not get plug 0x%02X\n",i); 
     533//             continue; 
     534//         } 
     535//          
     536//         if(p->getGlobalId()==getGlobalId()) continue; // skip yourself 
     537//          
     538//  
     539//     } 
     540 
     541    return true; 
     542} 
     543 
     544bool 
    125545Plug::inquireConnnection( Plug& plug ) 
    126546{ 
     
    148568} 
    149569 
     570int 
     571Plug::getSignalSource() 
     572{ 
     573    if((getPlugAddressType() == eAPA_PCR) || 
     574       (getPlugAddressType() == eAPA_ExternalPlug)) { 
     575        if (getPlugDirection() != eAPD_Output) { 
     576            debugWarning("Signal Source command not valid for non-output unit plugs...\n"); 
     577            return -1; 
     578        } 
     579    } 
     580     
     581    if(getPlugAddressType() == eAPA_SubunitPlug) { 
     582        if (getPlugDirection() != eAPD_Input) { 
     583            debugWarning("Signal Source command not valid for non-input subunit plugs...\n"); 
     584            return -1; 
     585        } 
     586    } 
     587     
     588    SignalSourceCmd signalSourceCmd( m_unit->get1394Service() ); 
     589     
     590    signalSourceCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     591    signalSourceCmd.setSubunitType( eST_Unit  ); 
     592    signalSourceCmd.setSubunitId( 0xff ); 
     593 
     594    SignalSubunitAddress signalSubunitAddr; 
     595    signalSubunitAddr.m_subunitType = 0xFF; 
     596    signalSubunitAddr.m_subunitId = 0xFF; 
     597    signalSubunitAddr.m_plugId = 0xFE; 
     598    signalSourceCmd.setSignalSource( signalSubunitAddr ); 
     599     
     600    setDestPlugAddrToSignalCmd( signalSourceCmd, *this ); 
     601 
     602    signalSourceCmd.setCommandType( AVCCommand::eCT_Status ); 
     603    signalSourceCmd.setVerbose( getDebugLevel() ); 
     604    signalSourceCmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); 
     605 
     606    if ( !signalSourceCmd.fire() ) { 
     607        debugError( "Could not get signal source for '%s'\n", 
     608                    getName() ); 
     609        return -1; 
     610    } 
     611 
     612    if ( signalSourceCmd.getResponse() == AVCCommand::eR_Implemented ) { 
     613        SignalAddress* src=signalSourceCmd.getSignalSource(); 
     614        Plug* p=NULL; 
     615        if(dynamic_cast<SignalUnitAddress *>(src)) { 
     616            SignalUnitAddress *usrc=dynamic_cast<SignalUnitAddress *>(src); 
     617            if (usrc->m_plugId & 0x80) { 
     618                p=m_unit->getPlugManager().getPlug( eST_Unit, 0xFF,  
     619                        0xFF, 0xFF, eAPA_ExternalPlug, eAPD_Input,  
     620                        usrc->m_plugId & 0x7F ); 
     621            } else { 
     622                p=m_unit->getPlugManager().getPlug( eST_Unit, 0xFF,  
     623                        0xFF, 0xFF, eAPA_PCR, eAPD_Input,  
     624                        usrc->m_plugId & 0x7F ); 
     625            } 
     626        } else if (dynamic_cast<SignalSubunitAddress *>(src)) { 
     627            SignalSubunitAddress *susrc=dynamic_cast<SignalSubunitAddress *>(src); 
     628            p=m_unit->getPlugManager().getPlug( byteToSubunitType(susrc->m_subunitType),  
     629                    susrc->m_subunitId, 0xFF, 0xFF, eAPA_SubunitPlug,  
     630                    eAPD_Output, susrc->m_plugId); 
     631        } else return -1; 
     632         
     633        if (p==NULL) { 
     634            debugError("reported signal source plug not found\n"); 
     635            return -1; 
     636        } 
     637         
     638        return p->getGlobalId(); 
     639    } 
     640 
     641    return -1; 
     642} 
     643 
    150644bool 
    151645Plug::setConnection( Plug& plug ) 
     
    174668} 
    175669 
     670bool  
     671Plug::propagateFromConnectedPlug( ) { 
     672 
     673    if (getDirection() == eAPD_Output) { 
     674        if (getInputConnections().size()==0) { 
     675            debugWarning("No input connections to propagate from, skipping.\n"); 
     676            return true; 
     677        } 
     678        if (getInputConnections().size()>1) { 
     679            debugWarning("Too many input connections to propagate from, using first one.\n"); 
     680        } 
     681         
     682        Plug* p = *(getInputConnections().begin()); 
     683        return propagateFromPlug( p ); 
     684         
     685    } else if (getDirection() == eAPD_Input) { 
     686        if (getOutputConnections().size()==0) { 
     687            debugWarning("No output connections to propagate from, skipping.\n"); 
     688            return true; 
     689        } 
     690        if (getOutputConnections().size()>1) { 
     691            debugWarning("Too many output connections to propagate from, using first one.\n"); 
     692        } 
     693         
     694        Plug* p = *(getOutputConnections().begin()); 
     695        return propagateFromPlug( p ); 
     696         
     697    } else { 
     698        debugWarning("plug with undefined direction\n"); 
     699        return false; 
     700    } 
     701} 
     702 
     703bool  
     704Plug::propagateFromPlug( Plug *p ) { 
     705    debugOutput( DEBUG_LEVEL_VERBOSE, 
     706                 "Propagating info from plug '%s' to plug '%s'\n", 
     707                 p->getName(), getName() ); 
     708     
     709    if (m_clusterInfos.size()==0) { 
     710        m_clusterInfos=p->m_clusterInfos; 
     711    } 
     712     
     713    m_nrOfChannels=p->m_nrOfChannels; 
     714     
     715    return true; 
     716} 
     717 
    176718int 
    177719Plug::getNrOfStreams() const 
     
    194736} 
    195737 
     738bool 
     739Plug::setNrOfChannels(int i) 
     740{ 
     741    m_nrOfChannels=i; 
     742    return true; 
     743} 
     744 
    196745int 
    197746Plug::getSampleRate() const 
    198747{ 
     748    if(getPlugAddressType()==eAPA_PCR) { 
     749        if(getPlugDirection()==eAPD_Input) { 
     750            InputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 
     751            cmd.m_form=0xFF; 
     752            cmd.m_eoh=0xFF; 
     753            cmd.m_fmt=0xFF; 
     754            cmd.m_plug=getPlugId(); 
     755             
     756            cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     757            cmd.setSubunitType( eST_Unit  ); 
     758            cmd.setSubunitId( 0xff ); 
     759             
     760            cmd.setCommandType( AVCCommand::eCT_Status ); 
     761 
     762            if ( !cmd.fire() ) { 
     763                debugError( "input plug signal format command failed\n" ); 
     764                return 0; 
     765            } 
     766             
     767            if (cmd.m_fmt != 0x10 ) { 
     768                debugWarning("Incorrect FMT response received: 0x%02X\n",cmd.m_fmt); 
     769            } 
     770             
     771            return fdfSfcToSampleRate(cmd.m_fdf[0]); 
     772             
     773        } else if (getPlugDirection()==eAPD_Output) { 
     774            OutputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 
     775            cmd.m_form=0xFF; 
     776            cmd.m_eoh=0xFF; 
     777            cmd.m_fmt=0xFF; 
     778            cmd.m_plug=getPlugId(); 
     779             
     780            cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     781            cmd.setSubunitType( eST_Unit  ); 
     782            cmd.setSubunitId( 0xff ); 
     783     
     784            cmd.setCommandType( AVCCommand::eCT_Status ); 
     785             
     786            if ( !cmd.fire() ) { 
     787                debugError( "output plug signal format command failed\n" ); 
     788                return 0; 
     789            } 
     790             
     791            if (cmd.m_fmt != 0x10 ) { 
     792                debugWarning("Incorrect FMT response received: 0x%02X\n",cmd.m_fmt); 
     793            } 
     794             
     795            return fdfSfcToSampleRate(cmd.m_fdf[0]); 
     796         
     797        } else { 
     798            debugError("PCR plug with undefined direction.\n"); 
     799            return 0; 
     800        } 
     801    } 
     802     
     803    // fallback 
    199804    return convertESamplingFrequency( static_cast<ESamplingFrequency>( m_samplingFrequency ) ); 
     805} 
     806 
     807bool 
     808Plug::setSampleRate( int rate ) 
     809{ 
     810    // apple style 
     811    if(getPlugAddressType()==eAPA_PCR) { 
     812        if(getPlugDirection()==eAPD_Input) { 
     813            InputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 
     814            cmd.m_eoh=1; 
     815            cmd.m_form=0; 
     816            cmd.m_fmt=0x10; 
     817            cmd.m_plug=getPlugId(); 
     818            cmd.m_fdf[0]=sampleRateToFdfSfc(rate); 
     819            cmd.m_fdf[1]=0xFF; 
     820            cmd.m_fdf[2]=0xFF; 
     821 
     822            cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     823            cmd.setSubunitType( eST_Unit  ); 
     824            cmd.setSubunitId( 0xff ); 
     825             
     826            cmd.setCommandType( AVCCommand::eCT_Control ); 
     827 
     828            if ( !cmd.fire() ) { 
     829                debugError( "input plug signal format command failed\n" ); 
     830                return false; 
     831            } 
     832 
     833            if ( cmd.getResponse() == AVCCommand::eR_Accepted ) 
     834            { 
     835                return true; 
     836            } 
     837            debugWarning( "output plug signal format command not accepted\n" ); 
     838 
     839        } else if (getPlugDirection()==eAPD_Output) { 
     840            OutputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 
     841            cmd.m_eoh=1; 
     842            cmd.m_form=0; 
     843            cmd.m_fmt=0x10; 
     844            cmd.m_plug=getPlugId(); 
     845            cmd.m_fdf[0]=sampleRateToFdfSfc(rate); 
     846            cmd.m_fdf[1]=0xFF; 
     847            cmd.m_fdf[2]=0xFF; 
     848             
     849            cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     850            cmd.setSubunitType( eST_Unit  ); 
     851            cmd.setSubunitId( 0xff ); 
     852     
     853            cmd.setCommandType( AVCCommand::eCT_Control ); 
     854             
     855            if ( !cmd.fire() ) { 
     856                debugError( "output plug signal format command failed\n" ); 
     857                return false; 
     858            } 
     859 
     860            if ( cmd.getResponse() == AVCCommand::eR_Accepted ) 
     861            { 
     862                return true; 
     863            } 
     864            debugWarning( "output plug signal format command not accepted\n" ); 
     865        } else { 
     866            debugError("PCR plug with undefined direction.\n"); 
     867            return false; 
     868        } 
     869    } 
     870 
     871    // fallback: BeBoB style 
     872    ESamplingFrequency samplingFrequency = parseSampleRate(rate); 
     873     
     874    ExtendedStreamFormatCmd extStreamFormatCmd( 
     875        m_unit->get1394Service(), 
     876        ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList ); 
     877    UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 
     878                                     getPlugId() ); 
     879 
     880    extStreamFormatCmd.setPlugAddress( 
     881        PlugAddress( 
     882            Plug::convertPlugDirection(getPlugDirection() ), 
     883            PlugAddress::ePAM_Unit, 
     884            unitPlugAddress ) ); 
     885 
     886    extStreamFormatCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     887    extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
     888 
     889    int i = 0; 
     890    bool cmdSuccess = false; 
     891    bool correctFormatFound = false; 
     892 
     893    do { 
     894        extStreamFormatCmd.setIndexInStreamFormat( i ); 
     895        extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
     896        extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     897 
     898        cmdSuccess = extStreamFormatCmd.fire(); 
     899 
     900        if ( cmdSuccess 
     901             && ( extStreamFormatCmd.getResponse() == 
     902                  AVCCommand::eR_Implemented ) ) 
     903        { 
     904            ESamplingFrequency foundFreq = eSF_DontCare; 
     905 
     906            FormatInformation* formatInfo = 
     907                extStreamFormatCmd.getFormatInformation(); 
     908            FormatInformationStreamsCompound* compoundStream 
     909                = dynamic_cast< FormatInformationStreamsCompound* > ( 
     910                    formatInfo->m_streams ); 
     911            if ( compoundStream ) { 
     912                foundFreq = 
     913                    static_cast< ESamplingFrequency >( 
     914                        compoundStream->m_samplingFrequency ); 
     915            } 
     916 
     917            FormatInformationStreamsSync* syncStream 
     918                = dynamic_cast< FormatInformationStreamsSync* > ( 
     919                    formatInfo->m_streams ); 
     920            if ( syncStream ) { 
     921                foundFreq = 
     922                    static_cast< ESamplingFrequency >( 
     923                        syncStream->m_samplingFrequency ); 
     924            } 
     925 
     926            if ( foundFreq == samplingFrequency ) 
     927            { 
     928                correctFormatFound = true; 
     929                break; 
     930            } 
     931        } 
     932 
     933        ++i; 
     934    } while ( cmdSuccess 
     935              && ( extStreamFormatCmd.getResponse() == 
     936                   ExtendedStreamFormatCmd::eR_Implemented ) ); 
     937 
     938    if ( !cmdSuccess ) { 
     939        debugError( "setSampleRatePlug: Failed to retrieve format info\n" ); 
     940        return false; 
     941    } 
     942 
     943    if ( !correctFormatFound ) { 
     944        debugError( "setSampleRatePlug: %s plug %d does not support " 
     945                    "sample rate %d\n", 
     946                    getName(), 
     947                    getPlugId(), 
     948                    convertESamplingFrequency( samplingFrequency ) ); 
     949        return false; 
     950    } 
     951 
     952    extStreamFormatCmd.setSubFunction( 
     953        ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
     954    extStreamFormatCmd.setCommandType( AVCCommand::eCT_Control ); 
     955    extStreamFormatCmd.setVerbose( getDebugLevel() ); 
     956 
     957    if ( !extStreamFormatCmd.fire() ) { 
     958        debugError( "setSampleRate: Could not set sample rate %d " 
     959                    "to %s plug %d\n", 
     960                    convertESamplingFrequency( samplingFrequency ), 
     961                    getName(), 
     962                    getPlugId() ); 
     963        return false; 
     964    } 
     965 
     966    return true; 
    200967} 
    201968 
     
    4341201    } 
    4351202    return dir; 
     1203} 
     1204 
     1205std::string 
     1206Plug::plugAddressTypeToString(enum EPlugAddressType t) { 
     1207    switch (t) { 
     1208        case eAPA_PCR: 
     1209            return string("PCR"); 
     1210        case eAPA_ExternalPlug: 
     1211            return string("External"); 
     1212        case eAPA_AsynchronousPlug: 
     1213            return string("Async"); 
     1214        case eAPA_SubunitPlug: 
     1215            return string("Subunit"); 
     1216        case eAPA_FunctionBlockPlug: 
     1217            return string("Function Block"); 
     1218        default: 
     1219        case eAPA_Undefined: 
     1220            return string("Undefined"); 
     1221    } 
     1222} 
     1223 
     1224std::string 
     1225Plug::plugTypeToString(enum EPlugType t) { 
     1226    switch (t) { 
     1227        case eAPT_IsoStream: 
     1228            return string("IsoStream"); 
     1229        case eAPT_AsyncStream: 
     1230            return string("AsyncStream"); 
     1231        case eAPT_Midi: 
     1232            return string("MIDI"); 
     1233        case eAPT_Sync: 
     1234            return string("Sync"); 
     1235        case eAPT_Analog: 
     1236            return string("Analog"); 
     1237        case eAPT_Digital: 
     1238            return string("Digital"); 
     1239        default: 
     1240        case eAPT_Unknown: 
     1241            return string("Unknown"); 
     1242    } 
     1243} 
     1244 
     1245std::string 
     1246Plug::plugDirectionToString(enum EPlugDirection t) { 
     1247    switch (t) { 
     1248        case eAPD_Input: 
     1249            return string("Input"); 
     1250        case eAPD_Output: 
     1251            return string("Output"); 
     1252        default: 
     1253        case eAPT_Unknown: 
     1254            return string("Unknown"); 
     1255    } 
    4361256} 
    4371257 
     
    4591279    debugOutput( DEBUG_LEVEL_VERBOSE, "\tNumber of Streams  = %d\n", 
    4601280                 getNrOfStreams() ); 
     1281    debugOutput( DEBUG_LEVEL_VERBOSE, "\tIncoming connections from: "); 
     1282     
     1283    for ( PlugVector::const_iterator it = m_inputConnections.begin(); 
     1284          it != m_inputConnections.end(); 
     1285          ++it ) 
     1286    { 
     1287        debugOutputShort(DEBUG_LEVEL_VERBOSE, "%s, ", (*it)->getName()); 
     1288    } 
     1289    debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 
     1290 
     1291    debugOutput( DEBUG_LEVEL_VERBOSE, "\tOutgoing connections to: "); 
     1292    for ( PlugVector::const_iterator it = m_outputConnections.begin(); 
     1293          it != m_outputConnections.end(); 
     1294          ++it ) 
     1295    { 
     1296        debugOutputShort(DEBUG_LEVEL_VERBOSE, "%s, ", (*it)->getName()); 
     1297    } 
     1298    debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 
     1299 
    4611300    flushDebugOutput(); 
    4621301} 
     
    10401879 
    10411880// helper function 
    1042 static void addConnection( PlugConnectionOwnerVector& connections, 
     1881static void addConnection( PlugConnectionVector& connections, 
    10431882                           Plug& srcPlug, 
    10441883                           Plug& destPlug ) 
    10451884{ 
     1885    for ( PlugConnectionVector::iterator it = connections.begin(); 
     1886          it != connections.end(); 
     1887          ++it ) 
     1888    { 
     1889        PlugConnection* con = *it; 
     1890        if ( ( &( con->getSrcPlug() ) == &srcPlug ) 
     1891             && ( &( con->getDestPlug() ) == &destPlug ) ) 
     1892        { 
     1893            return; 
     1894        } 
     1895    } 
     1896    connections.push_back( new PlugConnection( srcPlug, destPlug ) ); 
     1897} 
     1898 
     1899bool 
     1900PlugManager::tidyPlugConnections(PlugConnectionVector& connections) 
     1901{ 
     1902    for ( PlugVector::const_iterator it = m_plugs.begin(); 
     1903          it !=  m_plugs.end(); 
     1904          ++it ) 
     1905    { 
     1906        Plug* plug = *it; 
     1907        for ( PlugVector::const_iterator it = 
     1908                  plug->getInputConnections().begin(); 
     1909            it != plug->getInputConnections().end(); 
     1910            ++it ) 
     1911        { 
     1912            addConnection( connections, *( *it ), *plug ); 
     1913        } 
     1914        plug->getInputConnections().clear(); 
     1915         
     1916        for ( PlugVector::const_iterator it = 
     1917                  plug->getOutputConnections().begin(); 
     1918            it != plug->getOutputConnections().end(); 
     1919            ++it ) 
     1920        { 
     1921            addConnection( connections, *plug, *( *it ) ); 
     1922        } 
     1923        plug->getOutputConnections().clear(); 
     1924    } 
     1925     
     1926    for ( PlugConnectionVector::iterator it = connections.begin(); 
     1927          it != connections.end(); 
     1928          ++it ) 
     1929    { 
     1930        PlugConnection * con = *it; 
     1931        con->getSrcPlug().getOutputConnections().push_back(&( con->getDestPlug() )); 
     1932        con->getDestPlug().getInputConnections().push_back(&( con->getSrcPlug() )); 
     1933 
     1934    } 
     1935     
     1936    return true; 
     1937} 
     1938 
     1939static void addConnectionOwner( PlugConnectionOwnerVector& connections, 
     1940                           Plug& srcPlug, 
     1941                           Plug& destPlug ) 
     1942{ 
     1943 
    10461944    for ( PlugConnectionOwnerVector::iterator it = connections.begin(); 
    10471945          it != connections.end(); 
     
    10571955    connections.push_back( PlugConnection( srcPlug, destPlug ) ); 
    10581956} 
     1957 
    10591958 
    10601959void 
     
    11042003            ++it ) 
    11052004        { 
    1106             addConnection( connections, *( *it ), *plug ); 
     2005            addConnectionOwner( connections, *( *it ), *plug ); 
    11072006        } 
    11082007        for ( PlugVector::const_iterator it = 
     
    11112010            ++it ) 
    11122011        { 
    1113             addConnection( connections, *plug, *( *it ) ); 
     2012            addConnectionOwner( connections, *plug, *( *it ) ); 
    11142013        } 
    11152014    } 
     
    14092308} 
    14102309 
    1411 
     2310ExtendedPlugInfoCmd 
     2311Plug::setPlugAddrToPlugInfoCmd() 
     2312
     2313    ExtendedPlugInfoCmd extPlugInfoCmd( m_unit->get1394Service() ); 
     2314 
     2315    switch( getSubunitType() ) { 
     2316    case eST_Unit: 
     2317        { 
     2318            UnitPlugAddress::EPlugType ePlugType = 
     2319                UnitPlugAddress::ePT_Unknown; 
     2320            switch ( m_addressType ) { 
     2321                case eAPA_PCR: 
     2322                    ePlugType = UnitPlugAddress::ePT_PCR; 
     2323                    break; 
     2324                case eAPA_ExternalPlug: 
     2325                    ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
     2326                    break; 
     2327                case eAPA_AsynchronousPlug: 
     2328                    ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
     2329                    break; 
     2330                default: 
     2331                    ePlugType = UnitPlugAddress::ePT_Unknown; 
     2332            } 
     2333            UnitPlugAddress unitPlugAddress( ePlugType, 
     2334                                             m_id ); 
     2335            extPlugInfoCmd.setPlugAddress( 
     2336                PlugAddress( convertPlugDirection( getPlugDirection() ), 
     2337                             PlugAddress::ePAM_Unit, 
     2338                             unitPlugAddress ) ); 
     2339        } 
     2340        break; 
     2341    case eST_Music: 
     2342    case eST_Audio: 
     2343        { 
     2344            switch( m_addressType ) { 
     2345            case eAPA_SubunitPlug: 
     2346            { 
     2347                SubunitPlugAddress subunitPlugAddress( m_id ); 
     2348                extPlugInfoCmd.setPlugAddress( 
     2349                    PlugAddress( 
     2350                        convertPlugDirection( getPlugDirection() ), 
     2351                        PlugAddress::ePAM_Subunit, 
     2352                        subunitPlugAddress ) ); 
     2353            } 
     2354            break; 
     2355            case eAPA_FunctionBlockPlug: 
     2356            { 
     2357                FunctionBlockPlugAddress functionBlockPlugAddress( 
     2358                    m_functionBlockType, 
     2359                    m_functionBlockId, 
     2360                    m_id ); 
     2361                extPlugInfoCmd.setPlugAddress( 
     2362                    PlugAddress( 
     2363                        convertPlugDirection( getPlugDirection() ), 
     2364                        PlugAddress::ePAM_FunctionBlock, 
     2365                        functionBlockPlugAddress ) ); 
     2366            } 
     2367            break; 
     2368            default: 
     2369                extPlugInfoCmd.setPlugAddress(PlugAddress()); 
     2370            } 
     2371        } 
     2372        break; 
     2373    default: 
     2374        debugError( "Unknown subunit type\n" ); 
     2375    } 
     2376 
     2377    extPlugInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     2378    extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
     2379    extPlugInfoCmd.setSubunitId( getSubunitId() ); 
     2380    extPlugInfoCmd.setSubunitType( getSubunitType() ); 
     2381 
     2382    return extPlugInfoCmd; 
     2383
     2384 
     2385ExtendedStreamFormatCmd 
     2386Plug::setPlugAddrToStreamFormatCmd( 
     2387    ExtendedStreamFormatCmd::ESubFunction subFunction) 
     2388
     2389    ExtendedStreamFormatCmd extStreamFormatInfoCmd( 
     2390        m_unit->get1394Service(), 
     2391        subFunction ); 
     2392    switch( getSubunitType() ) { 
     2393    case eST_Unit: 
     2394    { 
     2395            UnitPlugAddress::EPlugType ePlugType = 
     2396                UnitPlugAddress::ePT_Unknown; 
     2397            switch ( m_addressType ) { 
     2398                case eAPA_PCR: 
     2399                    ePlugType = UnitPlugAddress::ePT_PCR; 
     2400                    break; 
     2401                case eAPA_ExternalPlug: 
     2402                    ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
     2403                    break; 
     2404                case eAPA_AsynchronousPlug: 
     2405                    ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
     2406                    break; 
     2407                default: 
     2408                    ePlugType = UnitPlugAddress::ePT_Unknown; 
     2409            } 
     2410        UnitPlugAddress unitPlugAddress( ePlugType, 
     2411                                         m_id ); 
     2412        extStreamFormatInfoCmd.setPlugAddress( 
     2413            PlugAddress( convertPlugDirection( getPlugDirection() ), 
     2414                         PlugAddress::ePAM_Unit, 
     2415                         unitPlugAddress ) ); 
     2416        } 
     2417        break; 
     2418    case eST_Music: 
     2419    case eST_Audio: 
     2420    { 
     2421        switch( m_addressType ) { 
     2422        case eAPA_SubunitPlug: 
     2423        { 
     2424            SubunitPlugAddress subunitPlugAddress( m_id ); 
     2425            extStreamFormatInfoCmd.setPlugAddress( 
     2426                PlugAddress( convertPlugDirection( getPlugDirection() ), 
     2427                             PlugAddress::ePAM_Subunit, 
     2428                             subunitPlugAddress ) ); 
     2429        } 
     2430        break; 
     2431        case eAPA_FunctionBlockPlug: 
     2432        { 
     2433            FunctionBlockPlugAddress functionBlockPlugAddress( 
     2434                m_functionBlockType, 
     2435                m_functionBlockId, 
     2436                m_id ); 
     2437            extStreamFormatInfoCmd.setPlugAddress( 
     2438                PlugAddress( convertPlugDirection( getPlugDirection() ), 
     2439                             PlugAddress::ePAM_FunctionBlock, 
     2440                             functionBlockPlugAddress ) ); 
     2441        } 
     2442        break; 
     2443        default: 
     2444            extStreamFormatInfoCmd.setPlugAddress(PlugAddress()); 
     2445        } 
     2446    } 
     2447    break; 
     2448    default: 
     2449        debugError( "Unknown subunit type\n" ); 
     2450    } 
     2451 
     2452    extStreamFormatInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     2453    extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
     2454    extStreamFormatInfoCmd.setSubunitId( getSubunitId() ); 
     2455    extStreamFormatInfoCmd.setSubunitType( getSubunitType() ); 
     2456 
     2457    return extStreamFormatInfoCmd; 
     2458
     2459 
     2460
  • branches/echoaudio/src/libavc/general/avc_plug.h

    r509 r524  
    4747class Subunit; 
    4848class PlugManager; 
     49 
    4950class Plug; 
    50  
    5151typedef std::vector<Plug*> PlugVector; 
     52 
     53class PlugConnection; 
     54typedef std::vector<PlugConnection*> PlugConnectionVector; 
     55 
    5256 
    5357class Plug { 
     
    6266        eAPA_Undefined, 
    6367    }; 
     68    std::string plugAddressTypeToString(enum EPlugAddressType t); 
    6469 
    6570    enum EPlugType { 
     
    7277        eAPT_Unknown, 
    7378    }; 
     79    std::string plugTypeToString(enum EPlugType t); 
    7480 
    7581    enum EPlugDirection { 
     
    7884        eAPD_Unknown, 
    7985    }; 
     86    std::string plugDirectionToString(enum EPlugDirection t); 
    8087 
    8188    // \todo This constructors sucks. too many parameters. fix it. 
     
    9097    virtual ~Plug(); 
    9198 
    92     virtual bool discover()  
    93     {//FIXME: 
    94         #warning FIXME i want to be pure!! 
    95         return true; 
    96     }; 
    97  
    9899    bool inquireConnnection( Plug& plug ); 
    99100    bool setConnection( Plug& plug ); 
     101 
     102    int getSignalSource(); 
    100103 
    101104    int getGlobalId() const 
     
    108111    const char* getName() const 
    109112        { return m_name.c_str(); } 
     113    bool setName(const char *n) 
     114        { m_name=n; return true;}; 
     115    bool setName(std::string n) 
     116        { m_name=n; return true;}; 
    110117    EPlugDirection getPlugDirection() const 
    111118        { return m_direction; } 
     119    bool setPlugDirection(EPlugDirection d) 
     120        { m_direction=d; return true; } 
    112121    sampling_frequency_t getSamplingFrequency() const 
    113122        { return m_samplingFrequency; } 
    114123    int getSampleRate() const; // 22050, 24000, 32000, ... 
     124    bool setSampleRate( int rate ); 
     125     
    115126    int getNrOfChannels() const; 
     127    bool setNrOfChannels(int i); 
    116128    int getNrOfStreams() const; 
    117129 
     130    // FIXME: this is the same as getPlugDirection 
    118131    EPlugDirection getDirection() const 
    119132        { return m_direction; } 
     
    122135    EPlugType getPlugType() const 
    123136        { return m_infoPlugType; } 
     137    bool setPlugType(EPlugType t) 
     138        { m_infoPlugType=t; return true; } 
    124139 
    125140    function_block_type_t getFunctionBlockType() const 
     
    128143        { return m_functionBlockId; } 
    129144 
    130     const PlugVector& getInputConnections() const 
     145//     const PlugVector& getInputConnections() const 
     146//         { return m_inputConnections; } 
     147//     const PlugVector& getOutputConnections() const 
     148//         { return m_outputConnections; } 
     149    PlugVector& getInputConnections() 
    131150        { return m_inputConnections; } 
    132     const PlugVector& getOutputConnections() const 
     151    PlugVector& getOutputConnections() 
    133152        { return m_outputConnections; } 
    134153 
     
    171190    virtual void setVerboseLevel( int i )  
    172191            {setDebugLevel(i);}; 
     192     
     193// the discovery interface 
     194// everything can be overloaded, or 
     195// can be left as is 
     196public: 
     197    virtual bool discover(); 
     198    virtual bool discoverConnections(); 
     199    virtual bool propagateFromConnectedPlug( ); 
     200     
     201protected: 
     202    virtual bool discoverPlugType(); 
     203    virtual bool discoverName(); 
     204    virtual bool discoverNoOfChannels(); 
     205    virtual bool discoverChannelPosition(); 
     206    virtual bool discoverChannelName(); 
     207    virtual bool discoverClusterInfo(); 
     208    virtual bool discoverStreamFormat(); 
     209    virtual bool discoverSupportedStreamFormats(); 
     210    virtual bool discoverConnectionsInput(); 
     211    virtual bool discoverConnectionsOutput(); 
     212    virtual bool initFromDescriptor(); 
     213 
     214    bool propagateFromPlug( Plug *p ); 
     215 
     216    ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd(); 
     217 
     218    ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd( 
     219            ExtendedStreamFormatCmd::ESubFunction subFunction); 
     220 
    173221protected: 
    174222    Plug(); 
     
    280328    void showPlugs() const; 
    281329 
     330    int getPlugCount()  
     331        { return m_plugs.size(); }; 
     332 
    282333    Plug* getPlug( ESubunitType subunitType, 
    283334                   subunit_id_t subunitId, 
     
    302353    void setVerboseLevel( int i )  
    303354            {setDebugLevel(i);}; 
     355    PlugVector& getPlugs() {return m_plugs;}; 
     356    bool tidyPlugConnections(PlugConnectionVector&); 
     357 
    304358private: 
    305359 
     
    330384}; 
    331385 
    332 typedef std::vector<PlugConnection*> PlugConnectionVector; 
    333386typedef std::vector<PlugConnection> PlugConnectionOwnerVector; 
    334387 
  • branches/echoaudio/src/libavc/general/avc_subunit.cpp

    r509 r524  
    6666} 
    6767 
     68Plug * 
     69Subunit::createPlug( AVC::Unit* unit, 
     70                     AVC::Subunit* subunit, 
     71                     AVC::function_block_type_t functionBlockType, 
     72                     AVC::function_block_type_t functionBlockId, 
     73                     AVC::Plug::EPlugAddressType plugAddressType, 
     74                     AVC::Plug::EPlugDirection plugDirection, 
     75                     AVC::plug_id_t plugId ) 
     76{ 
     77 
     78    return new Plug( unit, 
     79                     subunit, 
     80                     functionBlockType, 
     81                     functionBlockId, 
     82                     plugAddressType, 
     83                     plugDirection, 
     84                     plugId ); 
     85} 
     86 
    6887bool 
    6988Subunit::discover() 
    7089{ 
    71     // There is nothing we can discover for a generic subunit 
    72     // Maybe the plugs, but there are multiple ways of doing that. 
    73     // subclasses should implement this 
     90    if ( !discoverPlugs() ) { 
     91        debugError( "plug discovery failed\n" ); 
     92        return false; 
     93    } 
     94 
     95    return true; 
     96
     97 
     98bool 
     99Subunit::discoverPlugs() 
     100
     101    PlugInfoCmd plugInfoCmd( getUnit().get1394Service(), 
     102                             PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug ); 
     103    plugInfoCmd.setNodeId( getUnit().getConfigRom().getNodeId() ); 
     104    plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
     105    plugInfoCmd.setSubunitType( getSubunitType() ); 
     106    plugInfoCmd.setSubunitId( getSubunitId() ); 
     107    plugInfoCmd.setVerbose( getDebugLevel() ); 
     108 
     109    if ( !plugInfoCmd.fire() ) { 
     110        debugError( "plug info command failed\n" ); 
     111        return false; 
     112    } 
     113 
     114    debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n", 
     115                 plugInfoCmd.m_sourcePlugs ); 
     116    debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output " 
     117                 "plugs = %d\n", plugInfoCmd.m_destinationPlugs ); 
     118 
     119    if ( !discoverPlugs( Plug::eAPD_Input, 
     120                         plugInfoCmd.m_destinationPlugs ) ) 
     121    { 
     122        debugError( "destination plug discovering failed\n" ); 
     123        return false; 
     124    } 
     125 
     126    if ( !discoverPlugs(  Plug::eAPD_Output, 
     127                          plugInfoCmd.m_sourcePlugs ) ) 
     128    { 
     129        debugError( "source plug discovering failed\n" ); 
     130        return false; 
     131    } 
     132 
     133    return true; 
     134
     135 
     136bool 
     137Subunit::discoverConnections() 
     138
     139    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
     140     
     141    for ( PlugVector::iterator it = getPlugs().begin(); 
     142          it != getPlugs().end(); 
     143          ++it ) 
     144    { 
     145        Plug* plug = *it; 
     146        if ( !plug->discoverConnections() ) { 
     147            debugError( "plug connection discovering failed ('%s')\n", 
     148                        plug->getName() ); 
     149            return false; 
     150        } 
     151    } 
     152 
     153    return true; 
     154
     155 
     156bool 
     157Subunit::discoverPlugs(Plug::EPlugDirection plugDirection, 
     158                                      plug_id_t plugMaxId ) 
     159
     160    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 
     161    for ( int plugIdx = 0; 
     162          plugIdx < plugMaxId; 
     163          ++plugIdx ) 
     164    { 
     165        Plug* plug = createPlug(  &getUnit(), 
     166                                &getSubunit(), 
     167                                0xff, 
     168                                0xff, 
     169                                Plug::eAPA_SubunitPlug, 
     170                                plugDirection, 
     171                                plugIdx ); 
     172        if ( !plug ) { 
     173            debugError( "plug creation failed\n" ); 
     174            return false; 
     175        } 
     176         
     177        plug->setVerboseLevel(getDebugLevel()); 
     178         
     179        if ( !plug->discover() ) { 
     180            debugError( "plug discover failed\n" ); 
     181            return false; 
     182        } 
     183 
     184        debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
     185                     plug->getName() ); 
     186        getPlugs().push_back( plug ); 
     187    } 
    74188    return true; 
    75189} 
     
    98212    } 
    99213    return 0; 
     214} 
     215 
     216bool 
     217Subunit::initPlugFromDescriptor( Plug& plug ) 
     218{ 
     219    debugError("plug loading from descriptor not implemented\n"); 
     220    return false; 
    100221} 
    101222 
  • branches/echoaudio/src/libavc/general/avc_subunit.h

    r509 r524  
    5151 
    5252    virtual bool discover(); 
     53    virtual bool discoverConnections(); 
    5354    virtual const char* getName() = 0; 
    5455 
     
    6061    Unit& getUnit() const 
    6162        { return *m_unit; } 
     63    Subunit& getSubunit() 
     64        { return *this; } 
    6265 
     66    virtual Plug *createPlug( AVC::Unit* unit, 
     67                              AVC::Subunit* subunit, 
     68                              AVC::function_block_type_t functionBlockType, 
     69                              AVC::function_block_type_t functionBlockId, 
     70                              AVC::Plug::EPlugAddressType plugAddressType, 
     71                              AVC::Plug::EPlugDirection plugDirection, 
     72                              AVC::plug_id_t plugId ); 
    6373 
    6474    bool addPlug( Plug& plug ); 
     75    virtual bool initPlugFromDescriptor( Plug& plug ); 
    6576 
    6677    PlugVector& getPlugs() 
     
    6879    Plug* getPlug(Plug::EPlugDirection direction, plug_id_t plugId); 
    6980 
     81    virtual void setVerboseLevel(int l)  
     82        { setDebugLevel(l);}; 
    7083 
    7184    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    7285    static Subunit* deserialize( Glib::ustring basePath, 
    73                      Util::IODeserialize& deser, 
    74                                          Unit& avDevice ); 
     86                     Util::IODeserialize& deser, Unit& avDevice ); 
    7587 protected: 
    7688    Subunit(); 
     
    8193                                   Util::IODeserialize& deser, 
    8294                                   Unit& avDevice ) = 0; 
     95    bool discoverPlugs(); 
     96    bool discoverPlugs(Plug::EPlugDirection plugDirection, 
     97                       AVC::plug_id_t plugMaxId ); 
    8398 
    8499 protected: 
  • branches/echoaudio/src/libavc/general/avc_unit.cpp

    r510 r524  
    5050    , m_activeSyncInfo( 0 ) 
    5151{ 
    52     debugOutput( DEBUG_LEVEL_VERBOSE, "Created AVC::Unit\n" ); 
     52    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Unit\n" ); 
     53    m_pPlugManager->setVerboseLevel( getDebugLevel() ); 
    5354} 
    5455 
     
    8182} 
    8283 
     84Plug * 
     85Unit::createPlug( Unit* unit, 
     86                     Subunit* subunit, 
     87                     function_block_type_t functionBlockType, 
     88                     function_block_type_t functionBlockId, 
     89                     Plug::EPlugAddressType plugAddressType, 
     90                     Plug::EPlugDirection plugDirection, 
     91                     plug_id_t plugId ) 
     92{ 
     93 
     94    return new Plug( unit, 
     95                     subunit, 
     96                     functionBlockType, 
     97                     functionBlockId, 
     98                     plugAddressType, 
     99                     plugDirection, 
     100                     plugId ); 
     101} 
     102 
     103Subunit*  
     104Unit::createSubunit(Unit& unit, 
     105                    ESubunitType type, 
     106                    subunit_t id )  
     107{ 
     108    switch (type) { 
     109        case eST_Audio: 
     110            return new SubunitAudio(unit, id ); 
     111        case eST_Music: 
     112            return new SubunitMusic(unit, id ); 
     113        default: 
     114            return NULL; 
     115    } 
     116} 
     117 
    83118void 
    84119Unit::setVerboseLevel(int l) 
     
    93128    if ( !enumerateSubUnits() ) { 
    94129        debugError( "Could not enumarate sub units\n" ); 
     130        return false; 
     131    } 
     132 
     133    if ( !discoverPlugs() ) { 
     134        debugError( "Detecting plugs failed\n" ); 
     135        return false; 
     136    } 
     137 
     138    if ( !discoverPlugConnections() ) { 
     139        debugError( "Detecting plug connections failed\n" ); 
     140        return false; 
     141    } 
     142 
     143    if ( !discoverSubUnitsPlugConnections() ) { 
     144        debugError( "Detecting subunit plug connnections failed\n" ); 
     145        return false; 
     146    } 
     147 
     148    if ( !m_pPlugManager->tidyPlugConnections(m_plugConnections) ) { 
     149        debugError( "Tidying of plug connnections failed\n" ); 
     150        return false; 
     151    } 
     152 
     153    if ( !discoverSyncModes() ) { 
     154        debugError( "Detecting sync modes failed\n" ); 
     155        return false; 
     156    } 
     157 
     158    if ( !propagateClusterInfos() ) { 
     159        debugError( "Failed to propagate cluster info's\n" ); 
    95160        return false; 
    96161    } 
     
    135200        switch( subunit_type ) { 
    136201        case eST_Audio: 
    137             subunit = new SubunitAudio( *this, 
    138                                                 subunitId ); 
     202            subunit = createSubunit( *this, eST_Audio, subunitId ); 
    139203            if ( !subunit ) { 
    140204                debugFatal( "Could not allocate SubunitAudio\n" ); 
    141205                return false; 
    142206            } 
     207             
     208            subunit->setVerboseLevel(getDebugLevel()); 
    143209             
    144210            if ( !subunit->discover() ) { 
     
    156222            break; 
    157223        case eST_Music: 
    158             subunit = new SubunitMusic( *this, 
    159                                         subunitId ); 
     224            subunit = createSubunit( *this, eST_Music, subunitId ); 
    160225            if ( !subunit ) { 
    161226                debugFatal( "Could not allocate SubunitMusic\n" ); 
    162227                return false; 
    163228            } 
     229             
     230            subunit->setVerboseLevel(getDebugLevel()); 
     231             
    164232            if ( !subunit->discover() ) { 
    165233                debugError( "enumerateSubUnits: Could not discover " 
     
    225293} 
    226294 
     295bool 
     296Unit::discoverPlugs() 
     297{ 
     298    debugOutput( DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 
     299 
     300    ////////////////////////////////////////////// 
     301    // Get number of available isochronous input 
     302    // and output plugs of unit 
     303 
     304    PlugInfoCmd plugInfoCmd( get1394Service() ); 
     305    plugInfoCmd.setNodeId( getConfigRom().getNodeId() ); 
     306    plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
     307    plugInfoCmd.setVerbose( getDebugLevel() ); 
     308 
     309    if ( !plugInfoCmd.fire() ) { 
     310        debugError( "plug info command failed\n" ); 
     311        return false; 
     312    } 
     313 
     314    debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n", 
     315                 plugInfoCmd.m_serialBusIsochronousInputPlugs ); 
     316    debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n", 
     317                 plugInfoCmd.m_serialBusIsochronousOutputPlugs ); 
     318    debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n", 
     319                 plugInfoCmd.m_externalInputPlugs ); 
     320    debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n", 
     321                 plugInfoCmd.m_externalOutputPlugs ); 
     322 
     323    if ( !discoverPlugsPCR( Plug::eAPD_Input, 
     324                            plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) 
     325    { 
     326        debugError( "pcr input plug discovering failed\n" ); 
     327        return false; 
     328    } 
     329 
     330    if ( !discoverPlugsPCR( Plug::eAPD_Output, 
     331                            plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) 
     332    { 
     333        debugError( "pcr output plug discovering failed\n" ); 
     334        return false; 
     335    } 
     336 
     337    if ( !discoverPlugsExternal( Plug::eAPD_Input, 
     338                                 plugInfoCmd.m_externalInputPlugs ) ) 
     339    { 
     340        debugError( "external input plug discovering failed\n" ); 
     341        return false; 
     342    } 
     343 
     344    if ( !discoverPlugsExternal( Plug::eAPD_Output, 
     345                                 plugInfoCmd.m_externalOutputPlugs ) ) 
     346    { 
     347        debugError( "external output plug discovering failed\n" ); 
     348        return false; 
     349    } 
     350 
     351    return true; 
     352} 
     353 
     354bool 
     355Unit::discoverPlugsPCR( Plug::EPlugDirection plugDirection, 
     356                            plug_id_t plugMaxId ) 
     357{ 
     358    debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plugs, direction %d...\n",plugDirection); 
     359    for ( int plugId = 0; 
     360          plugId < plugMaxId; 
     361          ++plugId ) 
     362    { 
     363        Plug* plug  = createPlug( this, 
     364                                NULL, 
     365                                0xff, 
     366                                0xff, 
     367                                Plug::eAPA_PCR, 
     368                                plugDirection, 
     369                                plugId ); 
     370        if ( !plug || !plug->discover() ) { 
     371            debugError( "plug discovering failed\n" ); 
     372            delete plug; 
     373            return false; 
     374        } 
     375 
     376        debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
     377                     plug->getName() ); 
     378        m_pcrPlugs.push_back( plug ); 
     379    } 
     380 
     381    return true; 
     382} 
     383 
     384bool 
     385Unit::discoverPlugsExternal( Plug::EPlugDirection plugDirection, 
     386                                 plug_id_t plugMaxId ) 
     387{ 
     388    debugOutput( DEBUG_LEVEL_NORMAL, "Discovering External plugs, direction %d...\n",plugDirection); 
     389    for ( int plugId = 0; 
     390          plugId < plugMaxId; 
     391          ++plugId ) 
     392    { 
     393        Plug* plug  = createPlug( this, NULL, 
     394                                0xff, 
     395                                0xff, 
     396                                Plug::eAPA_ExternalPlug, 
     397                                plugDirection, 
     398                                plugId ); 
     399        if ( !plug || !plug->discover() ) { 
     400            debugError( "plug discovering failed\n" ); 
     401            return false; 
     402        } 
     403 
     404        debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
     405                     plug->getName() ); 
     406        m_externalPlugs.push_back( plug ); 
     407    } 
     408 
     409    return true; 
     410} 
     411 
     412bool 
     413Unit::discoverPlugConnections() 
     414{ 
     415    debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plug connections...\n"); 
     416    for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
     417          it != m_pcrPlugs.end(); 
     418          ++it ) 
     419    { 
     420        Plug* plug = *it; 
     421        if ( !plug->discoverConnections() ) { 
     422            debugError( "Could not discover PCR plug connections\n" ); 
     423            return false; 
     424        } 
     425    } 
     426    debugOutput( DEBUG_LEVEL_NORMAL, "Discovering External plug connections...\n"); 
     427    for ( PlugVector::iterator it = m_externalPlugs.begin(); 
     428          it != m_externalPlugs.end(); 
     429          ++it ) 
     430    { 
     431        Plug* plug = *it; 
     432        if ( !plug->discoverConnections() ) { 
     433            debugError( "Could not discover External plug connections\n" ); 
     434            return false; 
     435        } 
     436    } 
     437 
     438    return true; 
     439} 
     440 
     441bool 
     442Unit::discoverSubUnitsPlugConnections() 
     443{ 
     444    for ( SubunitVector::iterator it = m_subunits.begin(); 
     445          it != m_subunits.end(); 
     446          ++it ) 
     447    { 
     448        Subunit* subunit = *it; 
     449 
     450        if ( !subunit->discoverConnections() ) { 
     451            debugError( "Subunit '%s'  plug connections failed\n", 
     452                        subunit->getName() ); 
     453            return false; 
     454        } 
     455    } 
     456    return true; 
     457} 
     458 
     459bool 
     460Unit::propagateClusterInfos() 
     461{ 
     462    debugOutput( DEBUG_LEVEL_NORMAL, "Propagating info to PCR plugs...\n"); 
     463    for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
     464          it != m_pcrPlugs.end(); 
     465          ++it ) 
     466    { 
     467        Plug* plug = *it; 
     468        debugOutput( DEBUG_LEVEL_NORMAL, "plug: %s\n", plug->getName()); 
     469        if (!plug->propagateFromConnectedPlug()) { 
     470            debugWarning( "Could not propagate info for plug '%s'\n", plug->getName()); 
     471        } 
     472    } 
     473    debugOutput( DEBUG_LEVEL_NORMAL, "Propagating info to External plugs...\n"); 
     474    for ( PlugVector::iterator it = m_externalPlugs.begin(); 
     475          it != m_externalPlugs.end(); 
     476          ++it ) 
     477    { 
     478        Plug* plug = *it; 
     479        debugOutput( DEBUG_LEVEL_NORMAL, "plug: %s\n", plug->getName()); 
     480        if (!plug->propagateFromConnectedPlug()) { 
     481            debugWarning( "Could not propagate info for plug '%s'\n", plug->getName()); 
     482        } 
     483    } 
     484 
     485    return true; 
     486 
     487} 
     488 
     489 
    227490PlugConnection* 
    228491Unit::getPlugConnection( Plug& srcPlug ) const 
     
    288551    return 0; 
    289552} 
     553 
     554bool 
     555Unit::discoverSyncModes() 
     556{ 
     557    // Following possible sync plugs exists: 
     558    // - Music subunit sync output plug = internal sync (CSP) 
     559    // - Unit input plug 0 = SYT match 
     560    // - Unit input plut 1 = Sync stream 
     561    // 
     562    // If last sync mode is reported it is mostelikely not 
     563    // implemented *sic* 
     564    // 
     565    // Following sync sources are device specific: 
     566    // - All unit external input plugs which have a 
     567    //   sync information (WS, SPDIF, ...) 
     568 
     569    // First we have to find the sync input and output plug 
     570    // in the music subunit. 
     571 
     572    // Note PCR input means 1394bus-to-device where as 
     573    // MSU input means subunit-to-device 
     574 
     575    PlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
     576                                                     Plug::eAPD_Input, 
     577                                                     Plug::eAPT_Sync ); 
     578    if ( !syncPCRInputPlugs.size() ) { 
     579        debugWarning( "No PCR sync input plug found\n" ); 
     580    } 
     581 
     582    PlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
     583                                                      Plug::eAPD_Output, 
     584                                                      Plug::eAPT_Sync ); 
     585    if ( !syncPCROutputPlugs.size() ) { 
     586        debugWarning( "No PCR sync output plug found\n" ); 
     587    } 
     588 
     589    PlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
     590                                                    Plug::eAPD_Input, 
     591                                                    Plug::eAPT_IsoStream ); 
     592    if ( !isoPCRInputPlugs.size() ) { 
     593        debugWarning( "No PCR iso input plug found\n" ); 
     594 
     595    } 
     596 
     597    PlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
     598                                                    Plug::eAPD_Output, 
     599                                                    Plug::eAPT_IsoStream ); 
     600    if ( !isoPCROutputPlugs.size() ) { 
     601        debugWarning( "No PCR iso output plug found\n" ); 
     602 
     603    } 
     604 
     605    PlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 
     606                                                    Plug::eAPD_Input, 
     607                                                    Plug::eAPT_Digital ); 
     608 
     609    PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
     610        eST_Music, 
     611        0, 
     612        0xff, 
     613        0xff, 
     614        Plug::eAPA_SubunitPlug, 
     615        Plug::eAPD_Input, 
     616        Plug::eAPT_Sync ); 
     617    if ( !syncMSUInputPlugs.size() ) { 
     618        debugWarning( "No sync input plug for MSU subunit found\n" ); 
     619    } 
     620 
     621    PlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 
     622        eST_Music, 
     623        0, 
     624        0xff, 
     625        0xff, 
     626        Plug::eAPA_SubunitPlug, 
     627        Plug::eAPD_Output, 
     628        Plug::eAPT_Sync ); 
     629    if ( !syncMSUOutputPlugs.size() ) { 
     630        debugWarning( "No sync output plug for MSU subunit found\n" ); 
     631    } 
     632 
     633    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); 
     634    showPlugs( syncPCRInputPlugs ); 
     635    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); 
     636    showPlugs( syncPCROutputPlugs ); 
     637    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); 
     638    showPlugs( isoPCRInputPlugs ); 
     639    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); 
     640    showPlugs( isoPCROutputPlugs ); 
     641    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); 
     642    showPlugs( digitalPCRInputPlugs ); 
     643    debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); 
     644    showPlugs( syncMSUInputPlugs ); 
     645    debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); 
     646    showPlugs( syncMSUOutputPlugs ); 
     647 
     648    // Check all possible PCR input to MSU input connections 
     649    // -> sync stream input 
     650    checkSyncConnectionsAndAddToList( syncPCRInputPlugs, 
     651                                      syncMSUInputPlugs, 
     652                                      "Sync Stream Input" ); 
     653 
     654    // Check all possible MSU output to PCR output connections 
     655    // -> sync stream output 
     656    checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
     657                                      syncPCROutputPlugs, 
     658                                      "Sync Stream Output" ); 
     659 
     660    // Check all PCR iso input to MSU input connections 
     661    // -> SYT match 
     662    checkSyncConnectionsAndAddToList( isoPCRInputPlugs, 
     663                                      syncMSUInputPlugs, 
     664                                      "Syt Match" ); 
     665 
     666    // Check all MSU sync output to MSU input connections 
     667    // -> CSP 
     668    checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
     669                                      syncMSUInputPlugs, 
     670                                      "Internal (CSP)" ); 
     671 
     672    // Check all external PCR digital input to MSU input connections 
     673    // -> SPDIF/ADAT sync 
     674    checkSyncConnectionsAndAddToList( digitalPCRInputPlugs, 
     675                                      syncMSUInputPlugs, 
     676                                      "Digital Input Sync" ); 
     677 
     678    // Currently active connection signal source cmd, command type 
     679    // status, source unknown, destination MSU sync input plug 
     680 
     681    for ( PlugVector::const_iterator it = syncMSUInputPlugs.begin(); 
     682          it != syncMSUInputPlugs.end(); 
     683          ++it ) 
     684    { 
     685        AVC::Plug* msuPlug = *it; 
     686        for ( PlugVector::const_iterator jt = 
     687                  msuPlug->getInputConnections().begin(); 
     688              jt != msuPlug->getInputConnections().end(); 
     689              ++jt ) 
     690        { 
     691            AVC::Plug* plug = *jt; 
     692 
     693            for ( SyncInfoVector::iterator it = m_syncInfos.begin(); 
     694                  it != m_syncInfos.end(); 
     695                  ++it ) 
     696            { 
     697                SyncInfo* pSyncInfo = &*it; 
     698                if ( ( pSyncInfo->m_source == plug ) 
     699                     && ( pSyncInfo->m_destination == msuPlug ) ) 
     700                { 
     701                    m_activeSyncInfo = pSyncInfo; 
     702                    break; 
     703                } 
     704            } 
     705            debugOutput( DEBUG_LEVEL_NORMAL, 
     706                         "Active Sync Connection: '%s' -> '%s'\n", 
     707                         plug->getName(), 
     708                         msuPlug->getName() ); 
     709        } 
     710    } 
     711 
     712    return true; 
     713} 
     714 
     715bool 
     716Unit::checkSyncConnectionsAndAddToList( PlugVector& plhs, 
     717                                            PlugVector& prhs, 
     718                                            std::string syncDescription ) 
     719{ 
     720    for ( PlugVector::iterator plIt = plhs.begin(); 
     721          plIt != plhs.end(); 
     722          ++plIt ) 
     723    { 
     724        AVC::Plug* pl = *plIt; 
     725        for ( PlugVector::iterator prIt = prhs.begin(); 
     726              prIt != prhs.end(); 
     727              ++prIt ) 
     728        { 
     729            AVC::Plug* pr = *prIt; 
     730            if ( pl->inquireConnnection( *pr ) ) { 
     731                m_syncInfos.push_back( SyncInfo( *pl, *pr, syncDescription ) ); 
     732                debugOutput( DEBUG_LEVEL_NORMAL, 
     733                             "Sync connection '%s' -> '%s'\n", 
     734                             pl->getName(), 
     735                             pr->getName() ); 
     736            } 
     737        } 
     738    } 
     739    return true; 
     740} 
     741 
     742bool Unit::setActiveSync(const SyncInfo& syncInfo) 
     743{ 
     744    return syncInfo.m_source->setConnection( *syncInfo.m_destination ); 
     745} 
     746 
    290747 
    291748void 
  • branches/echoaudio/src/libavc/general/avc_unit.h

    r509 r524  
    6262     
    6363    /// Discovers the unit's internals 
    64     bool discover(); 
     64    virtual bool discover(); 
    6565 
    6666    PlugManager& getPlugManager() 
     
    8686 
    8787    typedef std::vector<SyncInfo> SyncInfoVector; 
    88     const SyncInfoVector& getSyncInfos() const 
     88    virtual const SyncInfoVector& getSyncInfos() const 
    8989        { return m_syncInfos; } 
    90     const SyncInfo* getActiveSyncInfo() const 
     90    virtual const SyncInfo* getActiveSyncInfo() const 
    9191        { return m_activeSyncInfo; } 
    92     virtual bool setActiveSync( const SyncInfo& syncInfo ) = 0; 
     92         
     93    virtual bool setActiveSync( const SyncInfo& syncInfo ); 
    9394 
    9495    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
     
    104105    Subunit* getSubunit( subunit_type_t subunitType, 
    105106                         subunit_id_t subunitId ) const; 
     107 
     108    virtual AVC::Subunit* createSubunit(Unit& unit, 
     109                                        ESubunitType type, 
     110                                        subunit_t id ); 
     111    virtual AVC::Plug* createPlug( AVC::Unit* unit, 
     112                                   AVC::Subunit* subunit, 
     113                                   AVC::function_block_type_t functionBlockType, 
     114                                   AVC::function_block_type_t functionBlockId, 
     115                                   AVC::Plug::EPlugAddressType plugAddressType, 
     116                                   AVC::Plug::EPlugDirection plugDirection, 
     117                                   AVC::plug_id_t plugId ); 
     118 
    106119protected: 
    107120 
    108121    virtual bool enumerateSubUnits(); 
    109  
     122    virtual bool discoverPlugConnections(); 
     123    virtual bool discoverSubUnitsPlugConnections(); 
     124    virtual bool discoverPlugs(); 
     125    virtual bool discoverPlugsPCR( AVC::Plug::EPlugDirection plugDirection, 
     126                           AVC::plug_id_t plugMaxId ); 
     127    virtual bool discoverPlugsExternal( AVC::Plug::EPlugDirection plugDirection, 
     128                                AVC::plug_id_t plugMaxId ); 
     129    virtual bool propagateClusterInfos(); 
     130    virtual bool discoverSyncModes(); 
     131    virtual bool checkSyncConnectionsAndAddToList( AVC::PlugVector& plhs, 
     132                                           AVC::PlugVector& prhs, 
     133                                           std::string syncDescription ); 
     134    virtual Plug* getSyncPlug( int maxPlugId, Plug::EPlugDirection ); 
     135     
    110136    unsigned int getNrOfSubunits( subunit_type_t subunitType ) const; 
    111137    PlugConnection* getPlugConnection( Plug& srcPlug ) const; 
    112  
    113     Plug* getSyncPlug( int maxPlugId, Plug::EPlugDirection ); 
    114138 
    115139    Plug* getPlugById( PlugVector& plugs, 
     
    126150    void showPlugs( PlugVector& plugs ) const; 
    127151 
    128 //     bool checkSyncConnectionsAndAddToList( PlugVector& plhs, 
    129 //                                            PlugVector& prhs, 
    130 //                                            std::string syncDescription ); 
    131152 
    132153    static bool serializeSyncInfoVector( Glib::ustring basePath, 
  • branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.cpp

    r503 r524  
    3030#include "libieee1394/ieee1394service.h" 
    3131 
     32#include "../general/avc_subunit.h" 
     33#include "../general/avc_unit.h" 
     34 
    3235#include <netinet/in.h> 
    3336 
     
    199202        } 
    200203    } 
    201          
    202     return result; 
    203 
     204 
     205    return result; 
     206
     207 
     208std::string  
     209AVCMusicClusterInfoBlock::getName() { 
     210    if(m_RawTextInfoBlock.m_compound_length>0) { 
     211        return m_RawTextInfoBlock.m_text; 
     212    } else if (m_NameInfoBlock.m_compound_length>0) { 
     213        return m_NameInfoBlock.m_text; 
     214    } else { 
     215        return std::string("Unknown"); 
     216    } 
     217
     218 
    204219 
    205220// --------- 
     
    322337    return result; 
    323338} 
     339 
     340std::string  
     341AVCMusicSubunitPlugInfoBlock::getName() { 
     342    if(m_RawTextInfoBlock.m_compound_length>0) { 
     343        return m_RawTextInfoBlock.m_text; 
     344    } else if (m_NameInfoBlock.m_compound_length>0) { 
     345        return m_NameInfoBlock.m_text; 
     346    } else { 
     347        return std::string("Unknown"); 
     348    } 
     349} 
     350 
    324351 
    325352// --------- 
     
    431458} 
    432459 
     460std::string  
     461AVCMusicPlugInfoBlock::getName() { 
     462    if(m_RawTextInfoBlock.m_compound_length>0) { 
     463        return m_RawTextInfoBlock.m_text; 
     464    } else if (m_NameInfoBlock.m_compound_length>0) { 
     465        return m_NameInfoBlock.m_text; 
     466    } else { 
     467        return std::string("Unknown"); 
     468    } 
     469} 
     470 
     471 
    433472// --------- 
    434473AVCMusicRoutingStatusInfoBlock::AVCMusicRoutingStatusInfoBlock( ) 
     
    568607} 
    569608 
     609AVCMusicSubunitPlugInfoBlock * 
     610AVCMusicRoutingStatusInfoBlock::getSubunitPlugInfoBlock(Plug::EPlugDirection direction, plug_id_t id) { 
     611    if (direction == Plug::eAPD_Input) { 
     612        for ( AVCMusicSubunitPlugInfoBlockVectorIterator it = mDestPlugInfoBlocks.begin(); 
     613        it != mDestPlugInfoBlocks.end(); 
     614        ++it ) 
     615        { 
     616            AVCMusicSubunitPlugInfoBlock *b=(*it); 
     617            if (b->m_subunit_plug_id == id) return b; 
     618        } 
     619        debugOutput(DEBUG_LEVEL_VERBOSE, "no plug info found.\n"); 
     620        return NULL; 
     621    } else if (direction == Plug::eAPD_Output) { 
     622        for ( AVCMusicSubunitPlugInfoBlockVectorIterator it = mSourcePlugInfoBlocks.begin(); 
     623        it != mSourcePlugInfoBlocks.end(); 
     624        ++it ) 
     625        { 
     626            AVCMusicSubunitPlugInfoBlock *b=(*it); 
     627            if (b->m_subunit_plug_id == id) return b; 
     628        } 
     629        debugOutput(DEBUG_LEVEL_VERBOSE, "no plug info found.\n"); 
     630        return NULL; 
     631    } else { 
     632        debugOutput(DEBUG_LEVEL_VERBOSE, "Invalid direction.\n"); 
     633        return NULL; 
     634    } 
     635} 
     636 
     637AVCMusicPlugInfoBlock * 
     638AVCMusicRoutingStatusInfoBlock::getMusicPlugInfoBlock(plug_id_t id) { 
     639    for ( AVCMusicPlugInfoBlockVectorIterator it = mMusicPlugInfoBlocks.begin(); 
     640    it != mMusicPlugInfoBlocks.end(); 
     641    ++it ) 
     642    { 
     643        AVCMusicPlugInfoBlock *b=(*it); 
     644        if (b->m_music_plug_id == id) return b; 
     645    } 
     646    debugOutput(DEBUG_LEVEL_VERBOSE, "no music plug info found.\n"); 
     647    return NULL; 
     648} 
    570649 
    571650// ---------------------- 
    572 AVCMusicStatusDescriptor::AVCMusicStatusDescriptor( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId
    573     : AVCDescriptor(ieee1394service, nodeId, eST_Music, 0x00, AVCDescriptorSpecifier::eSubunit0x80) 
     651AVCMusicStatusDescriptor::AVCMusicStatusDescriptor( Unit* unit, Subunit* subunit
     652    : AVCDescriptor(unit, subunit, AVCDescriptorSpecifier::eSubunit0x80) 
    574653{} 
    575654 
     
    614693         
    615694        switch (block_type) { 
    616             case 0x8100:  
     695            case 0x8100: 
    617696                m_general_status_infoblock.setVerbose(getVerboseLevel()); 
    618697                result &= m_general_status_infoblock.deserialize(de); 
    619698                break; 
    620             case 0x8101:  
     699            case 0x8101: 
    621700                m_output_plug_status_infoblock.setVerbose(getVerboseLevel()); 
    622701                result &= m_output_plug_status_infoblock.deserialize(de); 
    623702                break; 
    624         case 0x8108:  
     703            case 0x8108: 
    625704                m_routing_status_infoblock.setVerbose(getVerboseLevel()); 
    626705                result &= m_routing_status_infoblock.deserialize(de); 
     
    631710                break; 
    632711        } 
    633          
     712 
    634713        if(blocks_done++>max_blocks) { 
    635714            debugError("Too much info blocks in descriptor, probably a runaway parser\n"); 
     
    641720} 
    642721 
    643 
     722AVCMusicSubunitPlugInfoBlock * 
     723AVCMusicStatusDescriptor::getSubunitPlugInfoBlock(Plug::EPlugDirection direction, plug_id_t id) { 
     724    return m_routing_status_infoblock.getSubunitPlugInfoBlock(direction, id); 
     725
     726 
     727AVCMusicPlugInfoBlock * 
     728AVCMusicStatusDescriptor::getMusicPlugInfoBlock(plug_id_t id) { 
     729    return m_routing_status_infoblock.getMusicPlugInfoBlock(id); 
     730
     731 
     732
  • branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.h

    r503 r524  
    3434 
    3535#include "../general/avc_generic.h" 
     36#include "../general/avc_plug.h" 
     37 
    3638#include "debugmodule/debugmodule.h" 
    3739 
    3840#include <libavc1394/avc1394.h> 
     41 
    3942#include <vector> 
     43#include <string> 
    4044 
    4145class Ieee1394Service; 
     
    99103        byte_t stream_location; 
    100104    }; 
    101  
    102     virtual bool serialize( IOSSerialize& se ); 
    103     virtual bool deserialize( IISDeserialize& de ); 
    104  
    105     virtual bool clear(); 
    106      
     105    typedef std::vector<struct sSignalInfo> SignalInfoVector; 
     106    typedef std::vector<struct sSignalInfo>::iterator SignalInfoVectorIterator; 
     107 
     108    virtual bool serialize( IOSSerialize& se ); 
     109    virtual bool deserialize( IISDeserialize& de ); 
     110 
     111    virtual bool clear(); 
     112     
     113    std::string getName(); 
     114 
    107115    AVCMusicClusterInfoBlock( ); 
    108116    virtual ~AVCMusicClusterInfoBlock(); 
     
    113121    byte_t      m_port_type; 
    114122    byte_t      m_nb_signals; 
    115     std::vector<struct sSignalInfo> m_SignalInfos; 
     123    SignalInfoVector m_SignalInfos; 
    116124 
    117125    AVCRawTextInfoBlock m_RawTextInfoBlock; 
     
    128136{ 
    129137public: 
     138    enum AVCMusicSubunitPlugInfoBlockPlugType { 
     139        ePT_IsoStream   = 0x0, 
     140        ePT_AsyncStream = 0x1, 
     141        ePT_Midi        = 0x2, 
     142        ePT_Sync        = 0x3, 
     143        ePT_Analog      = 0x4, 
     144        ePT_Digital     = 0x5, 
     145 
     146        ePT_Unknown     = 0xff, 
     147    }; 
    130148 
    131149    virtual bool serialize( IOSSerialize& se ); 
     
    138156         
    139157    virtual bool clear(); 
     158     
     159    std::string getName(); 
    140160     
    141161    byte_t      m_subunit_plug_id; 
     
    169189    virtual const char* getInfoBlockName() const 
    170190        {return "AVCMusicPlugInfoBlock";}; 
     191 
     192    std::string getName(); 
    171193 
    172194    byte_t      m_music_plug_type; 
     
    207229        {return "AVCMusicRoutingStatusInfoBlock";}; 
    208230 
     231    AVCMusicSubunitPlugInfoBlock *getSubunitPlugInfoBlock(Plug::EPlugDirection, plug_id_t); 
     232    AVCMusicPlugInfoBlock *getMusicPlugInfoBlock(plug_id_t); 
     233     
    209234    virtual bool clear(); 
    210235 
     
    233258    virtual bool deserialize( IISDeserialize& de ); 
    234259     
    235     AVCMusicStatusDescriptor( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId ); 
     260    AVCMusicStatusDescriptor( Unit* unit, Subunit* subunit ); 
    236261    virtual ~AVCMusicStatusDescriptor() {} 
    237262     
    238263    virtual const char* getDescriptorName() const 
    239264        {return "AVCMusicStatusDescriptor";}; 
     265         
     266    AVCMusicSubunitPlugInfoBlock *getSubunitPlugInfoBlock(Plug::EPlugDirection, plug_id_t); 
     267    AVCMusicPlugInfoBlock *getMusicPlugInfoBlock(plug_id_t); 
     268     
    240269private: 
    241270    // the child info blocks 
  • branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.cpp

    r508 r524  
    3434#include "../util/avc_serialize.h" 
    3535 
     36#include "avc_musicsubunit.h" 
     37#include "avc_descriptor_music.h" 
     38 
    3639#include <sstream> 
    3740 
     
    4245SubunitMusic::SubunitMusic( Unit& unit, subunit_t id ) 
    4346    : Subunit( unit, eST_Music, id ) 
    44 
     47    , m_status_descriptor ( new AVCMusicStatusDescriptor( &unit, this ) ) 
     48
     49 
    4550} 
    4651 
    4752SubunitMusic::SubunitMusic() 
    4853    : Subunit() 
     54    , m_status_descriptor ( NULL ) 
    4955{ 
    5056} 
     
    5258SubunitMusic::~SubunitMusic() 
    5359{ 
     60    if (m_status_descriptor) delete m_status_descriptor; 
     61} 
     62 
     63bool 
     64SubunitMusic::discover() 
     65{ 
     66    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering %s...\n", getName()); 
     67     
     68    // discover the AV/C generic part 
     69    if ( !Subunit::discover() ) { 
     70        return false; 
     71    } 
     72     
     73    // now we have the subunit plugs 
     74     
     75    return true; 
     76} 
     77 
     78bool 
     79SubunitMusic::initPlugFromDescriptor( Plug& plug ) 
     80{ 
     81    debugOutput(DEBUG_LEVEL_VERBOSE, "Loading info from descriptor for plug: \n"); 
     82    bool result=true; 
     83     
     84    // load the descriptor (if not already loaded) 
     85    if (m_status_descriptor != NULL) { 
     86        result &= m_status_descriptor->load(); 
     87    } 
     88     
     89    AVCMusicSubunitPlugInfoBlock *info; 
     90    info = m_status_descriptor->getSubunitPlugInfoBlock(plug.getDirection(), plug.getPlugId()); 
     91     
     92    if (info == NULL) { 
     93        debugError("Could not find plug info block\n"); 
     94        return false; 
     95    } 
     96     
     97    debugOutput(DEBUG_LEVEL_VERBOSE, "Found plug: %s\n",info->getName().c_str()); 
     98     
     99    // plug name 
     100    result &= plug.setName(info->getName()); 
     101     
     102    // plug type 
     103    switch (info->m_plug_type) { 
     104        case AVCMusicSubunitPlugInfoBlock::ePT_IsoStream: 
     105            result &= plug.setPlugType(Plug::eAPT_IsoStream); 
     106            break; 
     107        case AVCMusicSubunitPlugInfoBlock::ePT_AsyncStream: 
     108            result &= plug.setPlugType(Plug::eAPT_AsyncStream); 
     109            break; 
     110        case AVCMusicSubunitPlugInfoBlock::ePT_Midi: 
     111            result &= plug.setPlugType(Plug::eAPT_Midi); 
     112            break; 
     113        case AVCMusicSubunitPlugInfoBlock::ePT_Sync: 
     114            result &= plug.setPlugType(Plug::eAPT_Sync); 
     115            break; 
     116        case AVCMusicSubunitPlugInfoBlock::ePT_Analog: 
     117            result &= plug.setPlugType(Plug::eAPT_Analog); 
     118            break; 
     119        case AVCMusicSubunitPlugInfoBlock::ePT_Digital: 
     120            result &= plug.setPlugType(Plug::eAPT_Digital); 
     121            break; 
     122    } 
     123     
     124    // number of channels 
     125    result &= plug.setNrOfChannels(info->m_nb_channels); 
     126     
     127     
     128     
     129    int idx=1; 
     130    for ( AVCMusicClusterInfoBlockVectorIterator it = info->m_Clusters.begin(); 
     131      it != info->m_Clusters.end(); 
     132      ++it ) 
     133    { 
     134        struct Plug::ClusterInfo cinfo; 
     135         
     136        AVCMusicClusterInfoBlock *c=(*it); 
     137         
     138        cinfo.m_index=idx; //FIXME: is this correct? 
     139        cinfo.m_portType=c->m_port_type; 
     140        cinfo.m_nrOfChannels=c->m_nb_signals; 
     141        cinfo.m_streamFormat=c->m_stream_format; 
     142        cinfo.m_name=c->getName(); 
     143 
     144        debugOutput(DEBUG_LEVEL_VERBOSE, "Adding cluster idx=%2d type=%02X nbch=%2d fmt=%02X name=%s\n", 
     145            cinfo.m_index, cinfo.m_portType, cinfo.m_nrOfChannels, cinfo.m_streamFormat, cinfo.m_name.c_str()); 
     146 
     147        for ( AVCMusicClusterInfoBlock::SignalInfoVectorIterator sig_it  
     148              = c->m_SignalInfos.begin(); 
     149            sig_it != c->m_SignalInfos.end(); 
     150            ++sig_it ) 
     151        { 
     152            struct AVCMusicClusterInfoBlock::sSignalInfo s=(*sig_it); 
     153            struct Plug::ChannelInfo sinfo; 
     154             
     155            sinfo.m_streamPosition=s.stream_position; 
     156            sinfo.m_location=s.stream_location; 
     157             
     158            AVCMusicPlugInfoBlock *mplug=m_status_descriptor->getMusicPlugInfoBlock(s.music_plug_id); 
     159             
     160            if (mplug==NULL) { 
     161                debugWarning("No music plug found for this signal\n"); 
     162                sinfo.m_name="unknown"; 
     163            } else { 
     164                sinfo.m_name=mplug->getName(); 
     165            } 
     166             
     167            debugOutput(DEBUG_LEVEL_VERBOSE, "Adding signal pos=%2d loc=%2d name=%s\n", 
     168                sinfo.m_streamPosition, sinfo.m_location, mplug->getName().c_str()); 
     169             
     170            cinfo.m_channelInfos.push_back(sinfo); 
     171        } 
     172 
     173        idx++; 
     174        plug.getClusterInfos().push_back(cinfo); 
     175    } 
     176     
     177     
     178    return result; 
     179 
     180} 
     181 
     182bool 
     183SubunitMusic::loadDescriptors() 
     184{ 
     185    bool result=true; 
     186    if (m_status_descriptor != NULL) { 
     187        result &= m_status_descriptor->load(); 
     188    } else { 
     189        debugError("BUG: m_status_descriptor == NULL\n"); 
     190        return false; 
     191    } 
     192    return result; 
     193} 
     194 
     195void SubunitMusic::setVerboseLevel(int l) 
     196{ 
     197    Subunit::setVerboseLevel(l); 
     198    if (m_status_descriptor != NULL) { 
     199        m_status_descriptor->setVerboseLevel(l); 
     200    } 
    54201} 
    55202 
  • branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.h

    r508 r524  
    3232 
    3333class Unit; 
     34class Plug; 
     35class AVCMusicStatusDescriptor; 
    3436 
    3537// ///////////////////////////// 
     
    4143    SubunitMusic(); 
    4244    virtual ~SubunitMusic(); 
     45     
     46    virtual bool discover(); 
     47    virtual bool initPlugFromDescriptor( Plug& plug ); 
    4348 
     49    virtual bool loadDescriptors(); 
     50     
     51    virtual void setVerboseLevel(int l); 
    4452    virtual const char* getName(); 
    45  
    4653protected: 
    4754    virtual bool serializeChild( Glib::ustring basePath, 
     
    5057                                   Util::IODeserialize& deser, 
    5158                                   Unit& avDevice ); 
     59 
     60    class AVCMusicStatusDescriptor*  m_status_descriptor; 
    5261}; 
    5362 
  • branches/echoaudio/src/libstreaming/PortManager.cpp

    r445 r524  
    2525#include "Port.h" 
    2626#include <assert.h> 
     27 
     28#include <iostream> 
     29#include <sstream> 
    2730 
    2831 
     
    5760// } 
    5861 
     62bool PortManager::makeNameUnique(Port *port) 
     63{ 
     64    bool done=false; 
     65    int idx=0; 
     66    std::string portname_orig=port->getName(); 
     67     
     68    while(!done && idx<10000) { 
     69        bool is_unique=true; 
     70         
     71        for ( PortVectorIterator it = m_Ports.begin(); 
     72        it != m_Ports.end(); 
     73        ++it ) 
     74        { 
     75            is_unique &= !((*it)->getName() == port->getName()); 
     76        } 
     77         
     78        if (is_unique) { 
     79            done=true; 
     80        } else { 
     81            std::ostringstream portname; 
     82            portname << portname_orig << idx++; 
     83             
     84            port->setName(portname.str()); 
     85        } 
     86    } 
     87     
     88    if(idx<10000) return true; 
     89    else return false; 
     90} 
     91 
    5992/** 
    6093 * 
     
    6699    assert(port); 
    67100 
    68     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s\n",port->getName().c_str()); 
    69     m_Ports.push_back(port); 
    70  
    71     return true; 
     101    debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s, type: %d, dir: %d, dtype: %d\n", 
     102        port->getName().c_str(), port->getPortType(), port->getDirection(), port->getDataType()); 
     103     
     104    if (makeNameUnique(port)) { 
     105        m_Ports.push_back(port); 
     106        return true; 
     107    } else { 
     108        return false; 
     109    } 
    72110} 
    73111 
  • branches/echoaudio/src/libstreaming/PortManager.h

    r445 r524  
    4848    virtual ~PortManager(); 
    4949 
     50    virtual bool makeNameUnique(Port *port); 
    5051    virtual bool addPort(Port *port); 
    5152    virtual bool deletePort(Port *port); 
  • branches/echoaudio/src/Makefile.am

    r508 r524  
    7171        libavc/general/avc_generic.h \ 
    7272        libavc/general/avc_connect.h \ 
     73        libavc/general/avc_signal_format.h \ 
    7374        libavc/general/avc_extended_plug_info.h \ 
    7475        libavc/general/avc_unit.h \ 
     
    112113        libavc/general/avc_subunit_info.cpp \ 
    113114        libavc/general/avc_connect.cpp \ 
     115        libavc/general/avc_signal_format.cpp \ 
    114116        libavc/general/avc_extended_cmd_generic.cpp \ 
    115117        libavc/general/avc_extended_plug_info.cpp \ 
  • branches/echoaudio/tests/Makefile.am

    r499 r524  
    2424# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    2525 
    26 #SUBDIRS=streaming 
     26SUBDIRS=streaming 
    2727 
    2828INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src $(LIBXML_CFLAGS) \ 
  • branches/echoaudio/tests/streaming/testmidistreaming1.c

    r445 r524  
    4545#include <alsa/asoundlib.h> 
    4646 
    47 #include "libfreebob/freebob_streaming.h" 
     47#include "libffado/ffado.h" 
    4848 
    4949#include "debugtools.h" 
     
    6868        snd_midi_event_t *parser; 
    6969        snd_seq_t *seq_handle; 
    70 } freebob_midi_port_t; 
     70} ffado_midi_port_t; 
    7171 
    7272typedef struct { 
    7373        snd_seq_t *seq_handle; 
    7474        int nb_seq_ports; 
    75         freebob_midi_port_t *ports[MAX_MIDI_PORTS]; 
    76 } freebob_midi_ports_t; 
     75        ffado_midi_port_t *ports[MAX_MIDI_PORTS]; 
     76} ffado_midi_ports_t; 
    7777 
    7878int open_seq(snd_seq_t **seq_handle, int in_ports[], int out_ports[], int num_in, int num_out); 
     
    113113} 
    114114 
    115 void decode_midi_byte (freebob_midi_port_t *port, int byte) { 
     115void decode_midi_byte (ffado_midi_port_t *port, int byte) { 
    116116        snd_seq_event_t ev; 
    117117        if ((snd_midi_event_encode_byte(port->parser,byte, &ev)) > 0) { 
     
    127127} 
    128128 
    129 int encode_midi_bytes(freebob_midi_port_t *port, unsigned char *byte_buff, int len) { 
     129int encode_midi_bytes(ffado_midi_port_t *port, unsigned char *byte_buff, int len) { 
    130130        return 0; 
    131131} 
     
    140140        int retval=0; 
    141141        int i=0; 
     142        int start_flag = 0; 
    142143 
    143144        int nb_periods=0; 
    144145 
    145         freebob_sample_t **audiobuffers_in; 
    146         freebob_sample_t **audiobuffers_out; 
    147         freebob_sample_t *nullbuffer; 
     146        ffado_sample_t **audiobuffers_in; 
     147        ffado_sample_t **audiobuffers_out; 
     148        ffado_sample_t *nullbuffer; 
    148149         
    149150        run=1; 
    150151 
    151         printf("Freebob MIDI streaming test application (1)\n"); 
     152        printf("Ffado MIDI streaming test application (1)\n"); 
    152153 
    153154        signal (SIGINT, sighandler); 
    154155        signal (SIGPIPE, sighandler); 
    155156 
    156         freebob_device_info_t device_info; 
    157  
    158         freebob_options_t dev_options; 
     157        ffado_device_info_t device_info; 
     158 
     159        ffado_options_t dev_options; 
    159160 
    160161        dev_options.sample_rate=-1; // -1 = detect from discovery 
     
    169170        dev_options.packetizer_priority=60; 
    170171         
    171         freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 
     172        dev_options.verbose=5; 
     173         
     174        dev_options.slave_mode=0; 
     175        dev_options.snoop_mode=0; 
     176 
     177        ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 
    172178        if (!dev) { 
    173                 fprintf(stderr,"Could not init Freebob Streaming layer\n"); 
     179                fprintf(stderr,"Could not init Ffado Streaming layer\n"); 
    174180                exit(-1); 
    175181        } 
    176182 
    177         nb_in_channels=freebob_streaming_get_nb_capture_streams(dev); 
    178         nb_out_channels=freebob_streaming_get_nb_playback_streams(dev); 
     183        nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 
     184        nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 
    179185 
    180186        int midi_in_nbchannels=0; 
     
    182188         
    183189        /* allocate intermediate buffers */ 
    184         audiobuffers_in=calloc(nb_in_channels,sizeof(freebob_sample_t *)); 
    185         audiobuffers_out=calloc(nb_in_channels,sizeof(freebob_sample_t)); 
     190        audiobuffers_in=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 
     191        audiobuffers_out=calloc(nb_in_channels,sizeof(ffado_sample_t)); 
    186192        for (i=0;i<nb_in_channels;i++) { 
    187                 audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
    188                 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
     193                audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
     194                audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
    189195                         
    190                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    191                         case freebob_stream_type_audio: 
     196                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     197                        case ffado_stream_type_audio: 
    192198                                /* assign the audiobuffer to the stream */ 
    193                                 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
    194                                 freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_float); 
     199                                ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
     200                                ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_float); 
    195201                                break; 
    196202                                 
    197203                        // this is done with read/write routines because the nb of bytes can differ. 
    198                         case freebob_stream_type_midi: 
     204                        case ffado_stream_type_midi: 
    199205                                midi_in_nbchannels++; 
    200206                        default: 
     
    203209        } 
    204210         
    205         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
     211        nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
    206212         
    207213        for (i=0;i<nb_out_channels;i++) { 
    208                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    209                         case freebob_stream_type_audio: 
     214                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     215                        case ffado_stream_type_audio: 
    210216                                if (i<nb_in_channels) { 
    211217                                        /* assign the audiobuffer to the stream */ 
    212                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
    213                                         freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_float); 
     218                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
     219                                        ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float); 
    214220                                } else { 
    215                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
    216                                         freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24);         
     221                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
     222                                        ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24);     
    217223                                } 
    218224                                break; 
    219225                                // this is done with read/write routines because the nb of bytes can differ. 
    220                         case freebob_stream_type_midi: 
     226                        case ffado_stream_type_midi: 
    221227                                midi_out_nbchannels++; 
    222228                        default: 
     
    235241                fid_out[i]=fopen(name,"w"); 
    236242 
    237                 freebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
     243                ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
    238244                fprintf(fid_out[i],"Channel name: %s\n",name); 
    239                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    240                 case freebob_stream_type_audio: 
     245                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     246                case ffado_stream_type_audio: 
    241247                        fprintf(fid_out[i],"Channel type: audio\n"); 
    242248                        break; 
    243                 case freebob_stream_type_midi: 
     249                case ffado_stream_type_midi: 
    244250                        fprintf(fid_out[i],"Channel type: midi\n"); 
    245251                        break; 
    246                 case freebob_stream_type_unknown: 
     252                case ffado_stream_type_unknown: 
    247253                        fprintf(fid_out[i],"Channel type: unknown\n"); 
    248254                        break; 
    249255                default: 
    250                 case freebob_stream_type_invalid: 
     256                case ffado_stream_type_invalid: 
    251257                        fprintf(fid_out[i],"Channel type: invalid\n"); 
    252258                        break; 
     
    258264                fid_in[i]=fopen(name,"w"); 
    259265 
    260                 freebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
    261                 fprintf(fid_in[i], "Channel name: %s\n"); 
    262                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    263                 case freebob_stream_type_audio: 
     266                ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
     267                fprintf(fid_in[i], "Channel name: %s\n", name); 
     268                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     269                case ffado_stream_type_audio: 
    264270                        fprintf(fid_in[i], "Channel type: audio\n"); 
    265271                        break; 
    266                 case freebob_stream_type_midi: 
     272                case ffado_stream_type_midi: 
    267273                        fprintf(fid_in[i], "Channel type: midi\n"); 
    268274                        break; 
    269                 case freebob_stream_type_unknown: 
     275                case ffado_stream_type_unknown: 
    270276                        fprintf(fid_in[i],"Channel type: unknown\n"); 
    271277                        break; 
    272278                default: 
    273                 case freebob_stream_type_invalid: 
     279                case ffado_stream_type_invalid: 
    274280                        fprintf(fid_in[i],"Channel type: invalid\n"); 
    275281                        break; 
     
    288294        } 
    289295 
    290         freebob_midi_port_t* midi_out_portmap[nb_out_channels]; 
    291         freebob_midi_port_t* midi_in_portmap[nb_in_channels]; 
     296        ffado_midi_port_t* midi_out_portmap[nb_out_channels]; 
     297        ffado_midi_port_t* midi_in_portmap[nb_in_channels]; 
    292298         
    293299        int cnt=0; 
    294300         
    295301        for (i=0;i<nb_out_channels;i++) { 
    296                 freebob_midi_port_t *midi_out_port; 
    297                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    298                         case freebob_stream_type_audio: 
     302                ffado_midi_port_t *midi_out_port; 
     303                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     304                        case ffado_stream_type_audio: 
    299305                                midi_out_portmap[i]=NULL; 
    300306                                break; 
    301                         case freebob_stream_type_midi: 
    302                                 midi_out_port=malloc(sizeof(freebob_midi_port_t)); 
     307                        case ffado_stream_type_midi: 
     308                                midi_out_port=malloc(sizeof(ffado_midi_port_t)); 
    303309                                if(!midi_out_port) { 
    304310                                        fprintf(stderr, "Could not allocate memory for MIDI OUT port %d\n",i); 
     
    314320                                } 
    315321                                break; 
     322                        default: break; 
    316323                } 
    317324        } 
     
    319326        cnt=0; 
    320327        for (i=0;i<nb_in_channels;i++) { 
    321                 freebob_midi_port_t *midi_in_port; 
    322                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    323                         case freebob_stream_type_audio: 
     328                ffado_midi_port_t *midi_in_port; 
     329                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     330                        case ffado_stream_type_audio: 
    324331                                midi_in_portmap[i]=NULL; 
    325332                                break; 
    326                         case freebob_stream_type_midi: 
     333                        case ffado_stream_type_midi: 
    327334                 
    328                                 midi_in_port=malloc(sizeof(freebob_midi_port_t)); 
     335                                midi_in_port=malloc(sizeof(ffado_midi_port_t)); 
    329336                                if(!midi_in_port) { 
    330337                                        fprintf(stderr, "Could not allocate memory for MIDI IN port %d\n",i); 
     
    340347                                        midi_in_portmap[i]=midi_in_port; 
    341348                                } 
    342                         break; 
     349                                break; 
     350                        default: break; 
    343351                } 
    344352        }        
    345353         
    346354        // start the streaming layer 
    347         freebob_streaming_start(dev); 
     355        start_flag = ffado_streaming_start(dev); 
    348356 
    349357        fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 
    350         while(run) { 
    351                 retval = freebob_streaming_wait(dev); 
     358        while(run && start_flag==0) { 
     359                retval = ffado_streaming_wait(dev); 
    352360                if (retval < 0) { 
    353361                        fprintf(stderr,"Xrun\n"); 
    354                         freebob_streaming_reset(dev); 
     362                        ffado_streaming_reset(dev); 
    355363                        continue; 
    356364                } 
    357365                 
    358 //              freebob_streaming_transfer_buffers(dev); 
    359                 freebob_streaming_transfer_capture_buffers(dev); 
    360                 freebob_streaming_transfer_playback_buffers(dev); 
     366//              ffado_streaming_transfer_buffers(dev); 
     367                ffado_streaming_transfer_capture_buffers(dev); 
     368                ffado_streaming_transfer_playback_buffers(dev); 
    361369                 
    362370                nb_periods++; 
     
    369377                        int s; 
    370378                         
    371                         switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    372                         case freebob_stream_type_audio: 
     379                        switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     380                        case ffado_stream_type_audio: 
    373381                                // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 
    374 //                              //samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
     382//                              //samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    375383                                samplesread=PERIOD_SIZE; 
    376384                                break; 
    377                         case freebob_stream_type_midi: 
    378                                 samplesread=freebob_streaming_read(dev, i, audiobuffers_in[i], PERIOD_SIZE); 
     385                        case ffado_stream_type_midi: 
     386                                samplesread=ffado_streaming_read(dev, i, audiobuffers_in[i], PERIOD_SIZE); 
    379387                                quadlet_t *buff=(quadlet_t *)audiobuffers_in[i]; 
    380388                                for (s=0;s<samplesread;s++) { 
     
    385393                                if(samplesread>0) { 
    386394                                        fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 
    387                                         hexDumpToFile(fid_in[i],(unsigned char*)audiobuffers_in[i],samplesread*sizeof(freebob_sample_t)); 
    388                                 } 
    389                                 break; 
     395                                        hexDumpToFile(fid_in[i],(unsigned char*)audiobuffers_in[i],samplesread*sizeof(ffado_sample_t)); 
     396                                } 
     397                                break; 
     398                        default: break; 
    390399                        } 
    391400//                      fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 
    392 //                      hexDumpToFile(fid_in[i],(unsigned char*)buff,samplesread*sizeof(freebob_sample_t)); 
     401//                      hexDumpToFile(fid_in[i],(unsigned char*)buff,samplesread*sizeof(ffado_sample_t)); 
    393402         
    394403                } 
    395404 
    396405                for(i=0;i<nb_out_channels;i++) { 
    397                         freebob_sample_t *buff; 
     406                        ffado_sample_t *buff; 
    398407                        int b=0; 
    399408                        unsigned char* byte_buff; 
     
    405414                        } 
    406415                         
    407                         switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    408                         case freebob_stream_type_audio: 
    409 //                              sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
     416                        switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     417                        case ffado_stream_type_audio: 
     418//                              sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 
    410419//                              sampleswritten=PERIOD_SIZE; 
    411420                                break; 
    412                         case freebob_stream_type_midi: 
     421                        case ffado_stream_type_midi: 
    413422                                 
    414423                                #define max_midi_bytes_to_write PERIOD_SIZE/8 
     
    418427                                 
    419428                                for(b=0;b<sampleswritten;b++) { 
    420                                         freebob_sample_t tmp_event=*(byte_buff+b); 
    421                                         freebob_streaming_write(dev, i, &tmp_event, 1); 
     429                                        ffado_sample_t tmp_event=*(byte_buff+b); 
     430                                        ffado_streaming_write(dev, i, &tmp_event, 1); 
    422431                                } 
    423432                                 
    424433                                 
    425434                                fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 
    426                                 hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(freebob_sample_t)); 
    427                                 break; 
     435                                hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 
     436                                break; 
     437                        default: break; 
    428438                        } 
    429439                } 
     
    435445        fprintf(stderr,"Exiting receive loop\n"); 
    436446         
    437         freebob_streaming_stop(dev); 
    438  
    439         freebob_streaming_finish(dev); 
     447        ffado_streaming_stop(dev); 
     448 
     449        ffado_streaming_finish(dev); 
    440450 
    441451        for (i=0;i<nb_out_channels;i++) { 
     
    457467        // free the MIDI to seq parsers and port structures 
    458468        for(i=0;i<midi_in_nbchannels;i++) { 
    459                 freebob_midi_port_t *midi_in_port=midi_in_portmap[i]; 
     469                ffado_midi_port_t *midi_in_port=midi_in_portmap[i]; 
    460470                 
    461471                if(midi_in_port) { 
     
    466476        // free the MIDI to seq parsers and port structures 
    467477        for(i=0;i<midi_out_nbchannels;i++) { 
    468                 freebob_midi_port_t *midi_out_port=midi_out_portmap[i]; 
     478                ffado_midi_port_t *midi_out_port=midi_out_portmap[i]; 
    469479 
    470480                if(midi_out_port) { 
  • branches/echoaudio/tests/streaming/teststreaming.c

    r445 r524  
    3636#include <signal.h> 
    3737 
    38 #include "libfreebob/freebob_streaming.h" 
     38#include "libffado/ffado.h" 
    3939 
    4040#include "debugtools.h" 
     
    5656        int retval=0; 
    5757        int i=0; 
     58        int start_flag = 0; 
    5859 
    5960        int nb_periods=0; 
    6061 
    61         freebob_sample_t **audiobuffer; 
    62         freebob_sample_t *nullbuffer; 
     62        ffado_sample_t **audiobuffer; 
     63        ffado_sample_t *nullbuffer; 
    6364         
    6465        run=1; 
    6566 
    66         printf("Freebob streaming test application\n"); 
     67        printf("Ffado streaming test application\n"); 
    6768 
    6869        signal (SIGINT, sighandler); 
    6970        signal (SIGPIPE, sighandler); 
    7071 
    71         freebob_device_info_t device_info; 
    72  
    73         freebob_options_t dev_options; 
     72        ffado_device_info_t device_info; 
     73 
     74        ffado_options_t dev_options; 
    7475 
    7576        dev_options.sample_rate=44100; 
     
    8384        dev_options.realtime=0; 
    8485        dev_options.packetizer_priority=60; 
    85  
    86         freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 
     86         
     87        dev_options.verbose=5; 
     88         
     89        dev_options.slave_mode=0; 
     90        dev_options.snoop_mode=0; 
     91     
     92        ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 
    8793        if (!dev) { 
    88                 fprintf(stderr,"Could not init Freebob Streaming layer\n"); 
     94                fprintf(stderr,"Could not init FFADO Streaming layer\n"); 
    8995                exit(-1); 
    9096        } 
    9197 
    92         nb_in_channels=freebob_streaming_get_nb_capture_streams(dev); 
    93         nb_out_channels=freebob_streaming_get_nb_playback_streams(dev); 
     98        nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 
     99        nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 
    94100 
    95101        /* allocate intermediate buffers */ 
    96         audiobuffer=calloc(nb_in_channels,sizeof(freebob_sample_t *)); 
    97         for (i=0;i<nb_in_channels;i++) { 
    98                 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
    99         } 
    100          
    101         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
     102        audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 
     103        for (i=0;i<nb_in_channels;i++) { 
     104                audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
     105        } 
     106         
     107        nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
    102108         
    103109        /* open the files to write to*/ 
     
    111117                fid_out[i]=fopen(name,"w"); 
    112118 
    113                 freebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
     119                ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
    114120                fprintf(fid_out[i],"Channel name: %s\n",name); 
    115                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    116                 case freebob_stream_type_audio: 
     121                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     122                case ffado_stream_type_audio: 
    117123                        fprintf(fid_out[i],"Channel type: audio\n"); 
    118124                        break; 
    119                 case freebob_stream_type_midi: 
     125                case ffado_stream_type_midi: 
    120126                        fprintf(fid_out[i],"Channel type: midi\n"); 
    121127                        break; 
    122                 case freebob_stream_type_unknown: 
     128                case ffado_stream_type_unknown: 
    123129                        fprintf(fid_out[i],"Channel type: unknown\n"); 
    124130                        break; 
    125131                default: 
    126                 case freebob_stream_type_invalid: 
     132                case ffado_stream_type_invalid: 
    127133                        fprintf(fid_out[i],"Channel type: invalid\n"); 
    128134                        break; 
     
    134140                fid_in[i]=fopen(name,"w"); 
    135141 
    136                 freebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
     142                ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
    137143                fprintf(fid_in[i], "Channel name: %s\n",name); 
    138                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    139                 case freebob_stream_type_audio: 
     144                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     145                case ffado_stream_type_audio: 
    140146                        fprintf(fid_in[i], "Channel type: audio\n"); 
    141147                        break; 
    142                 case freebob_stream_type_midi: 
     148                case ffado_stream_type_midi: 
    143149                        fprintf(fid_in[i], "Channel type: midi\n"); 
    144150                        break; 
    145                 case freebob_stream_type_unknown: 
     151                case ffado_stream_type_unknown: 
    146152                        fprintf(fid_in[i],"Channel type: unknown\n"); 
    147153                        break; 
    148154                default: 
    149                 case freebob_stream_type_invalid: 
     155                case ffado_stream_type_invalid: 
    150156                        fprintf(fid_in[i],"Channel type: invalid\n"); 
    151157                        break; 
     
    153159        } 
    154160 
    155         freebob_streaming_prepare(dev); 
    156         freebob_streaming_start(dev); 
     161        ffado_streaming_prepare(dev); 
     162        start_flag = ffado_streaming_start(dev); 
    157163 
    158164        fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 
    159         while(run) { 
    160                 retval = freebob_streaming_wait(dev); 
     165        while(run && start_flag==0) { 
     166                retval = ffado_streaming_wait(dev); 
    161167                if (retval < 0) { 
    162168                        fprintf(stderr,"Xrun\n"); 
    163                         freebob_streaming_reset(dev); 
     169                        ffado_streaming_reset(dev); 
    164170                        continue; 
    165171                } 
    166172 
    167 //              freebob_streaming_transfer_buffers(dev); 
    168                 freebob_streaming_transfer_capture_buffers(dev); 
    169                 freebob_streaming_transfer_playback_buffers(dev); 
     173//              ffado_streaming_transfer_buffers(dev); 
     174                ffado_streaming_transfer_capture_buffers(dev); 
     175                ffado_streaming_transfer_playback_buffers(dev); 
    170176                 
    171177                nb_periods++; 
     
    176182 
    177183                for(i=0;i<nb_in_channels;i++) { 
    178                         switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    179                         case freebob_stream_type_audio: 
    180                                 samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    181                                 break; 
    182                         case freebob_stream_type_midi: 
    183                                 samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
     184                        switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     185                        case ffado_stream_type_audio: 
     186                                samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
     187                                break; 
     188                        case ffado_stream_type_midi: 
     189                                samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    184190                                break; 
    185191                        default: 
     
    187193                        } 
    188194//                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread); 
    189 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(freebob_sample_t)); 
     195//                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t)); 
    190196                } 
    191197 
    192198                for(i=0;i<nb_out_channels;i++) { 
    193                         freebob_sample_t *buff; 
     199                        ffado_sample_t *buff; 
    194200                        if (i<nb_in_channels) { 
    195201                                buff=audiobuffer[i]; 
     
    198204                        } 
    199205                         
    200                         switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    201                         case freebob_stream_type_audio: 
    202                                 sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
    203                                 break; 
    204                         case freebob_stream_type_midi: 
    205                                 sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
     206                        switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     207                        case ffado_stream_type_audio: 
     208                                sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 
     209                                break; 
     210                        case ffado_stream_type_midi: 
     211                                sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 
    206212                                break; 
    207213                        default: 
     
    209215                        } 
    210216//                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 
    211 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(freebob_sample_t)); 
     217//                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 
    212218                } 
    213219 
     
    218224        fprintf(stderr,"Exiting receive loop\n"); 
    219225         
    220         freebob_streaming_stop(dev); 
    221  
    222         freebob_streaming_finish(dev); 
     226        ffado_streaming_stop(dev); 
     227 
     228        ffado_streaming_finish(dev); 
    223229 
    224230        for (i=0;i<nb_out_channels;i++) { 
  • branches/echoaudio/tests/streaming/teststreaming2.c

    r445 r524  
    3838#include <signal.h> 
    3939 
    40 #include "libfreebob/freebob_streaming.h" 
     40#include "libffado/ffado.h" 
    4141 
    4242#include "debugtools.h" 
     
    5858        int retval=0; 
    5959        int i=0; 
     60        int start_flag=0; 
    6061 
    6162        int nb_periods=0; 
    6263 
    63         freebob_sample_t **audiobuffer; 
    64         freebob_sample_t *nullbuffer; 
     64        ffado_sample_t **audiobuffer; 
     65        ffado_sample_t *nullbuffer; 
    6566         
    6667        run=1; 
    6768 
    68         printf("Freebob streaming test application (2)\n"); 
     69        printf("Ffado streaming test application (2)\n"); 
    6970 
    7071        signal (SIGINT, sighandler); 
    7172        signal (SIGPIPE, sighandler); 
    7273 
    73         freebob_device_info_t device_info; 
    74  
    75         freebob_options_t dev_options; 
     74        ffado_device_info_t device_info; 
     75 
     76        ffado_options_t dev_options; 
    7677 
    7778        dev_options.sample_rate=44100; 
     
    8586        dev_options.realtime=1; 
    8687        dev_options.packetizer_priority=60; 
    87  
    88         freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 
     88         
     89        dev_options.verbose=5; 
     90         
     91        dev_options.slave_mode=0; 
     92        dev_options.snoop_mode=0; 
     93 
     94        ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 
    8995        if (!dev) { 
    90                 fprintf(stderr,"Could not init Freebob Streaming layer\n"); 
     96                fprintf(stderr,"Could not init Ffado Streaming layer\n"); 
    9197                exit(-1); 
    9298        } 
    9399 
    94         nb_in_channels=freebob_streaming_get_nb_capture_streams(dev); 
    95         nb_out_channels=freebob_streaming_get_nb_playback_streams(dev); 
     100        nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 
     101        nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 
    96102 
    97103        /* allocate intermediate buffers */ 
    98         audiobuffer=calloc(nb_in_channels,sizeof(freebob_sample_t *)); 
    99         for (i=0;i<nb_in_channels;i++) { 
    100                 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
    101                          
    102                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    103                         case freebob_stream_type_audio: 
     104        audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 
     105        for (i=0;i<nb_in_channels;i++) { 
     106                audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
     107                         
     108                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     109                        case ffado_stream_type_audio: 
    104110                                /* assign the audiobuffer to the stream */ 
    105                                 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 
    106                                 freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_int24); 
     111                                ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 
     112                                ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_int24); 
    107113                                break; 
    108114                                // this is done with read/write routines because the nb of bytes can differ. 
    109                         case freebob_stream_type_midi: 
     115                        case ffado_stream_type_midi: 
    110116                        default: 
    111117                                break; 
     
    113119        } 
    114120         
    115         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
     121        nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
    116122 
    117123#if 1 
    118124        for (i=0;i<nb_out_channels;i++) { 
    119                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    120                         case freebob_stream_type_audio: 
     125                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     126                        case ffado_stream_type_audio: 
    121127                                if (i<nb_in_channels) { 
    122128                                        /* assign the audiobuffer to the stream */ 
    123                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffer[i]); 
     129                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffer[i]); 
    124130                                } else { 
    125                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
     131                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
    126132                                } 
    127                                 freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24); 
     133                                ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24); 
    128134                                break; 
    129135                                // this is done with read/write routines because the nb of bytes can differ. 
    130                         case freebob_stream_type_midi: 
     136                        case ffado_stream_type_midi: 
    131137                        default: 
    132138                                break; 
     
    145151                fid_out[i]=fopen(name,"w"); 
    146152 
    147                 freebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
     153                ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
    148154                fprintf(fid_out[i],"Channel name: %s\n",name); 
    149                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    150                 case freebob_stream_type_audio: 
     155                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     156                case ffado_stream_type_audio: 
    151157                        fprintf(fid_out[i],"Channel type: audio\n"); 
    152158                        break; 
    153                 case freebob_stream_type_midi: 
     159                case ffado_stream_type_midi: 
    154160                        fprintf(fid_out[i],"Channel type: midi\n"); 
    155161                        break; 
    156                 case freebob_stream_type_unknown: 
     162                case ffado_stream_type_unknown: 
    157163                        fprintf(fid_out[i],"Channel type: unknown\n"); 
    158164                        break; 
    159165                default: 
    160                 case freebob_stream_type_invalid: 
     166                case ffado_stream_type_invalid: 
    161167                        fprintf(fid_out[i],"Channel type: invalid\n"); 
    162168                        break; 
     
    168174                fid_in[i]=fopen(name,"w"); 
    169175 
    170                 freebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
     176                ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
    171177                fprintf(fid_in[i], "Channel name: %s\n",name); 
    172                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    173                 case freebob_stream_type_audio: 
     178                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     179                case ffado_stream_type_audio: 
    174180                        fprintf(fid_in[i], "Channel type: audio\n"); 
    175181                        break; 
    176                 case freebob_stream_type_midi: 
     182                case ffado_stream_type_midi: 
    177183                        fprintf(fid_in[i], "Channel type: midi\n"); 
    178184                        break; 
    179                 case freebob_stream_type_unknown: 
     185                case ffado_stream_type_unknown: 
    180186                        fprintf(fid_in[i],"Channel type: unknown\n"); 
    181187                        break; 
    182188                default: 
    183                 case freebob_stream_type_invalid: 
     189                case ffado_stream_type_invalid: 
    184190                        fprintf(fid_in[i],"Channel type: invalid\n"); 
    185191                        break; 
     
    190196 
    191197        // prepare and start the streaming layer 
    192         freebob_streaming_prepare(dev); 
    193         freebob_streaming_start(dev); 
     198        ffado_streaming_prepare(dev); 
     199        start_flag = ffado_streaming_start(dev); 
    194200 
    195201        fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 
    196         while(run) { 
    197                 retval = freebob_streaming_wait(dev); 
     202        while(run && start_flag==0) { 
     203                retval = ffado_streaming_wait(dev); 
    198204                if (retval < 0) { 
    199205                        fprintf(stderr,"Xrun\n"); 
    200                         freebob_streaming_reset(dev); 
     206                        ffado_streaming_reset(dev); 
    201207                        continue; 
    202208                } 
    203209                 
    204210                for (i=0;i<nb_in_channels;i++) { 
    205                         memset(audiobuffer[i],0xCC,(PERIOD_SIZE+1)*sizeof(freebob_sample_t)); 
    206                 } 
    207  
    208 //              freebob_streaming_transfer_buffers(dev); 
    209                 freebob_streaming_transfer_capture_buffers(dev); 
    210                 freebob_streaming_transfer_playback_buffers(dev); 
     211                        memset(audiobuffer[i],0xCC,(PERIOD_SIZE+1)*sizeof(ffado_sample_t)); 
     212                } 
     213 
     214//              ffado_streaming_transfer_buffers(dev); 
     215                ffado_streaming_transfer_capture_buffers(dev); 
     216                ffado_streaming_transfer_playback_buffers(dev); 
    211217                 
    212218                nb_periods++; 
     
    219225                         
    220226                         
    221                         switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    222                         case freebob_stream_type_audio: 
     227                        switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     228                        case ffado_stream_type_audio: 
    223229                                // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 
    224 //                              //samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
     230//                              //samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    225231                                samplesread=PERIOD_SIZE; 
    226232                                break; 
    227                         case freebob_stream_type_midi: 
    228                                 samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
     233                        case ffado_stream_type_midi: 
     234                                samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    229235                                break; 
    230236                        default: 
     
    233239         
    234240//                      fprintf(fid_in[i], "---- Period read  (%d samples) ----\n",samplesread); 
    235 //                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(freebob_sample_t)+1); 
     241//                      hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t)+1); 
    236242// FIXME: Dump analog1 as raw data to a separate binary file for testing 
    237243//if (i==2) { 
    238 //  fwrite(audiobuffer[i],sizeof(freebob_sample_t),samplesread,of); 
     244//  fwrite(audiobuffer[i],sizeof(ffado_sample_t),samplesread,of); 
    239245//} 
    240246                } 
    241247 
    242248                for(i=0;i<nb_out_channels;i++) { 
    243                         freebob_sample_t *buff; 
     249                        ffado_sample_t *buff; 
    244250                        if (i<nb_in_channels) { 
    245251                                buff=audiobuffer[i]; 
     
    248254                        } 
    249255                         
    250                         switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    251                         case freebob_stream_type_audio: 
    252 //// Calling freebob_streaming_write() causes problems since the buffer is external here. 
     256                        switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     257                        case ffado_stream_type_audio: 
     258//// Calling ffado_streaming_write() causes problems since the buffer is external here. 
    253259//// Just mirror the read case since it seems to work. 
    254 ////                            sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
     260////                            sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 
    255261                                sampleswritten=PERIOD_SIZE; 
    256262                                break; 
    257                         case freebob_stream_type_midi: 
    258                                 sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
     263                        case ffado_stream_type_midi: 
     264                                sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 
    259265                                break; 
    260266                        default: 
     
    262268                        } 
    263269//                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 
    264 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(freebob_sample_t)); 
     270//                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 
    265271                } 
    266272 
     
    271277        fprintf(stderr,"Exiting receive loop\n"); 
    272278         
    273         freebob_streaming_stop(dev); 
    274  
    275         freebob_streaming_finish(dev); 
     279        ffado_streaming_stop(dev); 
     280 
     281        ffado_streaming_finish(dev); 
    276282fclose(of); 
    277283 
  • branches/echoaudio/tests/streaming/teststreaming3.c

    r445 r524  
    3838#include <signal.h> 
    3939 
    40 #include "libfreebob/freebob_streaming.h" 
     40#include "libffado/ffado.h" 
    4141 
    4242#include "debugtools.h" 
     
    5959        int retval=0; 
    6060        int i=0; 
     61        int start_flag = 0; 
    6162 
    6263        int nb_periods=0; 
    6364 
    6465        float **audiobuffers_in; 
    65         freebob_sample_t **audiobuffers_out; 
    66         freebob_sample_t *nullbuffer; 
     66        ffado_sample_t **audiobuffers_out; 
     67        ffado_sample_t *nullbuffer; 
    6768         
    6869        run=1; 
    6970 
    70         printf("Freebob streaming test application (3)\n"); 
     71        printf("Ffado streaming test application (3)\n"); 
    7172 
    7273        signal (SIGINT, sighandler); 
    7374        signal (SIGPIPE, sighandler); 
    7475 
    75         freebob_device_info_t device_info; 
    76  
    77         freebob_options_t dev_options; 
     76        ffado_device_info_t device_info; 
     77 
     78        ffado_options_t dev_options; 
    7879 
    7980        dev_options.sample_rate=44100; 
     
    8889        dev_options.packetizer_priority=70; 
    8990         
    90         freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 
     91        dev_options.verbose=5; 
     92         
     93        dev_options.slave_mode=0; 
     94        dev_options.snoop_mode=0; 
     95         
     96        ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 
    9197        if (!dev) { 
    92                 fprintf(stderr,"Could not init Freebob Streaming layer\n"); 
     98                fprintf(stderr,"Could not init Ffado Streaming layer\n"); 
    9399                exit(-1); 
    94100        } 
    95101 
    96         nb_in_channels=freebob_streaming_get_nb_capture_streams(dev); 
    97         nb_out_channels=freebob_streaming_get_nb_playback_streams(dev); 
     102        nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 
     103        nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 
    98104 
    99105        /* allocate intermediate buffers */ 
    100106        audiobuffers_in=calloc(nb_in_channels,sizeof(float *)); 
    101         audiobuffers_out=calloc(nb_in_channels,sizeof(freebob_sample_t)); 
     107        audiobuffers_out=calloc(nb_in_channels,sizeof(ffado_sample_t)); 
    102108        for (i=0;i<nb_in_channels;i++) { 
    103109                audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(float)); 
    104                 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
    105                          
    106                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    107                         case freebob_stream_type_audio: 
     110                audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
     111                         
     112                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     113                        case ffado_stream_type_audio: 
    108114                                /* assign the audiobuffer to the stream */ 
    109                                 freebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
    110                                 freebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_float); 
     115                                ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
     116                                ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_float); 
    111117                                break; 
    112118                                // this is done with read/write routines because the nb of bytes can differ. 
    113                         case freebob_stream_type_midi: 
     119                        case ffado_stream_type_midi: 
    114120                        default: 
    115121                                break; 
     
    117123        } 
    118124         
    119         nullbuffer=calloc(PERIOD_SIZE+1,sizeof(freebob_sample_t)); 
     125        nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 
    120126         
    121127        for (i=0;i<nb_out_channels;i++) { 
    122                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    123                         case freebob_stream_type_audio: 
     128                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     129                        case ffado_stream_type_audio: 
    124130                                if (i<nb_in_channels) { 
    125131                                        /* assign the audiobuffer to the stream */ 
    126                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
    127                                         freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_float); 
     132                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 
     133                                        ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float); 
    128134                                } else { 
    129                                         freebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
    130                                         freebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24);         
     135                                        ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 
     136                                        ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24);     
    131137                                } 
    132138                                break; 
    133139                                // this is done with read/write routines because the nb of bytes can differ. 
    134                         case freebob_stream_type_midi: 
     140                        case ffado_stream_type_midi: 
    135141                        default: 
    136142                                break; 
     
    148154                fid_out[i]=fopen(name,"w"); 
    149155 
    150                 freebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
     156                ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 
    151157                fprintf(fid_out[i],"Channel name: %s\n",name); 
    152                 switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    153                 case freebob_stream_type_audio: 
     158                switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     159                case ffado_stream_type_audio: 
    154160                        fprintf(fid_out[i],"Channel type: audio\n"); 
    155161                        break; 
    156                 case freebob_stream_type_midi: 
     162                case ffado_stream_type_midi: 
    157163                        fprintf(fid_out[i],"Channel type: midi\n"); 
    158164                        break; 
    159                 case freebob_stream_type_unknown: 
     165                case ffado_stream_type_unknown: 
    160166                        fprintf(fid_out[i],"Channel type: unknown\n"); 
    161167                        break; 
    162168                default: 
    163                 case freebob_stream_type_invalid: 
     169                case ffado_stream_type_invalid: 
    164170                        fprintf(fid_out[i],"Channel type: invalid\n"); 
    165171                        break; 
     
    171177                fid_in[i]=fopen(name,"w"); 
    172178 
    173                 freebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
    174                 fprintf(fid_in[i], "Channel name: %s\n"); 
    175                 switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    176                 case freebob_stream_type_audio: 
     179                ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 
     180                fprintf(fid_in[i], "Channel name: %s\n",name); 
     181                switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     182                case ffado_stream_type_audio: 
    177183                        fprintf(fid_in[i], "Channel type: audio\n"); 
    178184                        break; 
    179                 case freebob_stream_type_midi: 
     185                case ffado_stream_type_midi: 
    180186                        fprintf(fid_in[i], "Channel type: midi\n"); 
    181187                        break; 
    182                 case freebob_stream_type_unknown: 
     188                case ffado_stream_type_unknown: 
    183189                        fprintf(fid_in[i],"Channel type: unknown\n"); 
    184190                        break; 
    185191                default: 
    186                 case freebob_stream_type_invalid: 
     192                case ffado_stream_type_invalid: 
    187193                        fprintf(fid_in[i],"Channel type: invalid\n"); 
    188194                        break; 
     
    191197 
    192198        // start the streaming layer 
    193         freebob_streaming_start(dev); 
     199        ffado_streaming_prepare(dev); 
     200        start_flag = ffado_streaming_start(dev); 
    194201 
    195202        fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 
    196         while(run) { 
    197                 retval = freebob_streaming_wait(dev); 
     203        while(run && start_flag==0) { 
     204                retval = ffado_streaming_wait(dev); 
    198205                if (retval < 0) { 
    199206                        fprintf(stderr,"Xrun\n"); 
    200                         freebob_streaming_reset(dev); 
     207                        ffado_streaming_reset(dev); 
    201208                        continue; 
    202209                } 
    203210                 
    204 //              freebob_streaming_transfer_buffers(dev); 
    205                 freebob_streaming_transfer_capture_buffers(dev); 
    206                 freebob_streaming_transfer_playback_buffers(dev); 
     211//              ffado_streaming_transfer_buffers(dev); 
     212                ffado_streaming_transfer_capture_buffers(dev); 
     213                ffado_streaming_transfer_playback_buffers(dev); 
    207214                 
    208215                nb_periods++; 
     
    215222                         
    216223                         
    217                         switch (freebob_streaming_get_capture_stream_type(dev,i)) { 
    218                         case freebob_stream_type_audio: 
     224                        switch (ffado_streaming_get_capture_stream_type(dev,i)) { 
     225                        case ffado_stream_type_audio: 
    219226                                // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 
    220227//                              //samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 
    221228                                samplesread=PERIOD_SIZE; 
    222229                                break; 
    223                         case freebob_stream_type_midi: 
    224                                 samplesread=freebob_streaming_read(dev, i, audiobuffers_out[i], PERIOD_SIZE); 
    225                                 break; 
     230                        case ffado_stream_type_midi: 
     231                                samplesread=ffado_streaming_read(dev, i, audiobuffers_out[i], PERIOD_SIZE); 
     232                                break; 
     233                        default: break; 
    226234                        } 
    227235         
     
    231239 
    232240                for(i=0;i<nb_out_channels;i++) { 
    233                         freebob_sample_t *buff; 
     241                        ffado_sample_t *buff; 
    234242                        int sampleswritten=0; 
    235243                        if (i<nb_in_channels) { 
     
    239247                        } 
    240248                         
    241                         switch (freebob_streaming_get_playback_stream_type(dev,i)) { 
    242                         case freebob_stream_type_audio: 
     249                        switch (ffado_streaming_get_playback_stream_type(dev,i)) { 
     250                        case ffado_stream_type_audio: 
    243251//                              sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
    244252                                sampleswritten=PERIOD_SIZE; 
    245253                                break; 
    246                         case freebob_stream_type_midi: 
     254                        case ffado_stream_type_midi: 
    247255//                              sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 
    248256                                break; 
     257                        default: break; 
    249258                        } 
    250259//                      fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 
    251 //                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(freebob_sample_t)); 
     260//                      hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 
    252261                } 
    253262 
     
    258267        fprintf(stderr,"Exiting receive loop\n"); 
    259268         
    260         freebob_streaming_stop(dev); 
    261  
    262         freebob_streaming_finish(dev); 
     269        ffado_streaming_stop(dev); 
     270 
     271        ffado_streaming_finish(dev); 
    263272 
    264273        for (i=0;i<nb_out_channels;i++) {