Changeset 507

Show
Ignore:
Timestamp:
07/29/07 03:27:38 (16 years ago)
Author:
ppalmers
Message:

[Temporary commit: compiles but doesn't run]

First pass on AV/C code refactoring. Generic code and data structures
are moved to libavc classes. Implementation/vendor specific stuff remains
in specific classes.

In this case all 'Extended' commands and the discovery procedures remain in
the bebob/ classes, while the remainder goes into the libavc classes.

Files:

Legend:

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

    r504 r507  
    4545namespace BeBoB { 
    4646 
     47IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); 
     48 
    4749static VendorModelEntry supportedDeviceList[] = 
    4850{ 
     
    7375                    int nodeId ) 
    7476    : FFADODevice( configRom, ieee1394service, nodeId ) 
    75     , m_pPlugManager( new AvPlugManager( DEBUG_LEVEL_NORMAL ) ) 
    76     , m_activeSyncInfo( 0 ) 
     77    , AVC::Unit( configRom, ieee1394service, nodeId ) 
    7778    , m_model ( NULL ) 
    7879    , m_Mixer ( NULL ) 
     
    9293    } 
    9394 
    94     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); 
     95    for ( SubunitVector::iterator it = m_subunits.begin(); 
    9596          it != m_subunits.end(); 
    9697          ++it ) 
     
    9899        delete *it; 
    99100    } 
    100     for ( AvPlugConnectionVector::iterator it = m_plugConnections.begin(); 
     101    for ( PlugConnectionVector::iterator it = m_plugConnections.begin(); 
    101102          it != m_plugConnections.end(); 
    102103          ++it ) 
     
    104105        delete *it; 
    105106    } 
    106     for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); 
     107    for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
    107108          it != m_pcrPlugs.end(); 
    108109          ++it ) 
     
    110111        delete *it; 
    111112    } 
    112     for ( AvPlugVector::iterator it = m_externalPlugs.begin(); 
     113    for ( PlugVector::iterator it = m_externalPlugs.begin(); 
    113114          it != m_externalPlugs.end(); 
    114115          ++it ) 
     
    121122AvDevice::setVerboseLevel(int l) 
    122123{ 
    123 //     m_pPlugManager->setVerboseLevel(l); 
     124    m_pPlugManager->setVerboseLevel(l); 
    124125 
    125126    FFADODevice::setVerboseLevel(l); 
     
    170171    } else return false; 
    171172 
    172     if ( !enumerateSubUnits() ) { 
    173         debugError( "Could not enumarate sub units\n" ); 
    174         return false; 
    175     } 
     173    if ( !Unit::discover() ) { 
     174        debugError( "Could not discover unit\n" ); 
     175        return false; 
     176    } 
     177 
     178    if((getAudioSubunit( 0 ) == NULL)) { 
     179        debugError( "Unit doesn't have an Audio subunit.\n"); 
     180        return false; 
     181    } 
     182    if((getMusicSubunit( 0 ) == NULL)) { 
     183        debugError( "Unit doesn't have a Music subunit.\n"); 
     184        return false; 
     185    } 
     186 
     187// replaced by the previous Unit discovery 
     188//     if ( !enumerateSubUnits() ) { 
     189//         debugError( "Could not enumarate sub units\n" ); 
     190//         return false; 
     191//     } 
    176192 
    177193    if ( !discoverPlugs() ) { 
     
    243259                 plugInfoCmd.m_externalOutputPlugs ); 
    244260 
    245     if ( !discoverPlugsPCR( AvPlug::eAPD_Input, 
     261    if ( !discoverPlugsPCR( Plug::eAPD_Input, 
    246262                            plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) 
    247263    { 
     
    250266    } 
    251267 
    252     if ( !discoverPlugsPCR( AvPlug::eAPD_Output, 
     268    if ( !discoverPlugsPCR( Plug::eAPD_Output, 
    253269                            plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) 
    254270    { 
     
    257273    } 
    258274 
    259     if ( !discoverPlugsExternal( AvPlug::eAPD_Input, 
     275    if ( !discoverPlugsExternal( Plug::eAPD_Input, 
    260276                                 plugInfoCmd.m_externalInputPlugs ) ) 
    261277    { 
     
    264280    } 
    265281 
    266     if ( !discoverPlugsExternal( AvPlug::eAPD_Output, 
     282    if ( !discoverPlugsExternal( Plug::eAPD_Output, 
    267283                                 plugInfoCmd.m_externalOutputPlugs ) ) 
    268284    { 
     
    275291 
    276292bool 
    277 AvDevice::discoverPlugsPCR( AvPlug::EAvPlugDirection plugDirection, 
     293AvDevice::discoverPlugsPCR( Plug::EPlugDirection plugDirection, 
    278294                            plug_id_t plugMaxId ) 
    279295{ 
     
    282298          ++plugId ) 
    283299    { 
    284         AvPlug* plug  = new AvPlug( *m_p1394Service, 
    285                                     *m_pConfigRom, 
    286                                     *m_pPlugManager, 
    287                                     eST_Unit, 
    288                                     0xff, 
    289                                     0xff, 
    290                                     0xff, 
    291                                     AvPlug::eAPA_PCR, 
    292                                     plugDirection, 
    293                                     plugId, 
    294                                     m_verboseLevel ); 
     300        AVC::Plug* plug  = new Plug( this, 
     301                                NULL, 
     302                                0xff, 
     303                                0xff, 
     304                                Plug::eAPA_PCR, 
     305                                plugDirection, 
     306                                plugId ); 
    295307        if ( !plug || !plug->discover() ) { 
    296308            debugError( "plug discovering failed\n" ); 
     
    308320 
    309321bool 
    310 AvDevice::discoverPlugsExternal( AvPlug::EAvPlugDirection plugDirection, 
     322AvDevice::discoverPlugsExternal( Plug::EPlugDirection plugDirection, 
    311323                                 plug_id_t plugMaxId ) 
    312324{ 
     
    315327          ++plugId ) 
    316328    { 
    317         AvPlug* plug  = new AvPlug( *m_p1394Service, 
    318                                     *m_pConfigRom, 
    319                                     *m_pPlugManager, 
    320                                     eST_Unit, 
    321                                     0xff, 
    322                                     0xff, 
    323                                     0xff, 
    324                                     AvPlug::eAPA_ExternalPlug, 
    325                                     plugDirection, 
    326                                     plugId, 
    327                                     m_verboseLevel ); 
     329        AVC::Plug* plug  = new Plug( this, NULL, 
     330                                0xff, 
     331                                0xff, 
     332                                Plug::eAPA_ExternalPlug, 
     333                                plugDirection, 
     334                                plugId ); 
    328335        if ( !plug || !plug->discover() ) { 
    329336            debugError( "plug discovering failed\n" ); 
     
    342349AvDevice::discoverPlugConnections() 
    343350{ 
    344     for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); 
     351    for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
    345352          it != m_pcrPlugs.end(); 
    346353          ++it ) 
    347354    { 
    348         AvPlug* plug = *it; 
     355        AVC::Plug* plug = *it; 
    349356        if ( !plug->discoverConnections() ) { 
    350357            debugError( "Could not discover plug connections\n" ); 
     
    352359        } 
    353360    } 
    354     for ( AvPlugVector::iterator it = m_externalPlugs.begin(); 
     361    for ( PlugVector::iterator it = m_externalPlugs.begin(); 
    355362          it != m_externalPlugs.end(); 
    356363          ++it ) 
    357364    { 
    358         AvPlug* plug = *it; 
     365        AVC::Plug* plug = *it; 
    359366        if ( !plug->discoverConnections() ) { 
    360367            debugError( "Could not discover plug connections\n" ); 
     
    369376AvDevice::discoverSubUnitsPlugConnections() 
    370377{ 
    371     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); 
    372           it != m_subunits.end(); 
    373           ++it ) 
    374     { 
    375         AvDeviceSubunit* subunit = *it; 
    376         if ( !subunit->discoverConnections() ) { 
    377             debugError( "Subunit '%s'  plug connections failed\n", 
    378                         subunit->getName() ); 
    379             return false; 
    380         } 
    381     } 
     378//     for ( SubunitVector::iterator it = m_subunits.begin(); 
     379//           it != m_subunits.end(); 
     380//           ++it ) 
     381//     { 
     382//         Subunit* subunit = *it; 
     383//         if ( !subunit->discoverConnections() ) { 
     384//             debugError( "Subunit '%s'  plug connections failed\n", 
     385//                         subunit->getName() ); 
     386//             return false; 
     387//         } 
     388//     } 
    382389    return true; 
    383390} 
     
    404411    // MSU input means subunit-to-device 
    405412 
    406     AvPlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    407                                                      AvPlug::eAPD_Input, 
    408                                                      AvPlug::eAPT_Sync ); 
     413    PlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
     414                                                     Plug::eAPD_Input, 
     415                                                     Plug::eAPT_Sync ); 
    409416    if ( !syncPCRInputPlugs.size() ) { 
    410417        debugWarning( "No PCR sync input plug found\n" ); 
    411418    } 
    412419 
    413     AvPlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    414                                                       AvPlug::eAPD_Output, 
    415                                                       AvPlug::eAPT_Sync ); 
     420    PlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
     421                                                      Plug::eAPD_Output, 
     422                                                      Plug::eAPT_Sync ); 
    416423    if ( !syncPCROutputPlugs.size() ) { 
    417424        debugWarning( "No PCR sync output plug found\n" ); 
    418425    } 
    419426 
    420     AvPlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    421                                                     AvPlug::eAPD_Input, 
    422                                                     AvPlug::eAPT_IsoStream ); 
     427    PlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
     428                                                    Plug::eAPD_Input, 
     429                                                    Plug::eAPT_IsoStream ); 
    423430    if ( !isoPCRInputPlugs.size() ) { 
    424431        debugWarning( "No PCR iso input plug found\n" ); 
     
    426433    } 
    427434 
    428     AvPlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    429                                                     AvPlug::eAPD_Output, 
    430                                                     AvPlug::eAPT_IsoStream ); 
     435    PlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
     436                                                    Plug::eAPD_Output, 
     437                                                    Plug::eAPT_IsoStream ); 
    431438    if ( !isoPCROutputPlugs.size() ) { 
    432439        debugWarning( "No PCR iso output plug found\n" ); 
     
    434441    } 
    435442 
    436     AvPlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 
    437                                                     AvPlug::eAPD_Input, 
    438                                                     AvPlug::eAPT_Digital ); 
    439  
    440     AvPlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
     443    PlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 
     444                                                    Plug::eAPD_Input, 
     445                                                    Plug::eAPT_Digital ); 
     446 
     447    PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
    441448        eST_Music, 
    442449        0, 
    443450        0xff, 
    444451        0xff, 
    445         AvPlug::eAPA_SubunitPlug, 
    446         AvPlug::eAPD_Input, 
    447         AvPlug::eAPT_Sync ); 
     452        Plug::eAPA_SubunitPlug, 
     453        Plug::eAPD_Input, 
     454        Plug::eAPT_Sync ); 
    448455    if ( !syncMSUInputPlugs.size() ) { 
    449456        debugWarning( "No sync input plug for MSU subunit found\n" ); 
    450457    } 
    451458 
    452     AvPlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 
     459    PlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 
    453460        eST_Music, 
    454461        0, 
    455462        0xff, 
    456463        0xff, 
    457         AvPlug::eAPA_SubunitPlug, 
    458         AvPlug::eAPD_Output, 
    459         AvPlug::eAPT_Sync ); 
     464        Plug::eAPA_SubunitPlug, 
     465        Plug::eAPD_Output, 
     466        Plug::eAPT_Sync ); 
    460467    if ( !syncMSUOutputPlugs.size() ) { 
    461468        debugWarning( "No sync output plug for MSU subunit found\n" ); 
     
    463470 
    464471    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); 
    465     showAvPlugs( syncPCRInputPlugs ); 
     472    showPlugs( syncPCRInputPlugs ); 
    466473    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); 
    467     showAvPlugs( syncPCROutputPlugs ); 
     474    showPlugs( syncPCROutputPlugs ); 
    468475    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); 
    469     showAvPlugs( isoPCRInputPlugs ); 
     476    showPlugs( isoPCRInputPlugs ); 
    470477    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); 
    471     showAvPlugs( isoPCROutputPlugs ); 
     478    showPlugs( isoPCROutputPlugs ); 
    472479    debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); 
    473     showAvPlugs( digitalPCRInputPlugs ); 
     480    showPlugs( digitalPCRInputPlugs ); 
    474481    debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); 
    475     showAvPlugs( syncMSUInputPlugs ); 
     482    showPlugs( syncMSUInputPlugs ); 
    476483    debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); 
    477     showAvPlugs( syncMSUOutputPlugs ); 
     484    showPlugs( syncMSUOutputPlugs ); 
    478485 
    479486    // Check all possible PCR input to MSU input connections 
     
    510517    // status, source unknown, destination MSU sync input plug 
    511518 
    512     for ( AvPlugVector::const_iterator it = syncMSUInputPlugs.begin(); 
     519    for ( PlugVector::const_iterator it = syncMSUInputPlugs.begin(); 
    513520          it != syncMSUInputPlugs.end(); 
    514521          ++it ) 
    515522    { 
    516         AvPlug* msuPlug = *it; 
    517         for ( AvPlugVector::const_iterator jt = 
     523        AVC::Plug* msuPlug = *it; 
     524        for ( PlugVector::const_iterator jt = 
    518525                  msuPlug->getInputConnections().begin(); 
    519526              jt != msuPlug->getInputConnections().end(); 
    520527              ++jt ) 
    521528        { 
    522             AvPlug* plug = *jt; 
     529            AVC::Plug* plug = *jt; 
    523530 
    524531            for ( SyncInfoVector::iterator it = m_syncInfos.begin(); 
     
    545552 
    546553bool 
    547 AvDevice::enumerateSubUnits() 
    548 { 
    549     bool musicSubunitFound=false; 
    550     bool audioSubunitFound=false; 
    551  
    552     SubUnitInfoCmd subUnitInfoCmd( *m_p1394Service ); 
    553     //subUnitInfoCmd.setVerbose( 1 ); 
    554     subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    555  
    556     // BeBoB has always exactly one audio and one music subunit. This 
    557     // means is fits into the first page of the SubUnitInfo command. 
    558     // So there is no need to do more than needed 
    559  
    560     subUnitInfoCmd.m_page = 0; 
    561     subUnitInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    562     subUnitInfoCmd.setVerbose( m_verboseLevel ); 
    563     if ( !subUnitInfoCmd.fire() ) { 
    564         debugError( "Subunit info command failed\n" ); 
    565         // shouldn't this be an error situation? 
    566         return false; 
    567     } 
    568  
    569     for ( int i = 0; i < subUnitInfoCmd.getNrOfValidEntries(); ++i ) { 
    570         subunit_type_t subunit_type 
    571             = subUnitInfoCmd.m_table[i].m_subunit_type; 
    572  
    573         unsigned int subunitId = getNrOfSubunits( subunit_type ); 
    574  
    575         debugOutput( DEBUG_LEVEL_VERBOSE, 
    576                      "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    577                      subunitId, 
    578                      subunit_type, 
    579                      subunitTypeToString( subunit_type ) ); 
    580  
    581         AvDeviceSubunit* subunit = 0; 
    582         switch( subunit_type ) { 
    583         case eST_Audio: 
    584             subunit = new AvDeviceSubunitAudio( *this, 
    585                                                 subunitId, 
    586                                                 m_verboseLevel ); 
    587             if ( !subunit ) { 
    588                 debugFatal( "Could not allocate AvDeviceSubunitAudio\n" ); 
    589                 return false; 
    590             } 
    591             if ( !subunit ) { 
    592                 debugFatal( "Could not allocate AvDeviceSubunitMusic\n" ); 
    593                 return false; 
    594             } 
    595              
    596             if ( !subunit->discover() ) { 
    597                 debugError( "enumerateSubUnits: Could not discover " 
    598                             "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    599                             subunitId, 
    600                             subunit_type, 
    601                             subunitTypeToString( subunit_type ) ); 
    602                 delete subunit; 
    603                 return false; 
    604             } else { 
    605                 m_subunits.push_back( subunit ); 
    606                 audioSubunitFound=true; 
    607             } 
    608              
    609             break; 
    610         case eST_Music: 
    611             subunit = new AvDeviceSubunitMusic( *this, 
    612                                                 subunitId, 
    613                                                 m_verboseLevel ); 
    614             if ( !subunit ) { 
    615                 debugFatal( "Could not allocate AvDeviceSubunitMusic\n" ); 
    616                 return false; 
    617             } 
    618             if ( !subunit->discover() ) { 
    619                 debugError( "enumerateSubUnits: Could not discover " 
    620                             "subunit_id = %2d, subunit_type = %2d (%s)\n", 
    621                             subunitId, 
    622                             subunit_type, 
    623                             subunitTypeToString( subunit_type ) ); 
    624                 delete subunit; 
    625                 return false; 
    626             } else { 
    627                 m_subunits.push_back( subunit ); 
    628                 musicSubunitFound=true; 
    629             } 
    630  
    631             break; 
    632         default: 
    633             debugOutput( DEBUG_LEVEL_NORMAL, 
    634                          "Unsupported subunit found, subunit_type = %d (%s)\n", 
    635                          subunit_type, 
    636                          subunitTypeToString( subunit_type ) ); 
    637             continue; 
    638  
    639         } 
    640  
    641     } 
    642  
    643     // a BeBoB always has an audio and a music subunit 
    644     return (musicSubunitFound && audioSubunitFound); 
    645 } 
    646  
    647  
    648 AvDeviceSubunit* 
    649 AvDevice::getSubunit( subunit_type_t subunitType, 
    650                       subunit_id_t subunitId ) const 
    651 { 
    652     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); 
    653           it != m_subunits.end(); 
    654           ++it ) 
    655     { 
    656         AvDeviceSubunit* subunit = *it; 
    657         if ( ( subunitType == subunit->getSubunitType() ) 
    658              && ( subunitId == subunit->getSubunitId() ) ) 
    659         { 
    660             return subunit; 
    661         } 
    662     } 
    663  
    664     return 0; 
    665 } 
    666  
    667  
    668 unsigned int 
    669 AvDevice::getNrOfSubunits( subunit_type_t subunitType ) const 
    670 { 
    671     unsigned int nrOfSubunits = 0; 
    672  
    673     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); 
    674           it != m_subunits.end(); 
    675           ++it ) 
    676     { 
    677         AvDeviceSubunit* subunit = *it; 
    678         if ( subunitType == subunit->getSubunitType() ) { 
    679             nrOfSubunits++; 
    680         } 
    681     } 
    682  
    683     return nrOfSubunits; 
    684 } 
    685  
    686 AvPlugConnection* 
    687 AvDevice::getPlugConnection( AvPlug& srcPlug ) const 
    688 { 
    689     for ( AvPlugConnectionVector::const_iterator it 
    690               = m_plugConnections.begin(); 
    691           it != m_plugConnections.end(); 
    692           ++it ) 
    693     { 
    694         AvPlugConnection* plugConnection = *it; 
    695         if ( &( plugConnection->getSrcPlug() ) == &srcPlug ) { 
    696             return plugConnection; 
    697         } 
    698     } 
    699  
    700     return 0; 
    701 } 
    702  
    703 AvPlug* 
    704 AvDevice::getPlugById( AvPlugVector& plugs, 
    705                        AvPlug::EAvPlugDirection plugDirection, 
    706                        int id ) 
    707 { 
    708     for ( AvPlugVector::iterator it = plugs.begin(); 
    709           it != plugs.end(); 
    710           ++it ) 
    711     { 
    712         AvPlug* plug = *it; 
    713         if ( ( id == plug->getPlugId() ) 
    714              && ( plugDirection == plug->getPlugDirection() ) ) 
    715         { 
    716             return plug; 
    717         } 
    718     } 
    719  
    720     return 0; 
    721 } 
    722  
    723 AvPlugVector 
    724 AvDevice::getPlugsByType( AvPlugVector& plugs, 
    725                           AvPlug::EAvPlugDirection plugDirection, 
    726                           AvPlug::EAvPlugType type) 
    727 { 
    728     AvPlugVector plugVector; 
    729     for ( AvPlugVector::iterator it = plugs.begin(); 
    730           it != plugs.end(); 
    731           ++it ) 
    732     { 
    733         AvPlug* plug = *it; 
    734         if ( ( type == plug->getPlugType() ) 
    735              && ( plugDirection == plug->getPlugDirection() ) ) 
    736         { 
    737             plugVector.push_back( plug ); 
    738         } 
    739     } 
    740  
    741     return plugVector; 
    742 } 
    743  
    744 AvPlug* 
    745 AvDevice::getSyncPlug( int maxPlugId, AvPlug::EAvPlugDirection ) 
    746 { 
    747     return 0; 
    748 } 
    749  
    750 bool 
    751554AvDevice::setSamplingFrequency( int s ) 
    752555{ 
     
    766569        return true; 
    767570    } else { 
    768         AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
     571        AVC::Plug* plug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
    769572        if ( !plug ) { 
    770573            debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
     
    773576 
    774577        if ( !setSamplingFrequencyPlug( *plug, 
    775                                         AvPlug::eAPD_Input, 
     578                                        Plug::eAPD_Input, 
    776579                                        samplingFrequency ) ) 
    777580        { 
     
    780583        } 
    781584 
    782         plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output,  0 ); 
     585        plug = getPlugById( m_pcrPlugs, Plug::eAPD_Output,  0 ); 
    783586        if ( !plug ) { 
    784587            debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     
    787590 
    788591        if ( !setSamplingFrequencyPlug( *plug, 
    789                                         AvPlug::eAPD_Output, 
     592                                        Plug::eAPD_Output, 
    790593                                        samplingFrequency ) ) 
    791594        { 
     
    805608int 
    806609AvDevice::getSamplingFrequency( ) { 
    807     AvPlug* inputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
     610    AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
    808611    if ( !inputPlug ) { 
    809612        debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    810613        return false; 
    811614    } 
    812     AvPlug* outputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output, 0 ); 
     615    AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 
    813616    if ( !outputPlug ) { 
    814617        debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     
    827630 
    828631bool 
    829 AvDevice::setSamplingFrequencyPlug( AvPlug& plug, 
    830                                     AvPlug::EAvPlugDirection direction, 
     632AvDevice::setSamplingFrequencyPlug( AVC::Plug& plug, 
     633                                    Plug::EPlugDirection direction, 
    831634                                    ESamplingFrequency samplingFrequency ) 
    832635{ 
     
    840643    extStreamFormatCmd.setPlugAddress( 
    841644        PlugAddress( 
    842             AvPlug::convertPlugDirection(direction ), 
     645            Plug::convertPlugDirection(direction ), 
    843646            PlugAddress::ePAM_Unit, 
    844647            unitPlugAddress ) ); 
     
    937740} 
    938741 
    939 void 
    940 AvDevice::showAvPlugs( AvPlugVector& plugs ) const 
    941 
    942     int i = 0; 
    943     for ( AvPlugVector::const_iterator it = plugs.begin(); 
    944           it != plugs.end(); 
    945           ++it, ++i ) 
    946     { 
    947         AvPlug* plug = *it; 
    948         debugOutput( DEBUG_LEVEL_VERBOSE, "Plug %d\n", i ); 
    949         plug->showPlug(); 
    950     } 
    951 
    952  
    953 bool 
    954 AvDevice::checkSyncConnectionsAndAddToList( AvPlugVector& plhs, 
    955                                             AvPlugVector& prhs, 
     742bool 
     743AvDevice::checkSyncConnectionsAndAddToList( PlugVector& plhs, 
     744                                            PlugVector& prhs, 
    956745                                            std::string syncDescription ) 
    957746{ 
    958     for ( AvPlugVector::iterator plIt = plhs.begin(); 
     747    for ( PlugVector::iterator plIt = plhs.begin(); 
    959748          plIt != plhs.end(); 
    960749          ++plIt ) 
    961750    { 
    962         AvPlug* pl = *plIt; 
    963         for ( AvPlugVector::iterator prIt = prhs.begin(); 
     751        AVC::Plug* pl = *plIt; 
     752        for ( PlugVector::iterator prIt = prhs.begin(); 
    964753              prIt != prhs.end(); 
    965754              ++prIt ) 
    966755        { 
    967             AvPlug* pr = *prIt; 
     756            AVC::Plug* pr = *prIt; 
    968757            if ( pl->inquireConnnection( *pr ) ) { 
    969758                m_syncInfos.push_back( SyncInfo( *pl, *pr, syncDescription ) ); 
     
    1024813    // get plugs 
    1025814 
    1026     AvPlug* inputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
     815    AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 
    1027816    if ( !inputPlug ) { 
    1028817        debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    1029818        return false; 
    1030819    } 
    1031     AvPlug* outputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output, 0 ); 
     820    AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 
    1032821    if ( !outputPlug ) { 
    1033822        debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
     
    1109898bool 
    1110899AvDevice::addPlugToProcessor( 
    1111     AvPlug& plug, 
     900    AVC::Plug& plug, 
    1112901    Streaming::StreamProcessor *processor, 
    1113902    Streaming::AmdtpAudioPort::E_Direction direction) { 
     
    1118907    } 
    1119908 
    1120     AvPlug::ClusterInfoVector& clusterInfos = plug.getClusterInfos(); 
    1121     for ( AvPlug::ClusterInfoVector::const_iterator it = clusterInfos.begin(); 
     909    Plug::ClusterInfoVector& clusterInfos = plug.getClusterInfos(); 
     910    for ( Plug::ClusterInfoVector::const_iterator it = clusterInfos.begin(); 
    1122911          it != clusterInfos.end(); 
    1123912          ++it ) 
    1124913    { 
    1125         const AvPlug::ClusterInfo* clusterInfo = &( *it ); 
    1126  
    1127         AvPlug::ChannelInfoVector channelInfos = clusterInfo->m_channelInfos; 
    1128         for ( AvPlug::ChannelInfoVector::const_iterator it = channelInfos.begin(); 
     914        const Plug::ClusterInfo* clusterInfo = &( *it ); 
     915 
     916        Plug::ChannelInfoVector channelInfos = clusterInfo->m_channelInfos; 
     917        for ( Plug::ChannelInfoVector::const_iterator it = channelInfos.begin(); 
    1129918              it != channelInfos.end(); 
    1130919              ++it ) 
    1131920        { 
    1132             const AvPlug::ChannelInfo* channelInfo = &( *it ); 
     921            const Plug::ChannelInfo* channelInfo = &( *it ); 
    1133922            std::ostringstream portname; 
    1134923 
     
    13551144template <typename T, typename VT> bool deserializeVector( Glib::ustring path, 
    13561145                                                           Util::IODeserialize& deser, 
    1357                                                            AvDevice& avDevice, 
     1146                                                           Unit& avDevice, 
    13581147                                                           VT& vec ) 
    13591148{ 
     
    13781167 
    13791168bool 
    1380 AvDevice::serializeSyncInfoVector( Glib::ustring basePath, 
    1381                                    Util::IOSerialize& ser, 
    1382                                    const SyncInfoVector& vec ) 
    1383 { 
    1384     bool result = true; 
    1385     int i = 0; 
    1386  
    1387     for ( SyncInfoVector::const_iterator it = vec.begin(); 
    1388           it != vec.end(); 
    1389           ++it ) 
    1390     { 
    1391         const SyncInfo& info = *it; 
    1392  
    1393         std::ostringstream strstrm; 
    1394         strstrm << basePath << i << "/"; 
    1395  
    1396         result &= ser.write( strstrm.str() + "m_source", info.m_source->getGlobalId() ); 
    1397         result &= ser.write( strstrm.str() + "m_destination", info.m_destination->getGlobalId() ); 
    1398         result &= ser.write( strstrm.str() + "m_description", Glib::ustring( info.m_description ) ); 
    1399  
    1400         i++; 
    1401     } 
    1402  
    1403     return result; 
    1404 } 
    1405  
    1406 bool 
    1407 AvDevice::deserializeSyncInfoVector( Glib::ustring basePath, 
    1408                                      Util::IODeserialize& deser, 
    1409                                      AvDevice& avDevice, 
    1410                                      SyncInfoVector& vec ) 
    1411 { 
    1412     int i = 0; 
    1413     bool bFinished = false; 
    1414     do { 
    1415         bool result; 
    1416         std::ostringstream strstrm; 
    1417         strstrm << basePath << i << "/"; 
    1418  
    1419         plug_id_t sourceId; 
    1420         plug_id_t destinationId; 
    1421         Glib::ustring description; 
    1422  
    1423         result  = deser.read( strstrm.str() + "m_source", sourceId ); 
    1424         result &= deser.read( strstrm.str() + "m_destination", destinationId ); 
    1425         result &= deser.read( strstrm.str() + "m_description", description ); 
    1426  
    1427         if ( result ) { 
    1428             SyncInfo syncInfo; 
    1429             syncInfo.m_source = avDevice.getPlugManager().getPlug( sourceId ); 
    1430             syncInfo.m_destination = avDevice.getPlugManager().getPlug( destinationId ); 
    1431             syncInfo.m_description = description; 
    1432  
    1433             vec.push_back( syncInfo ); 
    1434             i++; 
    1435         } else { 
    1436             bFinished = true; 
    1437         } 
    1438     } while ( !bFinished ); 
    1439  
    1440     return true; 
    1441 } 
    1442  
    1443 static bool 
    1444 deserializeAvPlugUpdateConnections( Glib::ustring path, 
    1445                                     Util::IODeserialize& deser, 
    1446                                     AvPlugVector& vec ) 
    1447 { 
    1448     bool result = true; 
    1449     for ( AvPlugVector::iterator it = vec.begin(); 
    1450           it != vec.end(); 
    1451           ++it ) 
    1452     { 
    1453         AvPlug* pPlug = *it; 
    1454         result &= pPlug->deserializeUpdate( path, deser ); 
    1455     } 
    1456     return result; 
    1457 } 
    1458  
    1459 bool 
    14601169AvDevice::serialize( Glib::ustring basePath, 
    14611170                     Util::IOSerialize& ser ) const 
     
    14641173    bool result; 
    14651174    result  = m_pConfigRom->serialize( basePath + "m_pConfigRom/", ser ); 
    1466     result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel ); 
    1467     result &= m_pPlugManager->serialize( basePath + "AvPlug", ser ); // serialize all av plugs 
     1175    result &= ser.write( basePath + "m_verboseLevel", getDebugLevel() ); 
     1176    result &= m_pPlugManager->serialize( basePath + "Plug", ser ); // serialize all av plugs 
    14681177    result &= serializeVector( basePath + "PlugConnection", ser, m_plugConnections ); 
    14691178    result &= serializeVector( basePath + "Subunit", ser, m_subunits ); 
     
    15091218    if ( pDev ) { 
    15101219        bool result; 
    1511         result  = deser.read( basePath + "m_verboseLevel", pDev->m_verboseLevel ); 
    1512  
    1513         if (pDev->m_pPlugManager) delete pDev->m_pPlugManager; 
    1514         pDev->m_pPlugManager = AvPlugManager::deserialize( basePath + "AvPlug", deser, *pDev ); 
    1515         if ( !pDev->m_pPlugManager ) { 
    1516             delete pDev; 
    1517             return 0; 
    1518         } 
    1519         result &= deserializeAvPlugUpdateConnections( basePath + "AvPlug", deser, pDev->m_pcrPlugs ); 
    1520         result &= deserializeAvPlugUpdateConnections( basePath + "AvPlug", deser, pDev->m_externalPlugs ); 
    1521         result &= deserializeVector<AvPlugConnection>( basePath + "PlugConnnection", deser, *pDev, pDev->m_plugConnections ); 
    1522         result &= deserializeVector<AvDeviceSubunit>( basePath + "Subunit",  deser, *pDev, pDev->m_subunits ); 
    1523         result &= deserializeSyncInfoVector( basePath + "SyncInfo", deser, *pDev, pDev->m_syncInfos ); 
    1524  
    1525         unsigned int i; 
    1526         result &= deser.read( basePath + "m_activeSyncInfo", i ); 
    1527  
    1528         if ( result ) { 
    1529             if ( i < pDev->m_syncInfos.size() ) { 
    1530                 pDev->m_activeSyncInfo = &pDev->m_syncInfos[i]; 
    1531             } 
    1532         } 
     1220        int verboseLevel; 
     1221        result  = deser.read( basePath + "m_verboseLevel", verboseLevel ); 
     1222        setDebugLevel( verboseLevel ); 
     1223         
     1224        result &= AVC::Unit::deserialize(basePath, pDev, deser, ieee1394Service); 
    15331225 
    15341226        result &= deserializeOptions( basePath + "Options", deser, *pDev ); 
  • branches/echoaudio/src/bebob/bebob_avdevice.h

    r504 r507  
    3030#include "libavc/avc_definitions.h" 
    3131#include "libavc/general/avc_extended_cmd_generic.h" 
     32#include "libavc/general/avc_unit.h" 
     33#include "libavc/general/avc_subunit.h" 
     34#include "libavc/general/avc_plug.h" 
    3235 
    3336#include "bebob/bebob_avplug.h" 
     
    5861}; 
    5962 
    60 class AvDevice : public FFADODevice
     63class AvDevice : public FFADODevice, public AVC::Unit
    6164public: 
    6265    AvDevice( std::auto_ptr<ConfigRom>( configRom ), 
     
    8588    virtual void showDevice(); 
    8689 
    87     Ieee1394Service& get1394Service() 
    88         { return *m_p1394Service; } 
    89  
    90     AvPlugManager& getPlugManager() 
    91         { return *m_pPlugManager; } 
    92  
    93     struct SyncInfo { 
    94         SyncInfo( AvPlug& source, 
    95                   AvPlug& destination, 
    96                   std::string description ) 
    97             : m_source( &source ) 
    98             , m_destination( &destination ) 
    99             , m_description( description ) 
    100             {} 
    101         SyncInfo() 
    102             : m_source( 0 ) 
    103             , m_destination( 0 ) 
    104             , m_description( "" ) 
    105             {} 
    106         AvPlug*     m_source; 
    107         AvPlug*     m_destination; 
    108         std::string m_description; 
    109     }; 
    110  
    111     typedef std::vector<SyncInfo> SyncInfoVector; 
    112     const SyncInfoVector& getSyncInfos() const 
    113         { return m_syncInfos; } 
    114     const SyncInfo* getActiveSyncInfo() const 
    115         { return m_activeSyncInfo; } 
    11690    bool setActiveSync( const SyncInfo& syncInfo ); 
    11791 
     
    11993    static AvDevice* deserialize( Glib::ustring basePath, 
    12094                                  Util::IODeserialize& deser, 
    121                   Ieee1394Service& ieee1394Service ); 
    122     AvDeviceSubunitAudio* getAudioSubunit( AVC::subunit_id_t subunitId ) 
    123         { return dynamic_cast<AvDeviceSubunitAudio*>( 
    124                    getSubunit( AVC1394_SUBUNIT_AUDIO , subunitId ));}; 
     95                                  Ieee1394Service& ieee1394Service ); 
    12596 
     97    // redefinition to resolve ambiguity 
     98    Ieee1394Service& get1394Service() 
     99        { return *m_p1394Service; } 
     100    ConfigRom& getConfigRom() const  
     101        {return FFADODevice::getConfigRom();}; 
     102         
    126103protected: 
    127104 
    128     bool enumerateSubUnits(); 
    129  
    130105    bool discoverPlugs(); 
    131     bool discoverPlugsPCR( AvPlug::EAvPlugDirection plugDirection, 
     106    bool discoverPlugsPCR( AVC::Plug::EPlugDirection plugDirection, 
    132107                           AVC::plug_id_t plugMaxId ); 
    133     bool discoverPlugsExternal( AvPlug::EAvPlugDirection plugDirection, 
     108    bool discoverPlugsExternal( AVC::Plug::EPlugDirection plugDirection, 
    134109                                AVC::plug_id_t plugMaxId ); 
    135110    bool discoverPlugConnections(); 
     
    137112    bool discoverSubUnitsPlugConnections(); 
    138113 
    139     AvDeviceSubunit* getSubunit( AVC::subunit_type_t subunitType, 
    140                                  AVC::subunit_id_t subunitId ) const; 
    141  
    142     unsigned int getNrOfSubunits( AVC::subunit_type_t subunitType ) const; 
    143     AvPlugConnection* getPlugConnection( AvPlug& srcPlug ) const; 
    144  
    145     AvPlug* getSyncPlug( int maxPlugId, AvPlug::EAvPlugDirection ); 
    146  
    147     AvPlug* getPlugById( AvPlugVector& plugs, 
    148                          AvPlug::EAvPlugDirection plugDireciton, 
    149                          int id ); 
    150     AvPlugVector getPlugsByType( AvPlugVector& plugs, 
    151                  AvPlug::EAvPlugDirection plugDirection, 
    152                  AvPlug::EAvPlugType type); 
    153  
    154     bool addPlugToProcessor( AvPlug& plug, Streaming::StreamProcessor *processor, 
     114    bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, 
    155115                             Streaming::AmdtpAudioPort::E_Direction direction); 
    156116 
    157     bool setSamplingFrequencyPlug( AvPlug& plug, 
    158                                    AvPlug::EAvPlugDirection direction, 
     117    bool setSamplingFrequencyPlug( AVC::Plug& plug, 
     118                                   AVC::Plug::EPlugDirection direction, 
    159119                                   AVC::ESamplingFrequency samplingFrequency ); 
    160120 
    161     void showAvPlugs( AvPlugVector& plugs ) const; 
    162  
    163     bool checkSyncConnectionsAndAddToList( AvPlugVector& plhs, 
    164                                            AvPlugVector& prhs, 
     121    bool checkSyncConnectionsAndAddToList( AVC::PlugVector& plhs, 
     122                                           AVC::PlugVector& prhs, 
    165123                                           std::string syncDescription ); 
    166124 
    167     static bool serializeSyncInfoVector( Glib::ustring basePath, 
    168                                          Util::IOSerialize& ser, 
    169                                          const SyncInfoVector& vec ); 
    170     static bool deserializeSyncInfoVector( Glib::ustring basePath, 
    171                                            Util::IODeserialize& deser, 
    172                                            AvDevice& avDevice, 
    173                                            SyncInfoVector& vec ); 
    174125protected: 
    175     AvPlugVector              m_pcrPlugs; 
    176     AvPlugVector              m_externalPlugs; 
    177     AvPlugConnectionVector    m_plugConnections; 
    178     AvDeviceSubunitVector     m_subunits; 
    179     AvPlugManager*            m_pPlugManager; 
    180     SyncInfoVector            m_syncInfos; 
    181     SyncInfo*                 m_activeSyncInfo; 
    182126    struct VendorModelEntry*  m_model; 
    183127    GenericMixer*             m_Mixer; 
     
    187131    StreamProcessorVector m_receiveProcessors; 
    188132    StreamProcessorVector m_transmitProcessors; 
     133 
     134    DECLARE_DEBUG_MODULE; 
    189135}; 
    190136 
  • branches/echoaudio/src/bebob/bebob_avdevice_subunit.cpp

    r503 r507  
    3636using namespace AVC; 
    3737 
    38 IMPL_DEBUG_MODULE( BeBoB::AvDeviceSubunit, BeBoB::AvDeviceSubunit, DEBUG_LEVEL_VERBOSE ); 
    39  
    40 //////////////////////////////////////////// 
    41  
    42 BeBoB::AvDeviceSubunit::AvDeviceSubunit( AvDevice& avDevice, 
    43                                          ESubunitType type, 
    44                                          subunit_t id, 
    45                                          int verboseLevel ) 
    46     : m_avDevice( &avDevice ) 
    47     , m_sbType( type ) 
    48     , m_sbId( id ) 
    49     , m_verboseLevel( verboseLevel ) 
    50 
    51     setDebugLevel( m_verboseLevel ); 
    52 
    53  
    54 BeBoB::AvDeviceSubunit::AvDeviceSubunit() 
    55 
    56 
    57  
    58 BeBoB::AvDeviceSubunit::~AvDeviceSubunit() 
    59 
    60     for ( AvPlugVector::iterator it = m_plugs.begin(); 
    61           it != m_plugs.end(); 
    62           ++it ) 
    63     { 
    64         delete *it; 
    65     } 
    66 
    67  
    68 bool 
    69 BeBoB::AvDeviceSubunit::discover() 
    70 
    71     if ( !discoverPlugs() ) { 
    72         debugError( "plug discovering failed\n" ); 
    73         return false; 
    74     } 
    75  
    76     return true; 
    77 
    78  
    79 bool 
    80 BeBoB::AvDeviceSubunit::discoverPlugs() 
    81 
    82     PlugInfoCmd plugInfoCmd( m_avDevice->get1394Service(), 
    83                              PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug ); 
    84     plugInfoCmd.setNodeId( m_avDevice->getConfigRom().getNodeId() ); 
    85     plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    86     plugInfoCmd.setSubunitType( m_sbType ); 
    87     plugInfoCmd.setSubunitId( m_sbId ); 
    88     plugInfoCmd.setVerbose( m_verboseLevel ); 
    89  
    90     if ( !plugInfoCmd.fire() ) { 
    91         debugError( "plug info command failed\n" ); 
    92         return false; 
    93     } 
    94  
    95     debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n", 
    96                  plugInfoCmd.m_sourcePlugs ); 
    97     debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output " 
    98                  "plugs = %d\n", plugInfoCmd.m_destinationPlugs ); 
    99  
    100     if ( !discoverPlugs( AvPlug::eAPD_Input, 
    101                          plugInfoCmd.m_destinationPlugs ) ) 
    102     { 
    103         debugError( "destination plug discovering failed\n" ); 
    104         return false; 
    105     } 
    106  
    107     if ( !discoverPlugs(  AvPlug::eAPD_Output, 
    108                           plugInfoCmd.m_sourcePlugs ) ) 
    109     { 
    110         debugError( "source plug discovering failed\n" ); 
    111         return false; 
    112     } 
    113  
    114     return true; 
    115 
    116  
    117 bool 
    118 BeBoB::AvDeviceSubunit::discoverConnections() 
    119 
    120     for ( AvPlugVector::iterator it = m_plugs.begin(); 
    121           it != m_plugs.end(); 
    122           ++it ) 
    123     { 
    124         AvPlug* plug = *it; 
    125         if ( !plug->discoverConnections() ) { 
    126             debugError( "plug connection discovering failed ('%s')\n", 
    127                         plug->getName() ); 
    128             return false; 
    129         } 
    130     } 
    131  
    132     return true; 
    133 
    134  
    135 bool 
    136 BeBoB::AvDeviceSubunit::discoverPlugs(AvPlug::EAvPlugDirection plugDirection, 
    137                                       plug_id_t plugMaxId ) 
    138 
    139     for ( int plugIdx = 0; 
    140           plugIdx < plugMaxId; 
    141           ++plugIdx ) 
    142     { 
    143         ESubunitType subunitType = 
    144             static_cast<ESubunitType>( getSubunitType() ); 
    145         AvPlug* plug = new AvPlug( m_avDevice->get1394Service(), 
    146                                    m_avDevice->getConfigRom(), 
    147                                    m_avDevice->getPlugManager(), 
    148                                    subunitType, 
    149                                    getSubunitId(), 
    150                                    0xff, 
    151                                    0xff, 
    152                                    AvPlug::eAPA_SubunitPlug, 
    153                                    plugDirection, 
    154                                    plugIdx, 
    155                                    m_verboseLevel ); 
    156         if ( !plug || !plug->discover() ) { 
    157             debugError( "plug discover failed\n" ); 
    158             return false; 
    159         } 
    160  
    161         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    162                      plug->getName() ); 
    163         m_plugs.push_back( plug ); 
    164     } 
    165     return true; 
    166 
    167  
    168 bool 
    169 BeBoB::AvDeviceSubunit::addPlug( AvPlug& plug ) 
    170 
    171     m_plugs.push_back( &plug ); 
    172     return true; 
    173 
    174  
    175  
    176 BeBoB::AvPlug* 
    177 BeBoB::AvDeviceSubunit::getPlug(AvPlug::EAvPlugDirection direction, plug_id_t plugId) 
    178 
    179     for ( AvPlugVector::iterator it = m_plugs.begin(); 
    180           it != m_plugs.end(); 
    181           ++it ) 
    182     { 
    183         AvPlug* plug = *it; 
    184         if ( ( plug->getPlugId() == plugId ) 
    185             && ( plug->getDirection() == direction ) ) 
    186         { 
    187             return plug; 
    188         } 
    189     } 
    190     return 0; 
    191 
    192  
    193  
    194 bool 
    195 BeBoB::AvDeviceSubunit::serialize( Glib::ustring basePath, 
    196                                    Util::IOSerialize& ser ) const 
    197 
    198     bool result; 
    199  
    200     result  = ser.write( basePath + "m_sbType", m_sbType ); 
    201     result &= ser.write( basePath + "m_sbId", m_sbId ); 
    202     result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel ); 
    203     result &= serializeChild( basePath, ser ); 
    204  
    205     return result; 
    206 
    207  
    208 BeBoB::AvDeviceSubunit* 
    209 BeBoB::AvDeviceSubunit::deserialize( Glib::ustring basePath, 
    210                                      Util::IODeserialize& deser, 
    211                                      AvDevice& avDevice ) 
    212 
    213     bool result; 
    214     ESubunitType sbType; 
    215     result  = deser.read( basePath + "m_sbType", sbType ); 
    216  
    217     AvDeviceSubunit* pSubunit = 0; 
    218     switch( sbType ) { 
    219     case eST_Audio: 
    220         pSubunit = new AvDeviceSubunitAudio; 
    221         break; 
    222     case eST_Music: 
    223         pSubunit = new AvDeviceSubunitMusic; 
    224         break; 
    225     default: 
    226         pSubunit = 0; 
    227     } 
    228  
    229     if ( !pSubunit ) { 
    230         return 0; 
    231     } 
    232  
    233     pSubunit->m_avDevice = &avDevice; 
    234     pSubunit->m_sbType = sbType; 
    235     result &= deser.read( basePath + "m_sbId", pSubunit->m_sbId ); 
    236     result &= deser.read( basePath + "m_verboseLevel", pSubunit->m_verboseLevel ); 
    237     result &= pSubunit->deserializeChild( basePath, deser, avDevice ); 
    238  
    239     if ( !result ) { 
    240         delete pSubunit; 
    241         return 0; 
    242     } 
    243  
    244     return pSubunit; 
    245 
    246  
    247 //////////////////////////////////////////// 
    248  
    249 BeBoB::AvDeviceSubunitAudio::AvDeviceSubunitAudio( AvDevice& avDevice, 
    250                                                    subunit_t id, 
    251                                                    int verboseLevel ) 
    252     : AvDeviceSubunit( avDevice, eST_Audio, id, verboseLevel ) 
    253 
    254 
    255  
    256 BeBoB::AvDeviceSubunitAudio::AvDeviceSubunitAudio() 
    257     : AvDeviceSubunit() 
    258 
    259 
    260  
    261 BeBoB::AvDeviceSubunitAudio::~AvDeviceSubunitAudio() 
    262 
    263     for ( FunctionBlockVector::iterator it = m_functions.begin(); 
    264           it != m_functions.end(); 
    265           ++it ) 
    266     { 
    267         delete *it; 
    268     } 
    269 
    270  
    271 bool 
    272 BeBoB::AvDeviceSubunitAudio::discover() 
     38 
     39BeBoB::SubunitAudio::SubunitAudio( AVC::Unit& avDevice, 
     40                                   subunit_t id ) 
     41    : AVC::SubunitAudio( avDevice, id ) 
     42
     43
     44 
     45BeBoB::SubunitAudio::SubunitAudio() 
     46    : AVC::SubunitAudio() 
     47
     48
     49 
     50BeBoB::SubunitAudio::~SubunitAudio() 
     51
     52 
     53
     54 
     55bool 
     56BeBoB::SubunitAudio::discover() 
    27357{ 
    27458    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering Audio Subunit...\n"); 
    27559     
    276     if ( !AvDeviceSubunit::discover() ) { 
     60    if ( !AVC::SubunitAudio::discover() ) { 
    27761        return false; 
    27862    } 
     
    28771 
    28872bool 
    289 BeBoB::AvDeviceSubunitAudio::discoverConnections() 
     73BeBoB::SubunitAudio::discoverConnections() 
    29074{ 
    29175    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
    292     if ( !AvDeviceSubunit::discoverConnections() ) { 
     76    if ( !Subunit::discoverConnections() ) { 
    29377        return false; 
    29478    } 
     
    31094 
    31195const char* 
    312 BeBoB::AvDeviceSubunitAudio::getName() 
    313 { 
    314     return "AudioSubunit"; 
    315 } 
    316  
    317 bool 
    318 BeBoB::AvDeviceSubunitAudio::discoverFunctionBlocks() 
     96BeBoB::SubunitAudio::getName() 
     97{ 
     98    return "BeBoB::AudioSubunit"; 
     99} 
     100 
     101bool 
     102BeBoB::SubunitAudio::discoverFunctionBlocks() 
    319103{ 
    320104    debugOutput( DEBUG_LEVEL_NORMAL, 
     
    348132    // print a function block list 
    349133#ifdef DEBUG 
    350     if (getDebugLevel() >= DEBUG_LEVEL_NORMAL) { 
     134    if ((int)getDebugLevel() >= DEBUG_LEVEL_NORMAL) { 
    351135     
    352136        for ( FunctionBlockVector::iterator it = m_functions.begin(); 
     
    366150 
    367151bool 
    368 BeBoB::AvDeviceSubunitAudio::discoverFunctionBlocksDo( 
     152BeBoB::SubunitAudio::discoverFunctionBlocksDo( 
    369153    ExtendedSubunitInfoCmd::EFunctionBlockType fbType ) 
    370154{ 
     
    375159    do { 
    376160        ExtendedSubunitInfoCmd 
    377             extSubunitInfoCmd( m_avDevice->get1394Service() ); 
    378         extSubunitInfoCmd.setNodeId( m_avDevice->getConfigRom().getNodeId() ); 
     161        extSubunitInfoCmd( m_unit->get1394Service() ); 
     162        extSubunitInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    379163        extSubunitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    380164        extSubunitInfoCmd.setSubunitId( getSubunitId() ); 
    381165        extSubunitInfoCmd.setSubunitType( getSubunitType() ); 
    382         extSubunitInfoCmd.setVerbose( m_verboseLevel ); 
     166        extSubunitInfoCmd.setVerbose( (int)getDebugLevel() ); 
    383167 
    384168        extSubunitInfoCmd.m_fbType = fbType; 
     
    414198 
    415199bool 
    416 BeBoB::AvDeviceSubunitAudio::createFunctionBlock( 
     200BeBoB::SubunitAudio::createFunctionBlock( 
    417201    ExtendedSubunitInfoCmd::EFunctionBlockType fbType, 
    418202    ExtendedSubunitInfoPageData& data ) 
     
    431215                                        data.m_noOfInputPlugs, 
    432216                                        data.m_noOfOutputPlugs, 
    433                                         m_verboseLevel ); 
     217                                        (int)getDebugLevel() ); 
    434218    } 
    435219    break; 
     
    441225                                       data.m_noOfInputPlugs, 
    442226                                       data.m_noOfOutputPlugs, 
    443                                        m_verboseLevel ); 
     227                                       (int)getDebugLevel() ); 
    444228    } 
    445229    break; 
     
    454238                                                 data.m_noOfInputPlugs, 
    455239                                                 data.m_noOfOutputPlugs, 
    456                                                  m_verboseLevel ); 
     240                                                 (int)getDebugLevel() ); 
    457241        } 
    458242        break; 
     
    471255                                              data.m_noOfInputPlugs, 
    472256                                              data.m_noOfOutputPlugs, 
    473                                               m_verboseLevel ); 
     257                                              (int)getDebugLevel() ); 
    474258            debugWarning( "Dummy function block processing created. " 
    475259                          "Implementation is missing\n" ); 
     
    484268                                     data.m_noOfInputPlugs, 
    485269                                     data.m_noOfOutputPlugs, 
    486                                      m_verboseLevel ); 
     270                                     (int)getDebugLevel() ); 
    487271        debugWarning( "Dummy function block codec created. " 
    488272                      "Implementation is missing\n" ); 
     
    510294 
    511295BeBoB::FunctionBlock::ESpecialPurpose 
    512 BeBoB::AvDeviceSubunitAudio::convertSpecialPurpose( 
     296BeBoB::SubunitAudio::convertSpecialPurpose( 
    513297    function_block_special_purpose_t specialPurpose ) 
    514298{ 
     
    528312 
    529313bool 
    530 BeBoB::AvDeviceSubunitAudio::serializeChild( Glib::ustring basePath, 
     314BeBoB::SubunitAudio::serializeChild( Glib::ustring basePath, 
    531315                                             Util::IOSerialize& ser ) const 
    532316{ 
     
    551335 
    552336bool 
    553 BeBoB::AvDeviceSubunitAudio::deserializeChild( Glib::ustring basePath, 
     337BeBoB::SubunitAudio::deserializeChild( Glib::ustring basePath, 
    554338                                               Util::IODeserialize& deser, 
    555                                                AvDevice& avDevice ) 
     339                                               AVC::Unit& avDevice ) 
    556340{ 
    557341    int i = 0; 
     
    577361//////////////////////////////////////////// 
    578362 
    579 BeBoB::AvDeviceSubunitMusic::AvDeviceSubunitMusic( AvDevice& avDevice, 
    580                                                    subunit_t id, 
    581                                                    int verboseLevel ) 
    582     : AvDeviceSubunit( avDevice, eST_Music, id, verboseLevel ) 
    583 
    584 
    585  
    586 BeBoB::AvDeviceSubunitMusic::AvDeviceSubunitMusic() 
    587     : AvDeviceSubunit() 
    588 
    589 
    590  
    591 BeBoB::AvDeviceSubunitMusic::~AvDeviceSubunitMusic() 
     363BeBoB::SubunitMusic::SubunitMusic( AVC::Unit& avDevice, 
     364                                                   subunit_t id ) 
     365    : AVC::SubunitMusic( avDevice, id ) 
     366
     367
     368 
     369BeBoB::SubunitMusic::SubunitMusic() 
     370    : AVC::SubunitMusic() 
     371
     372
     373 
     374BeBoB::SubunitMusic::~SubunitMusic() 
    592375{ 
    593376} 
    594377 
    595378const char* 
    596 BeBoB::AvDeviceSubunitMusic::getName() 
    597 { 
    598     return "MusicSubunit"; 
    599 } 
    600  
    601 bool 
    602 BeBoB::AvDeviceSubunitMusic::serializeChild( Glib::ustring basePath, 
     379BeBoB::SubunitMusic::getName() 
     380{ 
     381    return "BeBoB::MusicSubunit"; 
     382} 
     383 
     384bool 
     385BeBoB::SubunitMusic::serializeChild( Glib::ustring basePath, 
    603386                                             Util::IOSerialize& ser ) const 
    604387{ 
     
    607390 
    608391bool 
    609 BeBoB::AvDeviceSubunitMusic::deserializeChild( Glib::ustring basePath, 
     392BeBoB::SubunitMusic::deserializeChild( Glib::ustring basePath, 
    610393                                               Util::IODeserialize& deser, 
    611                                                AvDevice& avDevice ) 
    612 { 
    613     return true; 
    614 } 
     394                                               AVC::Unit& avDevice ) 
     395{ 
     396    return true; 
     397} 
  • branches/echoaudio/src/bebob/bebob_avdevice_subunit.h

    r503 r507  
    3535#include <vector> 
    3636 
     37#include "libavc/general/avc_subunit.h" 
     38#include "libavc/general/avc_plug.h" 
     39 
    3740namespace BeBoB { 
    38  
    39 class AvDevice; 
    40  
    41 class AvDeviceSubunit { 
    42  public: 
    43     AvDeviceSubunit( AvDevice& avDevice, 
    44              AVC::ESubunitType type, 
    45              AVC::subunit_t id, 
    46              int verboseLevel ); 
    47     virtual ~AvDeviceSubunit(); 
    48  
    49     virtual bool discover(); 
    50     virtual bool discoverConnections(); 
    51     virtual const char* getName() = 0; 
    52  
    53     bool addPlug( AvPlug& plug ); 
    54  
    55     AVC::subunit_t getSubunitId() 
    56     { return m_sbId; } 
    57     AVC::ESubunitType getSubunitType() 
    58     { return m_sbType; } 
    59  
    60     AvPlugVector& getPlugs() 
    61     { return m_plugs; } 
    62     AvPlug* getPlug(AvPlug::EAvPlugDirection direction, AVC::plug_id_t plugId); 
    63  
    64  
    65     AvDevice& getAvDevice() const 
    66         { return *m_avDevice; } 
    67  
    68  
    69     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    70     static AvDeviceSubunit* deserialize( Glib::ustring basePath, 
    71                      Util::IODeserialize& deser, 
    72                                          AvDevice& avDevice ); 
    73  protected: 
    74     AvDeviceSubunit(); 
    75  
    76     bool discoverPlugs(); 
    77     bool discoverPlugs(AvPlug::EAvPlugDirection plugDirection, 
    78                        AVC::plug_id_t plugMaxId ); 
    79  
    80     virtual bool serializeChild( Glib::ustring basePath, 
    81                                  Util::IOSerialize& ser ) const = 0; 
    82     virtual bool deserializeChild( Glib::ustring basePath, 
    83                                    Util::IODeserialize& deser, 
    84                                    AvDevice& avDevice ) = 0; 
    85  
    86  protected: 
    87     AvDevice*                m_avDevice; 
    88     AVC::ESubunitType m_sbType; 
    89     AVC::subunit_t                m_sbId; 
    90     int                      m_verboseLevel; 
    91  
    92     AvPlugVector             m_plugs; 
    93  
    94     DECLARE_DEBUG_MODULE; 
    95 }; 
    96  
    97 typedef std::vector<AvDeviceSubunit*> AvDeviceSubunitVector; 
    9841 
    9942///////////////////////////// 
    10043 
    101 class AvDeviceSubunitAudio: public AvDeviceSubunit
     44class SubunitAudio: public AVC::SubunitAudio
    10245 public: 
    103     AvDeviceSubunitAudio( AvDevice& avDevice, 
    104               AVC::subunit_t id, 
    105               int verboseLevel ); 
    106     AvDeviceSubunitAudio(); 
    107     virtual ~AvDeviceSubunitAudio(); 
     46    SubunitAudio( AVC::Unit& avDevice, 
     47              AVC::subunit_t id ); 
     48    SubunitAudio(); 
     49    virtual ~SubunitAudio(); 
    10850 
    10951    virtual bool discover(); 
     
    12971    virtual bool deserializeChild( Glib::ustring basePath, 
    13072                                   Util::IODeserialize& deser, 
    131                                    AvDevice& avDevice ); 
     73                                   AVC::Unit& unit ); 
    13274 
    13375protected: 
     
    13779///////////////////////////// 
    13880 
    139 class AvDeviceSubunitMusic: public AvDeviceSubunit
     81class SubunitMusic: public AVC::SubunitMusic
    14082 public: 
    141     AvDeviceSubunitMusic( AvDevice& avDevice, 
    142               AVC::subunit_t id, 
    143               int verboseLevel ); 
    144     AvDeviceSubunitMusic(); 
    145     virtual ~AvDeviceSubunitMusic(); 
     83    SubunitMusic( AVC::Unit& avDevice, 
     84              AVC::subunit_t id ); 
     85    SubunitMusic(); 
     86    virtual ~SubunitMusic(); 
    14687 
    14788    virtual const char* getName(); 
     
    15293    virtual bool deserializeChild( Glib::ustring basePath, 
    15394                                   Util::IODeserialize& deser, 
    154                                    AvDevice& avDevice ); 
     95                                   AVC::Unit& unit ); 
    15596}; 
    15697 
  • branches/echoaudio/src/bebob/bebob_avplug.cpp

    r503 r507  
    3535namespace BeBoB { 
    3636 
    37 int AvPlug::m_globalIdCounter = 0; 
    38  
    39 IMPL_DEBUG_MODULE( AvPlug, AvPlug, DEBUG_LEVEL_NORMAL ); 
    40 IMPL_DEBUG_MODULE( AvPlugManager, AvPlugManager, DEBUG_LEVEL_NORMAL ); 
    41  
    42 AvPlug::AvPlug( Ieee1394Service& ieee1394Service, 
    43                 ConfigRom& configRom, 
    44                 AvPlugManager& plugManager, 
    45                 ESubunitType subunitType, 
    46                 subunit_id_t subunitId, 
    47                 function_block_type_t functionBlockType, 
    48                 function_block_id_t functionBlockId, 
    49                 EAvPlugAddressType plugAddressType, 
    50                 EAvPlugDirection plugDirection, 
    51                 plug_id_t plugId, 
    52                 int verboseLevel ) 
    53     : m_p1394Service( &ieee1394Service ) 
    54     , m_pConfigRom( &configRom ) 
    55     , m_subunitType( subunitType ) 
    56     , m_subunitId( subunitId ) 
    57     , m_functionBlockType( functionBlockType ) 
    58     , m_functionBlockId( functionBlockId ) 
    59     , m_addressType( plugAddressType ) 
    60     , m_direction( plugDirection ) 
    61     , m_id( plugId ) 
    62     , m_infoPlugType( eAPT_Unknown ) 
    63     , m_nrOfChannels( 0 ) 
    64     , m_plugManager( &plugManager ) 
    65     , m_verboseLevel( verboseLevel ) 
    66     , m_globalId( m_globalIdCounter++ ) 
    67 
    68     setDebugLevel( m_verboseLevel ); 
    69     debugOutput( DEBUG_LEVEL_VERBOSE, 
    70                  "nodeId = %d, subunitType = %d, " 
    71                  "subunitId = %d, functionBlockType = %d, " 
    72                  "functionBlockId = %d, addressType = %d, " 
    73                  "direction = %d, id = %d\n", 
    74                  m_pConfigRom->getNodeId(), 
    75                  m_subunitType, 
    76                  m_subunitId, 
    77                  m_functionBlockType, 
    78                  m_functionBlockId, 
    79                  m_addressType, 
    80                  m_direction, 
    81                  m_id ); 
    82 
    83  
    84 AvPlug::AvPlug( const AvPlug& rhs ) 
    85     : m_p1394Service( rhs.m_p1394Service ) 
    86     , m_pConfigRom( rhs.m_pConfigRom ) 
    87     , m_subunitType( rhs.m_subunitType ) 
    88     , m_subunitId( rhs.m_subunitId ) 
    89     , m_functionBlockType( rhs.m_functionBlockType ) 
    90     , m_functionBlockId( rhs.m_functionBlockId ) 
    91     , m_addressType( rhs.m_addressType ) 
    92     , m_direction( rhs.m_direction ) 
    93     , m_id( rhs.m_id ) 
    94     , m_infoPlugType( rhs.m_infoPlugType ) 
    95     , m_nrOfChannels( rhs.m_nrOfChannels ) 
    96     , m_name( rhs.m_name ) 
    97     , m_clusterInfos( rhs.m_clusterInfos ) 
    98     , m_formatInfos( rhs.m_formatInfos ) 
    99     , m_plugManager( rhs.m_plugManager ) 
    100     , m_verboseLevel( rhs.m_verboseLevel ) 
    101 
    102     if ( m_verboseLevel ) { 
    103         setDebugLevel( DEBUG_LEVEL_VERBOSE ); 
    104      } 
    105 
    106  
    107 AvPlug::AvPlug() 
    108     : m_p1394Service( 0 ) 
    109     , m_pConfigRom( 0 ) 
    110     , m_subunitType( eST_Reserved ) // a good value for unknown/undefined? 
    111     , m_subunitId( 0 ) 
    112     , m_functionBlockType( 0 ) 
    113     , m_functionBlockId( 0 ) 
    114     , m_addressType( eAPA_Undefined ) 
    115     , m_direction( eAPD_Unknown ) 
    116     , m_id( 0 ) 
    117     , m_infoPlugType( eAPT_Unknown ) 
    118     , m_nrOfChannels( 0 ) 
    119     , m_plugManager( 0 ) 
    120     , m_verboseLevel( 0 ) 
    121     , m_globalId( 0 ) 
    122 
    123 
    124  
    125 AvPlug::~AvPlug() 
    126 
    127     if ( m_plugManager ) { 
    128         m_plugManager->remPlug( *this ); 
    129     } 
    130 
    131  
    132 bool 
    133 AvPlug::discover() 
     37Plug::Plug( AVC::Unit* unit, 
     38            AVC::Subunit* subunit, 
     39            AVC::function_block_type_t functionBlockType, 
     40            AVC::function_block_type_t functionBlockId, 
     41            AVC::Plug::EPlugAddressType plugAddressType, 
     42            AVC::Plug::EPlugDirection plugDirection, 
     43            AVC::plug_id_t plugId ) 
     44    : AVC::Plug( unit, 
     45                 subunit, 
     46                 functionBlockType, 
     47                 functionBlockId, 
     48                 plugAddressType, 
     49                 plugDirection, 
     50                 plugId ) 
     51
     52 
     53
     54 
     55Plug::Plug( const Plug& rhs ) 
     56    : AVC::Plug( rhs ) 
     57
     58
     59 
     60Plug::Plug() 
     61    : AVC::Plug() 
     62
     63
     64 
     65Plug::~Plug() 
     66
     67 
     68
     69 
     70bool 
     71Plug::discover() 
    13472{ 
    13573    if ( !discoverPlugType() ) { 
    13674        debugError( "discover: Could not discover plug type (%d,%d,%d,%d,%d)\n", 
    137                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     75                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    13876        return false; 
    13977    } 
     
    14179    if ( !discoverName() ) { 
    14280        debugError( "Could not discover name (%d,%d,%d,%d,%d)\n", 
    143                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     81                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    14482        return false; 
    14583    } 
     
    14886        debugError( "Could not discover number of channels " 
    14987                    "(%d,%d,%d,%d,%d)\n", 
    150                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     88                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    15189        return false; 
    15290    } 
     
    15593        debugError( "Could not discover channel positions " 
    15694                    "(%d,%d,%d,%d,%d)\n", 
    157                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     95                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    15896        return false; 
    15997    } 
     
    162100        debugError( "Could not discover channel name " 
    163101                    "(%d,%d,%d,%d,%d)\n", 
    164                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     102                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    165103        return false; 
    166104    } 
     
    169107        debugError( "Could not discover channel name " 
    170108                    "(%d,%d,%d,%d,%d)\n", 
    171                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     109                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    172110        return false; 
    173111    } 
     
    176114        debugError( "Could not discover stream format " 
    177115                    "(%d,%d,%d,%d,%d)\n", 
    178                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     116                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
    179117        return false; 
    180118    } 
     
    183121        debugError( "Could not discover supported stream formats " 
    184122                    "(%d,%d,%d,%d,%d)\n", 
    185                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    186         return false; 
    187     } 
    188  
    189     return m_plugManager->addPlug( *this ); 
    190 } 
    191  
    192 bool 
    193 AvPlug::discoverConnections() 
     123                    m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 
     124        return false; 
     125    } 
     126 
     127    return m_unit->getPlugManager().addPlug( *this ); 
     128} 
     129 
     130bool 
     131Plug::discoverConnections() 
    194132{ 
    195133    return discoverConnectionsInput() && discoverConnectionsOutput(); 
     
    197135 
    198136bool 
    199 AvPlug::inquireConnnection( AvPlug& plug ) 
    200 
    201     SignalSourceCmd signalSourceCmd = setSrcPlugAddrToSignalCmd(); 
    202     setDestPlugAddrToSignalCmd( signalSourceCmd, plug ); 
    203     signalSourceCmd.setCommandType( AVCCommand::eCT_SpecificInquiry ); 
    204     signalSourceCmd.setVerbose( m_verboseLevel ); 
    205  
    206     if ( !signalSourceCmd.fire() ) { 
    207         debugError( "Could not inquire connection between '%s' and '%s'\n", 
    208                     getName(), plug.getName() ); 
    209         return false; 
    210     } 
    211  
    212     if ( signalSourceCmd.getResponse() == AVCCommand::eR_Implemented ) { 
    213         debugOutput( DEBUG_LEVEL_VERBOSE, 
    214                      "Connection possible between '%s' and '%s'\n", 
    215                      getName(),  plug.getName() ); 
    216         return true; 
    217     } 
    218     debugOutput( DEBUG_LEVEL_VERBOSE, 
    219                  "Connection not possible between '%s' and '%s'\n", 
    220                  getName(),  plug.getName() ); 
    221     return false; 
    222 
    223  
    224 bool 
    225 AvPlug::setConnection( AvPlug& plug ) 
    226 
    227     SignalSourceCmd signalSourceCmd = setSrcPlugAddrToSignalCmd(); 
    228     setDestPlugAddrToSignalCmd( signalSourceCmd, plug ); 
    229     signalSourceCmd.setCommandType( AVCCommand::eCT_Control ); 
    230     signalSourceCmd.setVerbose( m_verboseLevel ); 
    231  
    232     if ( !signalSourceCmd.fire() ) { 
    233         debugError( "Could not set connection between '%s' and '%s'\n", 
    234                     getName(), plug.getName() ); 
    235         return false; 
    236     } 
    237  
    238     if ( signalSourceCmd.getResponse() == AVCCommand::eR_Accepted ) { 
    239         debugOutput( DEBUG_LEVEL_VERBOSE, 
    240                      "Could set connection between '%s' and '%s'\n", 
    241                      getName(), plug.getName() ); 
    242         return true; 
    243     } 
    244     debugOutput( DEBUG_LEVEL_VERBOSE, 
    245                  "Could not set connection between '%s' and '%s'\n", 
    246                  getName(),  plug.getName() ); 
    247     return false; 
    248 
    249  
    250 int 
    251 AvPlug::getNrOfStreams() const 
    252 
    253     int nrOfChannels = 0; 
    254     for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin(); 
    255           it != m_clusterInfos.end(); 
    256           ++it ) 
    257     { 
    258         const ClusterInfo* clusterInfo = &( *it ); 
    259         nrOfChannels += clusterInfo->m_nrOfChannels; 
    260     } 
    261     return nrOfChannels; 
    262 
    263  
    264 int 
    265 AvPlug::getNrOfChannels() const 
    266 
    267     return m_nrOfChannels; 
    268 
    269  
    270 int 
    271 AvPlug::getSampleRate() const 
    272 
    273     return convertESamplingFrequency( static_cast<ESamplingFrequency>( m_samplingFrequency ) ); 
    274 
    275  
    276 bool 
    277 AvPlug::discoverPlugType() 
     137Plug::discoverPlugType() 
    278138{ 
    279139    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    282142    extendedPlugInfoInfoType.initialize(); 
    283143    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    284     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     144    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    285145 
    286146    if ( !extPlugInfoCmd.fire() ) { 
     
    338198 
    339199bool 
    340 AvPlug::discoverName() 
     200Plug::discoverName() 
    341201{ 
    342202    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    345205    extendedPlugInfoInfoType.initialize(); 
    346206    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    347     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     207    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    348208 
    349209    if ( !extPlugInfoCmd.fire() ) { 
     
    370230 
    371231bool 
    372 AvPlug::discoverNoOfChannels() 
     232Plug::discoverNoOfChannels() 
    373233{ 
    374234    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    378238    extendedPlugInfoInfoType.initialize(); 
    379239    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    380     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     240    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    381241 
    382242    if ( !extPlugInfoCmd.fire() ) { 
     
    403263 
    404264bool 
    405 AvPlug::discoverChannelPosition() 
     265Plug::discoverChannelPosition() 
    406266{ 
    407267    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    410270    extendedPlugInfoInfoType.initialize(); 
    411271    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    412     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     272    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    413273 
    414274    if ( !extPlugInfoCmd.fire() ) { 
     
    439299 
    440300bool 
    441 AvPlug::discoverChannelName() 
     301Plug::discoverChannelName() 
    442302{ 
    443303    for ( ClusterInfoVector::iterator clit = m_clusterInfos.begin(); 
     
    458318            extendedPlugInfoInfoType.initialize(); 
    459319            extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    460             extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     320            extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    461321 
    462322            ExtendedPlugInfoInfoType* infoType = 
     
    491351 
    492352bool 
    493 AvPlug::discoverClusterInfo() 
     353Plug::discoverClusterInfo() 
    494354{ 
    495355    if ( m_infoPlugType == eAPT_Sync ) 
     
    518378        extendedPlugInfoInfoType.initialize(); 
    519379        extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    520         extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     380        extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    521381 
    522382        extPlugInfoCmd.getInfoType()->m_plugClusterInfo->m_clusterIndex = 
     
    551411 
    552412bool 
    553 AvPlug::discoverStreamFormat() 
     413Plug::discoverStreamFormat() 
    554414{ 
    555415    ExtendedStreamFormatCmd extStreamFormatCmd = 
    556416        setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
    557     extStreamFormatCmd.setVerbose( m_verboseLevel ); 
     417    extStreamFormatCmd.setVerbose( getDebugLevel() ); 
    558418 
    559419    if ( !extStreamFormatCmd.fire() ) { 
     
    674534 
    675535bool 
    676 AvPlug::discoverSupportedStreamFormats() 
     536Plug::discoverSupportedStreamFormats() 
    677537{ 
    678538    ExtendedStreamFormatCmd extStreamFormatCmd = 
    679539        setPlugAddrToStreamFormatCmd( 
    680540            ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 
    681     extStreamFormatCmd.setVerbose( m_verboseLevel ); 
     541    extStreamFormatCmd.setVerbose( getDebugLevel() ); 
    682542 
    683543    int i = 0; 
     
    770630 
    771631bool 
    772 AvPlug::discoverConnectionsInput() 
     632Plug::discoverConnectionsInput() 
    773633{ 
    774634    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    777637    extendedPlugInfoInfoType.initialize(); 
    778638    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    779     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     639    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    780640 
    781641    if ( !extPlugInfoCmd.fire() ) { 
     
    822682 
    823683bool 
    824 AvPlug::discoverConnectionsOutput() 
     684Plug::discoverConnectionsOutput() 
    825685{ 
    826686    ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
     
    829689    extendedPlugInfoInfoType.initialize(); 
    830690    extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    831     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
     691    extPlugInfoCmd.setVerbose( getDebugLevel() ); 
    832692 
    833693    if ( !extPlugInfoCmd.fire() ) { 
     
    885745} 
    886746 
    887 bool 
    888 AvPlug::discoverConnectionsFromSpecificData( 
    889     EAvPlugDirection discoverDirection, 
    890     PlugAddressSpecificData* plugAddress, 
    891     AvPlugVector& connections ) 
    892 { 
    893     UnitPlugSpecificDataPlugAddress* pUnitPlugAddress = 
    894         dynamic_cast<UnitPlugSpecificDataPlugAddress*> 
    895         ( plugAddress->m_plugAddressData ); 
    896  
    897     SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress = 
    898         dynamic_cast<SubunitPlugSpecificDataPlugAddress*> 
    899         ( plugAddress->m_plugAddressData ); 
    900  
    901     FunctionBlockPlugSpecificDataPlugAddress* 
    902         pFunctionBlockPlugAddress = 
    903         dynamic_cast<FunctionBlockPlugSpecificDataPlugAddress*> 
    904         ( plugAddress->m_plugAddressData ); 
    905  
    906     AvPlug* plug = getPlugDefinedBySpecificData( 
    907         pUnitPlugAddress, 
    908         pSubunitPlugAddress, 
    909         pFunctionBlockPlugAddress ); 
    910  
    911     if ( plug ) { 
    912         debugOutput( DEBUG_LEVEL_VERBOSE, 
    913                      "'(%d) %s' has a connection to '(%d) %s'\n", 
    914                      getGlobalId(), 
    915                      getName(), 
    916                      plug->getGlobalId(), 
    917                      plug->getName() ); 
    918         addPlugConnection( connections, *plug ); 
    919     } else { 
    920         debugError( "no corresponding plug found for '(%d) %s'\n", 
    921                     getGlobalId(), 
    922                     getName() ); 
    923         return false; 
    924     } 
    925  
    926     return true; 
    927 } 
    928  
    929 bool 
    930 AvPlug::addPlugConnection( AvPlugVector& connections, 
    931                            AvPlug& plug ) 
    932  
    933 { 
    934     for ( AvPlugVector::iterator it = connections.begin(); 
    935           it != connections.end(); 
    936           ++it ) 
    937     { 
    938         AvPlug* cPlug = *it; 
    939         if ( cPlug == &plug ) { 
    940             debugOutput( DEBUG_LEVEL_VERBOSE, 
    941                          "plug '%s' already in connection list\n", 
    942                          plug.getName() ); 
    943             return true; 
    944         } 
    945     } 
    946  
    947     connections.push_back( &plug ); 
    948     return true; 
    949 } 
    950  
    951747ExtendedPlugInfoCmd 
    952 AvPlug::setPlugAddrToPlugInfoCmd() 
    953 { 
    954     ExtendedPlugInfoCmd extPlugInfoCmd( *m_p1394Service ); 
    955  
    956     switch( m_subunitType ) { 
     748Plug::setPlugAddrToPlugInfoCmd() 
     749{ 
     750    ExtendedPlugInfoCmd extPlugInfoCmd( m_unit->get1394Service() ); 
     751 
     752    switch( getSubunitType() ) { 
    957753    case eST_Unit: 
    958754        { 
     
    1016812    } 
    1017813 
    1018     extPlugInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
     814    extPlugInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    1019815    extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    1020     extPlugInfoCmd.setSubunitId( m_subunitId ); 
    1021     extPlugInfoCmd.setSubunitType( m_subunitType ); 
     816    extPlugInfoCmd.setSubunitId( getSubunitId() ); 
     817    extPlugInfoCmd.setSubunitType( getSubunitType() ); 
    1022818 
    1023819    return extPlugInfoCmd; 
     
    1025821 
    1026822ExtendedStreamFormatCmd 
    1027 AvPlug::setPlugAddrToStreamFormatCmd( 
     823Plug::setPlugAddrToStreamFormatCmd( 
    1028824    ExtendedStreamFormatCmd::ESubFunction subFunction) 
    1029825{ 
    1030826    ExtendedStreamFormatCmd extStreamFormatInfoCmd( 
    1031         *m_p1394Service
     827        m_unit->get1394Service()
    1032828        subFunction ); 
    1033     switch( m_subunitType ) { 
     829    switch( getSubunitType() ) { 
    1034830    case eST_Unit: 
    1035831    { 
     
    1091887    } 
    1092888 
    1093     extStreamFormatInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
     889    extStreamFormatInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    1094890    extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    1095     extStreamFormatInfoCmd.setSubunitId( m_subunitId ); 
    1096     extStreamFormatInfoCmd.setSubunitType( m_subunitType ); 
     891    extStreamFormatInfoCmd.setSubunitId( getSubunitId() ); 
     892    extStreamFormatInfoCmd.setSubunitType( getSubunitType() ); 
    1097893 
    1098894    return extStreamFormatInfoCmd; 
    1099895} 
    1100896 
    1101 SignalSourceCmd 
    1102 AvPlug::setSrcPlugAddrToSignalCmd() 
    1103 
    1104     SignalSourceCmd signalSourceCmd( *m_p1394Service ); 
    1105  
    1106     switch( m_subunitType ) { 
    1107     case eST_Unit: 
    1108     { 
    1109         SignalUnitAddress signalUnitAddr; 
    1110         if ( getPlugAddressType() == eAPA_ExternalPlug ) { 
    1111             signalUnitAddr.m_plugId = m_id + 0x80; 
    1112         } else { 
    1113             signalUnitAddr.m_plugId = m_id; 
    1114         } 
    1115         signalSourceCmd.setSignalSource( signalUnitAddr ); 
    1116     } 
    1117     break; 
    1118     case eST_Music: 
    1119     case eST_Audio: 
    1120     { 
    1121         SignalSubunitAddress signalSubunitAddr; 
    1122         signalSubunitAddr.m_subunitType = m_subunitType; 
    1123         signalSubunitAddr.m_subunitId = m_subunitId; 
    1124         signalSubunitAddr.m_plugId = m_id; 
    1125         signalSourceCmd.setSignalSource( signalSubunitAddr ); 
    1126     } 
    1127     break; 
    1128     default: 
    1129         debugError( "Unknown subunit type\n" ); 
    1130     } 
    1131  
    1132     signalSourceCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    1133     signalSourceCmd.setSubunitType( eST_Unit  ); 
    1134     signalSourceCmd.setSubunitId( 0xff ); 
    1135  
    1136     return signalSourceCmd; 
    1137 
    1138  
    1139 void 
    1140 AvPlug::setDestPlugAddrToSignalCmd(SignalSourceCmd& signalSourceCmd, 
    1141                                    AvPlug& plug) 
    1142 
    1143     switch( plug.m_subunitType ) { 
    1144     case eST_Unit: 
    1145     { 
    1146         SignalUnitAddress signalUnitAddr; 
    1147         if ( plug.getPlugAddressType() == eAPA_ExternalPlug ) { 
    1148             signalUnitAddr.m_plugId = plug.m_id + 0x80; 
    1149         } else { 
    1150             signalUnitAddr.m_plugId = plug.m_id; 
    1151         } 
    1152         signalSourceCmd.setSignalDestination( signalUnitAddr ); 
    1153     } 
    1154     break; 
    1155     case eST_Music: 
    1156     case eST_Audio: 
    1157     { 
    1158         SignalSubunitAddress signalSubunitAddr; 
    1159         signalSubunitAddr.m_subunitType = plug.m_subunitType; 
    1160         signalSubunitAddr.m_subunitId = plug.m_subunitId; 
    1161         signalSubunitAddr.m_plugId = plug.m_id; 
    1162         signalSourceCmd.setSignalDestination( signalSubunitAddr ); 
    1163     } 
    1164     break; 
    1165     default: 
    1166         debugError( "Unknown subunit type\n" ); 
    1167     } 
    1168 
    1169  
    1170  
    1171 bool 
    1172 AvPlug::copyClusterInfo(ExtendedPlugInfoPlugChannelPositionSpecificData& 
    1173                         channelPositionData ) 
    1174 
    1175     int index = 1; 
    1176     for ( ExtendedPlugInfoPlugChannelPositionSpecificData::ClusterInfoVector::const_iterator it 
    1177               = channelPositionData.m_clusterInfos.begin(); 
    1178           it != channelPositionData.m_clusterInfos.end(); 
    1179           ++it ) 
    1180     { 
    1181         const ExtendedPlugInfoPlugChannelPositionSpecificData::ClusterInfo* 
    1182             extPlugSpClusterInfo = &( *it ); 
    1183  
    1184         ClusterInfo clusterInfo; 
    1185         clusterInfo.m_nrOfChannels = extPlugSpClusterInfo->m_nrOfChannels; 
    1186         clusterInfo.m_index = index; 
    1187         index++; 
    1188  
    1189         for (  ExtendedPlugInfoPlugChannelPositionSpecificData::ChannelInfoVector::const_iterator cit 
    1190                   = extPlugSpClusterInfo->m_channelInfos.begin(); 
    1191               cit != extPlugSpClusterInfo->m_channelInfos.end(); 
    1192               ++cit ) 
    1193         { 
    1194             const ExtendedPlugInfoPlugChannelPositionSpecificData::ChannelInfo* 
    1195                 extPlugSpChannelInfo = &( *cit ); 
    1196  
    1197             ChannelInfo channelInfo; 
    1198             channelInfo.m_streamPosition = 
    1199                 extPlugSpChannelInfo->m_streamPosition; 
    1200             channelInfo.m_location = 
    1201                 extPlugSpChannelInfo->m_location; 
    1202  
    1203             clusterInfo.m_channelInfos.push_back( channelInfo ); 
    1204         } 
    1205         m_clusterInfos.push_back( clusterInfo ); 
    1206     } 
    1207  
    1208     return true; 
    1209 
    1210  
    1211 void 
    1212 AvPlug::debugOutputClusterInfos( int debugLevel ) 
    1213 
    1214     for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin(); 
    1215           it != m_clusterInfos.end(); 
    1216           ++it ) 
    1217     { 
    1218         const ClusterInfo* clusterInfo = &( *it ); 
    1219  
    1220         debugOutput( debugLevel, "number of channels: %d\n", 
    1221                      clusterInfo->m_nrOfChannels ); 
    1222  
    1223         for ( ChannelInfoVector::const_iterator cit 
    1224                   = clusterInfo->m_channelInfos.begin(); 
    1225               cit != clusterInfo->m_channelInfos.end(); 
    1226               ++cit ) 
    1227         { 
    1228             const ChannelInfo* channelInfo = &( *cit ); 
    1229             channelInfo = channelInfo; 
    1230             debugOutput( debugLevel, 
    1231                          "stream position: %d\n", 
    1232                          channelInfo->m_streamPosition ); 
    1233             debugOutput( debugLevel, 
    1234                          "location: %d\n", 
    1235                          channelInfo->m_location ); 
    1236         } 
    1237     } 
    1238 
    1239  
    1240 const AvPlug::ClusterInfo* 
    1241 AvPlug::getClusterInfoByIndex(int index) const 
    1242 
    1243     for ( AvPlug::ClusterInfoVector::const_iterator clit = 
    1244               m_clusterInfos.begin(); 
    1245           clit != m_clusterInfos.end(); 
    1246           ++clit ) 
    1247     { 
    1248         const ClusterInfo* info = &*clit; 
    1249         if ( info->m_index == index ) { 
    1250             return info; 
    1251         } 
    1252     } 
    1253     return 0; 
    1254 
    1255  
    1256 PlugAddress::EPlugDirection 
    1257 AvPlug::convertPlugDirection( EAvPlugDirection direction ) 
    1258 
    1259     PlugAddress::EPlugDirection dir; 
    1260     switch ( direction ) { 
    1261     case AvPlug::eAPD_Input: 
    1262         dir = PlugAddress::ePD_Input; 
    1263         break; 
    1264     case AvPlug::eAPD_Output: 
    1265         dir = PlugAddress::ePD_Output; 
    1266         break; 
    1267     default: 
    1268         dir = PlugAddress::ePD_Undefined; 
    1269     } 
    1270     return dir; 
    1271 
    1272  
    1273 void 
    1274 AvPlug::showPlug() const 
    1275 
    1276     debugOutput( DEBUG_LEVEL_VERBOSE, "\tName               = %s\n", 
    1277                  getName() ); 
    1278     debugOutput( DEBUG_LEVEL_VERBOSE, "\tType               = %s\n", 
    1279                  extendedPlugInfoPlugTypeToString( getPlugType() ) ); 
    1280     debugOutput( DEBUG_LEVEL_VERBOSE, "\tAddress Type       = %s\n", 
    1281                  avPlugAddressTypeToString( getPlugAddressType() ) ); 
    1282     debugOutput( DEBUG_LEVEL_VERBOSE, "\tId                 = %d\n", 
    1283                  getPlugId() ); 
    1284     debugOutput( DEBUG_LEVEL_VERBOSE, "\tSubunitType        = %d\n", 
    1285                  getSubunitType() ); 
    1286     debugOutput( DEBUG_LEVEL_VERBOSE, "\tSubunitId          = %d\n", 
    1287                  getSubunitId() ); 
    1288     debugOutput( DEBUG_LEVEL_VERBOSE, "\tDirection          = %s\n", 
    1289                  avPlugDirectionToString( getPlugDirection() ) ); 
    1290     debugOutput( DEBUG_LEVEL_VERBOSE, "\tSampling Rate      = %d\n", 
    1291                  getSampleRate() ); 
    1292     debugOutput( DEBUG_LEVEL_VERBOSE, "\tNumber of Channels = %d\n", 
    1293                  getNrOfChannels() ); 
    1294     debugOutput( DEBUG_LEVEL_VERBOSE, "\tNumber of Streams  = %d\n", 
    1295                  getNrOfStreams() ); 
    1296 
    1297  
    1298  
    1299 AvPlug* 
    1300 AvPlug::getPlugDefinedBySpecificData( 
    1301     UnitPlugSpecificDataPlugAddress* pUnitPlugAddress, 
    1302     SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress, 
    1303     FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress ) 
    1304 
    1305     subunit_type_t        subunitType       = 0xff; 
    1306     subunit_id_t          subunitId         = 0xff; 
    1307     function_block_type_t functionBlockType = 0xff; 
    1308     function_block_id_t   functionBlockId   = 0xff; 
    1309     EAvPlugAddressType    addressType       = eAPA_Undefined; 
    1310     EAvPlugDirection      direction         = eAPD_Unknown; 
    1311     plug_id_t             plugId            = 0xff; 
    1312  
    1313     if ( !pUnitPlugAddress 
    1314          && !pSubunitPlugAddress 
    1315          && !pFunctionBlockPlugAddress ) 
    1316     { 
    1317         debugError( "No correct specific data found\n" ); 
    1318         return 0; 
    1319     } 
    1320  
    1321     if ( pUnitPlugAddress ) { 
    1322         subunitType = eST_Unit; 
    1323         switch ( pUnitPlugAddress->m_plugType ) { 
    1324         case UnitPlugSpecificDataPlugAddress::ePT_PCR: 
    1325             addressType = eAPA_PCR; 
    1326             break; 
    1327         case UnitPlugSpecificDataPlugAddress::ePT_ExternalPlug: 
    1328             addressType = eAPA_ExternalPlug; 
    1329             break; 
    1330         case UnitPlugSpecificDataPlugAddress::ePT_AsynchronousPlug: 
    1331             addressType = eAPA_AsynchronousPlug; 
    1332             break; 
    1333         } 
    1334         // unit plug have only connections to subunits 
    1335         if ( getPlugAddressType() == eAPA_SubunitPlug ) { 
    1336             direction = getDirection(); 
    1337         } else { 
    1338             debugError( "Function block has connection from/to unknown " 
    1339                         "plug type\n" ); 
    1340             direction = eAPD_Unknown; 
    1341         } 
    1342         plugId = pUnitPlugAddress->m_plugId; 
    1343  
    1344         debugOutput( DEBUG_LEVEL_VERBOSE, 
    1345                      "'(%d) %s': Remote plug is a unit plug " 
    1346                      "(%s, %s, %d)\n", 
    1347                      getGlobalId(), 
    1348                      getName(), 
    1349                      avPlugAddressTypeToString( addressType ), 
    1350                      avPlugDirectionToString( direction ), 
    1351                      plugId ); 
    1352     } 
    1353  
    1354     if ( pSubunitPlugAddress ) { 
    1355         subunitType = pSubunitPlugAddress->m_subunitType; 
    1356         subunitId = pSubunitPlugAddress->m_subunitId; 
    1357         addressType = eAPA_SubunitPlug; 
    1358  
    1359         if ( getPlugAddressType() == eAPA_FunctionBlockPlug ) { 
    1360             direction = getDirection(); 
    1361         } else if ( getPlugAddressType() == eAPA_SubunitPlug ) { 
    1362             direction = toggleDirection( getDirection() ); 
    1363         } else { 
    1364             // unit 
    1365             direction = getDirection(); 
    1366         } 
    1367  
    1368         plugId = pSubunitPlugAddress->m_plugId; 
    1369         debugOutput( DEBUG_LEVEL_VERBOSE, 
    1370                      "'(%d) %s': Remote plug is a subunit plug " 
    1371                      "(%d, %d, %s, %d)\n", 
    1372                      getGlobalId(), 
    1373                      getName(), 
    1374                      subunitType, 
    1375                      subunitId, 
    1376                      avPlugDirectionToString( direction ), 
    1377                      plugId ); 
    1378     } 
    1379  
    1380     if ( pFunctionBlockPlugAddress ) { 
    1381         subunitType = pFunctionBlockPlugAddress->m_subunitType; 
    1382         subunitId = pFunctionBlockPlugAddress->m_subunitId; 
    1383         functionBlockType = pFunctionBlockPlugAddress->m_functionBlockType; 
    1384         functionBlockId = pFunctionBlockPlugAddress->m_functionBlockId; 
    1385         addressType = eAPA_FunctionBlockPlug; 
    1386  
    1387         if ( getPlugAddressType() == eAPA_FunctionBlockPlug ) { 
    1388             direction = toggleDirection( getDirection() ); 
    1389         } else if ( getPlugAddressType() == eAPA_SubunitPlug ){ 
    1390             direction = getDirection(); 
    1391         } else { 
    1392             debugError( "Function block has connection from/to unknown " 
    1393                         "plug type\n" ); 
    1394             direction = eAPD_Unknown; 
    1395         } 
    1396  
    1397         plugId = pFunctionBlockPlugAddress->m_plugId; 
    1398  
    1399         debugOutput( DEBUG_LEVEL_VERBOSE, 
    1400                      "'(%d) %s': Remote plug is a functionblock plug " 
    1401                      "(%d, %d, %d, %d, %s, %d)\n", 
    1402                      getGlobalId(), 
    1403                      getName(), 
    1404                      subunitType, 
    1405                      subunitId, 
    1406                      functionBlockType, 
    1407                      functionBlockId, 
    1408                      avPlugDirectionToString( direction ), 
    1409                      plugId ); 
    1410     } 
    1411  
    1412     ESubunitType enumSubunitType = 
    1413         static_cast<ESubunitType>( subunitType ); 
    1414  
    1415     return m_plugManager->getPlug( 
    1416         enumSubunitType, 
    1417         subunitId, 
    1418         functionBlockType, 
    1419         functionBlockId, 
    1420         addressType, 
    1421         direction, 
    1422         plugId ); 
    1423 
    1424  
    1425 AvPlug::EAvPlugDirection 
    1426 AvPlug::toggleDirection( EAvPlugDirection direction ) const 
    1427 
    1428     EAvPlugDirection newDirection; 
    1429     switch ( direction ) { 
    1430     case eAPD_Output: 
    1431         newDirection = eAPD_Input; 
    1432         break; 
    1433     case eAPD_Input: 
    1434         newDirection = eAPD_Output; 
    1435         break; 
    1436     default: 
    1437         newDirection = direction; 
    1438     } 
    1439  
    1440     return newDirection; 
    1441 
    1442  
    1443 bool 
    1444 AvPlug::serializeChannelInfos( Glib::ustring basePath, 
    1445                                Util::IOSerialize& ser, 
    1446                                const ClusterInfo& clusterInfo ) const 
    1447 
    1448     bool result = true; 
    1449     int i = 0; 
    1450     for ( ChannelInfoVector::const_iterator it = clusterInfo.m_channelInfos.begin(); 
    1451           it != clusterInfo.m_channelInfos.end(); 
    1452           ++it ) 
    1453     { 
    1454         const ChannelInfo& info = *it; 
    1455         std::ostringstream strstrm; 
    1456         strstrm << basePath << i; 
    1457  
    1458         result &= ser.write( strstrm.str() + "/m_streamPosition", info.m_streamPosition ); 
    1459         result &= ser.write( strstrm.str() + "/m_location", info.m_location ); 
    1460         result &= ser.write( strstrm.str() + "/m_name", info.m_name ); 
    1461     } 
    1462  
    1463     return result; 
    1464 
    1465  
    1466 bool 
    1467 AvPlug::deserializeChannelInfos( Glib::ustring basePath, 
    1468                                  Util::IODeserialize& deser, 
    1469                                  ClusterInfo& clusterInfo ) 
    1470 
    1471     int i = 0; 
    1472     bool bFinished = false; 
    1473     bool result = true; 
    1474     do { 
    1475         std::ostringstream strstrm; 
    1476         strstrm << basePath << i; 
    1477  
    1478         // check for one element to exist. when one exist the other elements 
    1479         // must also be there. otherwise just return (last) result. 
    1480         if ( deser.isExisting( strstrm.str() + "/m_streamPosition" ) ) { 
    1481             ChannelInfo info; 
    1482  
    1483             result &= deser.read( strstrm.str() + "/m_streamPosition", info.m_streamPosition ); 
    1484             result &= deser.read( strstrm.str() + "/m_location", info.m_location ); 
    1485             result &= deser.read( strstrm.str() + "/m_name", info.m_name ); 
    1486  
    1487             if ( result ) { 
    1488                 clusterInfo.m_channelInfos.push_back( info ); 
    1489                 i++; 
    1490             } else { 
    1491                 bFinished = true; 
    1492             } 
    1493         } else { 
    1494             bFinished = true; 
    1495         } 
    1496     } while ( !bFinished ); 
    1497  
    1498     return result; 
    1499 
    1500  
    1501  
    1502 bool 
    1503 AvPlug::serializeClusterInfos( Glib::ustring basePath, 
    1504                                Util::IOSerialize& ser ) const 
    1505 
    1506     bool result = true; 
    1507     int i = 0; 
    1508     for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin(); 
    1509           it != m_clusterInfos.end(); 
    1510           ++it ) 
    1511     { 
    1512         const ClusterInfo& info = *it; 
    1513         std::ostringstream strstrm; 
    1514         strstrm << basePath << i; 
    1515  
    1516         result &= ser.write( strstrm.str() + "/m_index", info.m_index ); 
    1517         result &= ser.write( strstrm.str() + "/m_portType", info.m_portType ); 
    1518         result &= ser.write( strstrm.str() + "/m_name", info.m_name ); 
    1519         result &= ser.write( strstrm.str() + "/m_nrOfChannels", info.m_nrOfChannels ); 
    1520         result &= serializeChannelInfos( strstrm.str() + "/m_channelInfo", ser, info ); 
    1521         result &= ser.write( strstrm.str() + "/m_streamFormat", info.m_streamFormat ); 
    1522  
    1523     } 
    1524  
    1525     return result; 
    1526 
    1527  
    1528 bool 
    1529 AvPlug::deserializeClusterInfos( Glib::ustring basePath, 
    1530                                  Util::IODeserialize& deser ) 
    1531 
    1532     int i = 0; 
    1533     bool bFinished = false; 
    1534     bool result = true; 
    1535     do { 
    1536         std::ostringstream strstrm; 
    1537         strstrm << basePath << i; 
    1538  
    1539         // check for one element to exist. when one exist the other elements 
    1540         // must also be there. otherwise just return (last) result. 
    1541         if ( deser.isExisting( strstrm.str() + "/m_index" ) ) { 
    1542             ClusterInfo info; 
    1543  
    1544             result &= deser.read( strstrm.str() + "/m_index", info.m_index ); 
    1545             result &= deser.read( strstrm.str() + "/m_portType", info.m_portType ); 
    1546             result &= deser.read( strstrm.str() + "/m_name", info.m_name ); 
    1547             result &= deser.read( strstrm.str() + "/m_nrOfChannels", info.m_nrOfChannels ); 
    1548             result &= deserializeChannelInfos( strstrm.str() + "/m_channelInfo", deser, info ); 
    1549             result &= deser.read( strstrm.str() + "/m_streamFormat", info.m_streamFormat ); 
    1550  
    1551             if ( result ) { 
    1552                 m_clusterInfos.push_back( info ); 
    1553                 i++; 
    1554             } else { 
    1555                 bFinished = true; 
    1556             } 
    1557         } else { 
    1558             bFinished = true; 
    1559         } 
    1560     } while ( !bFinished ); 
    1561  
    1562     return result; 
    1563 
    1564  
    1565  
    1566 bool 
    1567 AvPlug::serializeFormatInfos( Glib::ustring basePath, 
    1568                               Util::IOSerialize& ser ) const 
    1569 
    1570     bool result = true; 
    1571     int i = 0; 
    1572     for ( FormatInfoVector::const_iterator it = m_formatInfos.begin(); 
    1573           it != m_formatInfos.end(); 
    1574           ++it ) 
    1575     { 
    1576         const FormatInfo& info = *it; 
    1577         std::ostringstream strstrm; 
    1578         strstrm << basePath << i; 
    1579  
    1580         result &= ser.write( strstrm.str() + "/m_samplingFrequency", info.m_samplingFrequency ); 
    1581         result &= ser.write( strstrm.str() + "/m_isSyncStream", info.m_isSyncStream ); 
    1582         result &= ser.write( strstrm.str() + "/m_audioChannels", info.m_audioChannels ); 
    1583         result &= ser.write( strstrm.str() + "/m_midiChannels", info.m_midiChannels ); 
    1584         result &= ser.write( strstrm.str() + "/m_index", info.m_index ); 
    1585     } 
    1586     return result; 
    1587 
    1588  
    1589 bool 
    1590 AvPlug::deserializeFormatInfos( Glib::ustring basePath, 
    1591                                 Util::IODeserialize& deser ) 
    1592 
    1593     int i = 0; 
    1594     bool bFinished = false; 
    1595     bool result = true; 
    1596     do { 
    1597         std::ostringstream strstrm; 
    1598         strstrm << basePath << i; 
    1599  
    1600         // check for one element to exist. when one exist the other elements 
    1601         // must also be there. otherwise just return (last) result. 
    1602         if ( deser.isExisting( strstrm.str() + "/m_samplingFrequency" ) ) { 
    1603             FormatInfo info; 
    1604  
    1605             result &= deser.read( strstrm.str() + "/m_samplingFrequency", info.m_samplingFrequency ); 
    1606             result &= deser.read( strstrm.str() + "/m_isSyncStream", info.m_isSyncStream ); 
    1607             result &= deser.read( strstrm.str() + "/m_audioChannels", info.m_audioChannels ); 
    1608             result &= deser.read( strstrm.str() + "/m_midiChannels", info.m_midiChannels ); 
    1609             result &= deser.read( strstrm.str() + "/m_index", info.m_index ); 
    1610  
    1611             if ( result ) { 
    1612                 m_formatInfos.push_back( info ); 
    1613                 i++; 
    1614             } else { 
    1615                 bFinished = true; 
    1616             } 
    1617         } else { 
    1618             bFinished = true; 
    1619         } 
    1620     } while ( !bFinished ); 
    1621  
    1622     return result; 
    1623 
    1624  
    1625  
    1626 bool 
    1627 AvPlug::serializeAvPlugVector( Glib::ustring basePath, 
    1628                                Util::IOSerialize& ser, 
    1629                                const AvPlugVector& vec) const 
    1630 
    1631     bool result = true; 
    1632     int i = 0; 
    1633     for ( AvPlugVector::const_iterator it = vec.begin(); 
    1634           it != vec.end(); 
    1635           ++it ) 
    1636     { 
    1637         const AvPlug* pPlug = *it; 
    1638         std::ostringstream strstrm; 
    1639         strstrm << basePath << i; 
    1640  
    1641         result &= ser.write( strstrm.str() + "/global_id", pPlug->getGlobalId() ); 
    1642         i++; 
    1643     } 
    1644     return result; 
    1645 
    1646  
    1647 bool 
    1648 AvPlug::deserializeAvPlugVector( Glib::ustring basePath, 
    1649                                  Util::IODeserialize& deser, 
    1650                                  AvPlugVector& vec ) 
    1651 
    1652     int i = 0; 
    1653     bool bFinished = false; 
    1654     bool result = true; 
    1655     do { 
    1656         std::ostringstream strstrm; 
    1657         strstrm << basePath << i; 
    1658  
    1659         // check for one element to exist. when one exist the other elements 
    1660         // must also be there. otherwise just return (last) result. 
    1661         if ( deser.isExisting( strstrm.str() + "/global_id" ) ) { 
    1662             unsigned int iPlugId; 
    1663             result &= deser.read( strstrm.str() + "/global_id", iPlugId ); 
    1664  
    1665             if ( result ) { 
    1666                 AvPlug* pPlug = m_plugManager->getPlug( iPlugId ); 
    1667                 if ( pPlug ) { 
    1668                     vec.push_back( pPlug ); 
    1669                 } else { 
    1670                     result = false; 
    1671                     bFinished = true; 
    1672                 } 
    1673                 i++; 
    1674             } else { 
    1675                 bFinished = true; 
    1676             } 
    1677         } else { 
    1678             bFinished = true; 
    1679         } 
    1680     } while ( !bFinished ); 
    1681  
    1682     return result; 
    1683 
    1684  
    1685 bool 
    1686 AvPlug::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    1687 
    1688     bool result; 
    1689     result  = ser.write( basePath + "m_subunitType", m_subunitType ); 
    1690     result &= ser.write( basePath + "m_subunitId", m_subunitId ); 
    1691     result &= ser.write( basePath + "m_functionBlockType", m_functionBlockType); 
    1692     result &= ser.write( basePath + "m_functionBlockId", m_functionBlockId); 
    1693     result &= ser.write( basePath + "m_addressType", m_addressType ); 
    1694     result &= ser.write( basePath + "m_direction", m_direction); 
    1695     result &= ser.write( basePath + "m_id", m_id); 
    1696     result &= ser.write( basePath + "m_infoPlugType", m_infoPlugType); 
    1697     result &= ser.write( basePath + "m_nrOfChannels", m_nrOfChannels); 
    1698     result &= ser.write( basePath + "m_name", m_name); 
    1699     result &= serializeClusterInfos( basePath + "m_clusterInfos", ser ); 
    1700     result &= ser.write( basePath + "m_samplingFrequency", m_samplingFrequency); 
    1701     result &= serializeFormatInfos( basePath + "m_formatInfo", ser ); 
    1702     result &= serializeAvPlugVector( basePath + "m_inputConnections", ser, m_inputConnections ); 
    1703     result &= serializeAvPlugVector( basePath + "m_outputConnections", ser, m_outputConnections ); 
    1704     result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel); 
    1705     result &= ser.write( basePath + "m_globalId", m_globalId); 
    1706     result &= ser.write( basePath + "m_globalIdCounter", m_globalIdCounter ); 
    1707  
    1708     return result; 
    1709 
    1710  
    1711 AvPlug* 
    1712 AvPlug::deserialize( Glib::ustring basePath, 
    1713                      Util::IODeserialize& deser, 
    1714                      AvDevice& avDevice, 
    1715                      AvPlugManager& plugManager ) 
    1716 
    1717     AvPlug* pPlug = new AvPlug; 
    1718     if ( !pPlug ) { 
    1719         return 0; 
    1720     } 
    1721  
    1722     pPlug->m_p1394Service = &avDevice.get1394Service(); 
    1723     pPlug->m_pConfigRom   = &avDevice.getConfigRom(); 
    1724     pPlug->m_plugManager  = &plugManager; 
    1725     bool result; 
    1726     result  = deser.read( basePath + "m_subunitType", pPlug->m_subunitType ); 
    1727     result &= deser.read( basePath + "m_subunitId", pPlug->m_subunitId ); 
    1728     result &= deser.read( basePath + "m_functionBlockType", pPlug->m_functionBlockType ); 
    1729     result &= deser.read( basePath + "m_functionBlockId", pPlug->m_functionBlockId ); 
    1730     result &= deser.read( basePath + "m_addressType", pPlug->m_addressType ); 
    1731     result &= deser.read( basePath + "m_direction", pPlug->m_direction ); 
    1732     result &= deser.read( basePath + "m_id", pPlug->m_id ); 
    1733     result &= deser.read( basePath + "m_infoPlugType", pPlug->m_infoPlugType ); 
    1734     result &= deser.read( basePath + "m_nrOfChannels", pPlug->m_nrOfChannels ); 
    1735     result &= deser.read( basePath + "m_name", pPlug->m_name ); 
    1736     result &= pPlug->deserializeClusterInfos( basePath + "m_clusterInfos", deser ); 
    1737     result &= deser.read( basePath + "m_samplingFrequency", pPlug->m_samplingFrequency ); 
    1738     result &= pPlug->deserializeFormatInfos( basePath + "m_formatInfos", deser ); 
    1739     // input and output connections can't be processed here because not all plugs might 
    1740     // deserialized at this point. so we do that in deserializeUpdate. 
    1741     result &= deser.read( basePath + "m_verboseLevel", pPlug->m_verboseLevel ); 
    1742     result &= deser.read( basePath + "m_globalId", pPlug->m_globalId ); 
    1743     result &= deser.read( basePath + "m_globalIdCounter", pPlug->m_globalIdCounter ); 
    1744  
    1745     if ( !result ) { 
    1746         delete pPlug; 
    1747         return 0; 
    1748     } 
    1749  
    1750     return pPlug; 
    1751 
    1752  
    1753 bool 
    1754 AvPlug::deserializeUpdate( Glib::ustring basePath, 
    1755                            Util::IODeserialize& deser ) 
    1756 
    1757     bool result; 
    1758  
    1759     result  = deserializeAvPlugVector( basePath + "m_inputConnections", deser, m_inputConnections ); 
    1760     result &= deserializeAvPlugVector( basePath + "m_outputConnections", deser, m_outputConnections ); 
    1761  
    1762     return result; 
    1763 
    1764  
    1765 ///////////////////////////////////////// 
    1766 ///////////////////////////////////////// 
    1767  
    1768 const char* avPlugAddressTypeStrings[] = 
    1769 
    1770     "PCR", 
    1771     "external", 
    1772     "asynchronous", 
    1773     "subunit", 
    1774     "functionblock", 
    1775     "undefined", 
    1776 }; 
    1777  
    1778 const char* avPlugAddressTypeToString( AvPlug::EAvPlugAddressType type ) 
    1779 
    1780     if ( type > ( int )( sizeof( avPlugAddressTypeStrings ) 
    1781                          / sizeof( avPlugAddressTypeStrings[0] ) ) ) 
    1782     { 
    1783         type = AvPlug::eAPA_Undefined; 
    1784     } 
    1785     return avPlugAddressTypeStrings[type]; 
    1786 
    1787  
    1788 const char* avPlugTypeStrings[] = 
    1789 
    1790     "IsoStream", 
    1791     "AsyncStream", 
    1792     "MIDI", 
    1793     "Sync", 
    1794     "Analog", 
    1795     "Digital", 
    1796     "Unknown", 
    1797 }; 
    1798  
    1799 const char* avPlugTypeToString( AvPlug::EAvPlugType type ) 
    1800 
    1801     if ( type > ( int )( sizeof( avPlugTypeStrings ) 
    1802                          / sizeof( avPlugTypeStrings[0] ) ) ) 
    1803     { 
    1804         type = AvPlug::eAPT_Unknown; 
    1805     } 
    1806     return avPlugTypeStrings[type]; 
    1807 
    1808  
    1809 const char* avPlugDirectionStrings[] = 
    1810 
    1811     "Input", 
    1812     "Output", 
    1813     "Unknown", 
    1814 }; 
    1815  
    1816 const char* avPlugDirectionToString( AvPlug::EAvPlugDirection type ) 
    1817 
    1818     if ( type > ( int )( sizeof( avPlugDirectionStrings ) 
    1819                          / sizeof( avPlugDirectionStrings[0] ) ) ) 
    1820     { 
    1821         type = AvPlug::eAPD_Unknown; 
    1822     } 
    1823     return avPlugDirectionStrings[type]; 
    1824 
    1825  
    1826 ///////////////////////////////////// 
    1827  
    1828  
    1829 AvPlugManager::AvPlugManager( int verboseLevel ) 
    1830     : m_verboseLevel( verboseLevel ) 
    1831 
    1832     setDebugLevel( m_verboseLevel ); 
    1833 
    1834  
    1835 AvPlugManager::AvPlugManager() 
    1836     : m_verboseLevel( 0 ) 
    1837 
    1838     setDebugLevel( 0 ); 
    1839 
    1840  
    1841 AvPlugManager::AvPlugManager( const AvPlugManager& rhs ) 
    1842     : m_verboseLevel( rhs.m_verboseLevel ) 
    1843 
    1844     setDebugLevel( m_verboseLevel ); 
    1845 
    1846  
    1847 AvPlugManager::~AvPlugManager() 
    1848 
    1849 
    1850  
    1851 bool 
    1852 AvPlugManager::addPlug( AvPlug& plug ) 
    1853 
    1854     m_plugs.push_back( &plug ); 
    1855     return true; 
    1856 
    1857  
    1858 bool 
    1859 AvPlugManager::remPlug( AvPlug& plug ) 
    1860 
    1861     for ( AvPlugVector::iterator it = m_plugs.begin(); 
    1862           it !=  m_plugs.end(); 
    1863           ++it ) 
    1864     { 
    1865         AvPlug* plugIt = *it; 
    1866         if ( plugIt == &plug ) { 
    1867             m_plugs.erase( it ); 
    1868             return true; 
    1869         } 
    1870     } 
    1871     return false; 
    1872 
    1873  
    1874 // helper function 
    1875 static void addConnection( AvPlugConnectionOwnerVector& connections, 
    1876                            AvPlug& srcPlug, 
    1877                            AvPlug& destPlug ) 
    1878 
    1879     for ( AvPlugConnectionOwnerVector::iterator it = connections.begin(); 
    1880           it != connections.end(); 
    1881           ++it ) 
    1882     { 
    1883         AvPlugConnection& con = *it; 
    1884         if ( ( &( con.getSrcPlug() ) == &srcPlug ) 
    1885              && ( &( con.getDestPlug() ) == &destPlug ) ) 
    1886         { 
    1887             return; 
    1888         } 
    1889     } 
    1890     connections.push_back( AvPlugConnection( srcPlug, destPlug ) ); 
    1891 
    1892  
    1893 void 
    1894 AvPlugManager::showPlugs() const 
    1895 
    1896     // \todo The information provided here could be better arranged. For a start it is ok, but 
    1897     // there is room for improvement. Something for a lazy sunday afternoon (tip: maybe drink some 
    1898     // beer to get into the mood) 
    1899  
    1900     printf( "\nSummary\n" ); 
    1901     printf( "-------\n\n" ); 
    1902     printf( "Nr | AddressType     | Direction | SubUnitType | SubUnitId | FunctionBlockType | FunctionBlockId | Id   | Type         |Name\n" ); 
    1903     printf( "---+-----------------+-----------+-------------+-----------+-------------------+-----------------+------+--------------+------\n" ); 
    1904  
    1905     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    1906           it !=  m_plugs.end(); 
    1907           ++it ) 
    1908     { 
    1909         AvPlug* plug = *it; 
    1910  
    1911         printf( "%2d | %15s | %9s | %11s |      0x%02x |              0x%02x |            0x%02x | 0x%02x | %12s | %s\n", 
    1912                 plug->getGlobalId(), 
    1913                 avPlugAddressTypeToString( plug->getPlugAddressType() ), 
    1914                 avPlugDirectionToString( plug->getDirection() ), 
    1915                 subunitTypeToString( plug->getSubunitType() ), 
    1916                 plug->getSubunitId(), 
    1917                 plug->getFunctionBlockType(), 
    1918                 plug->getFunctionBlockId(), 
    1919                 plug->getPlugId(), 
    1920                 avPlugTypeToString( plug->getPlugType() ), 
    1921                 plug->getName() ); 
    1922     } 
    1923  
    1924     printf( "\nConnections\n" ); 
    1925     printf( "-----------\n" ); 
    1926  
    1927     AvPlugConnectionOwnerVector connections; 
    1928  
    1929     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    1930           it !=  m_plugs.end(); 
    1931           ++it ) 
    1932     { 
    1933         AvPlug* plug = *it; 
    1934         for ( AvPlugVector::const_iterator it = 
    1935                   plug->getInputConnections().begin(); 
    1936             it != plug->getInputConnections().end(); 
    1937             ++it ) 
    1938         { 
    1939             addConnection( connections, *( *it ), *plug ); 
    1940         } 
    1941         for ( AvPlugVector::const_iterator it = 
    1942                   plug->getOutputConnections().begin(); 
    1943             it != plug->getOutputConnections().end(); 
    1944             ++it ) 
    1945         { 
    1946             addConnection( connections, *plug, *( *it ) ); 
    1947         } 
    1948     } 
    1949  
    1950     printf( "digraph avcconnections {\n" ); 
    1951     for ( AvPlugConnectionOwnerVector::iterator it = connections.begin(); 
    1952           it != connections.end(); 
    1953           ++it ) 
    1954     { 
    1955         AvPlugConnection& con = *it; 
    1956         printf( "\t\"(%d) %s\" -> \"(%d) %s\"\n", 
    1957                 con.getSrcPlug().getGlobalId(), 
    1958                 con.getSrcPlug().getName(), 
    1959                 con.getDestPlug().getGlobalId(), 
    1960                 con.getDestPlug().getName() ); 
    1961     } 
    1962     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    1963           it != m_plugs.end(); 
    1964           ++it ) 
    1965     { 
    1966         AvPlug* plug = *it; 
    1967         if ( plug->getFunctionBlockType() != 0xff ) { 
    1968             std::ostringstream strstrm; 
    1969             switch(plug->getFunctionBlockType()) { 
    1970                 case 0x80: 
    1971                     strstrm << "Selector FB"; 
    1972                     break; 
    1973                 case 0x81: 
    1974                     strstrm << "Feature FB"; 
    1975                     break; 
    1976                 case 0x82: 
    1977                     strstrm << "Processing FB"; 
    1978                     break; 
    1979                 case 0x83: 
    1980                     strstrm << "CODEC FB"; 
    1981                     break; 
    1982                 default: 
    1983                     strstrm << plug->getFunctionBlockType(); 
    1984             } 
    1985              
    1986             if ( plug->getPlugDirection() == AvPlug::eAPD_Input ) { 
    1987                 printf( "\t\"(%d) %s\" -> \"(%s, ID %d)\"\n", 
    1988                         plug->getGlobalId(), 
    1989                         plug->getName(), 
    1990                         strstrm.str().c_str(), 
    1991                         plug->getFunctionBlockId() ); 
    1992             } else { 
    1993                 printf( "\t\"(%s, ID %d)\" -> \t\"(%d) %s\"\n", 
    1994                         strstrm.str().c_str(), 
    1995                         plug->getFunctionBlockId(), 
    1996                         plug->getGlobalId(), 
    1997                         plug->getName() ); 
    1998             } 
    1999         } 
    2000     } 
    2001  
    2002     const char* colorStrings[] = { 
    2003         "coral", 
    2004         "slateblue", 
    2005         "white", 
    2006         "green", 
    2007         "yellow", 
    2008         "grey", 
    2009     }; 
    2010  
    2011     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2012           it !=  m_plugs.end(); 
    2013           ++it ) 
    2014     { 
    2015         AvPlug* plug = *it; 
    2016         printf( "\t\"(%d) %s\" [color=%s,style=filled];\n", 
    2017                 plug->getGlobalId(), plug->getName(), 
    2018                 colorStrings[plug->getPlugAddressType() ] ); 
    2019     } 
    2020  
    2021     printf("}\n" ); 
    2022     printf( "Use \"dot -Tps FILENAME.dot -o FILENAME.ps\" " 
    2023             "to generate graph\n"); 
    2024  
    2025     debugOutput( DEBUG_LEVEL_VERBOSE, "Plug details\n" ); 
    2026     debugOutput( DEBUG_LEVEL_VERBOSE, "------------\n" ); 
    2027     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2028           it !=  m_plugs.end(); 
    2029           ++it ) 
    2030     { 
    2031         AvPlug* plug = *it; 
    2032         debugOutput( DEBUG_LEVEL_VERBOSE, "Plug %d:\n", plug->getGlobalId() ); 
    2033         plug->showPlug(); 
    2034  
    2035     } 
    2036 
    2037  
    2038 AvPlug* 
    2039 AvPlugManager::getPlug( ESubunitType subunitType, 
    2040                         subunit_id_t subunitId, 
    2041                         function_block_type_t functionBlockType, 
    2042                         function_block_id_t functionBlockId, 
    2043                         AvPlug::EAvPlugAddressType plugAddressType, 
    2044                         AvPlug::EAvPlugDirection plugDirection, 
    2045                         plug_id_t plugId ) const 
    2046 
    2047     debugOutput( DEBUG_LEVEL_VERBOSE, "SBT, SBID, FBT, FBID, AT, PD, ID = " 
    2048                  "(0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n", 
    2049                  subunitType, 
    2050                  subunitId, 
    2051                  functionBlockType, 
    2052                  functionBlockId, 
    2053                  plugAddressType, 
    2054                  plugDirection, 
    2055                  plugId ); 
    2056  
    2057     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2058           it !=  m_plugs.end(); 
    2059           ++it ) 
    2060     { 
    2061         AvPlug* plug = *it; 
    2062  
    2063         if (    ( subunitType == plug->getSubunitType() ) 
    2064              && ( subunitId == plug->getSubunitId() ) 
    2065              && ( functionBlockType == plug->getFunctionBlockType() ) 
    2066              && ( functionBlockId == plug->getFunctionBlockId() ) 
    2067              && ( plugAddressType == plug->getPlugAddressType() ) 
    2068              && ( plugDirection == plug->getPlugDirection() ) 
    2069              && ( plugId == plug->getPlugId() ) ) 
    2070         { 
    2071             return plug; 
    2072         } 
    2073     } 
    2074  
    2075     return 0; 
    2076 
    2077  
    2078 AvPlug* 
    2079 AvPlugManager::getPlug( int iGlobalId ) const 
    2080 
    2081     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2082           it !=  m_plugs.end(); 
    2083           ++it ) 
    2084     { 
    2085         AvPlug* pPlug = *it; 
    2086         if ( pPlug->getGlobalId() == iGlobalId ) { 
    2087             return pPlug; 
    2088         } 
    2089     } 
    2090  
    2091     return 0; 
    2092 
    2093  
    2094 AvPlugVector 
    2095 AvPlugManager::getPlugsByType( ESubunitType subunitType, 
    2096                                subunit_id_t subunitId, 
    2097                                function_block_type_t functionBlockType, 
    2098                                function_block_id_t functionBlockId, 
    2099                                AvPlug::EAvPlugAddressType plugAddressType, 
    2100                                AvPlug::EAvPlugDirection plugDirection, 
    2101                                AvPlug::EAvPlugType type) const 
    2102 
    2103     debugOutput( DEBUG_LEVEL_VERBOSE, "SBT, SBID, FBT, FBID, AT, PD, T = " 
    2104                  "(0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x)\n", 
    2105                  subunitType, 
    2106                  subunitId, 
    2107                  functionBlockType, 
    2108                  functionBlockId, 
    2109                  plugAddressType, 
    2110                  plugDirection, 
    2111                  type ); 
    2112  
    2113     AvPlugVector plugVector; 
    2114     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2115           it !=  m_plugs.end(); 
    2116           ++it ) 
    2117     { 
    2118         AvPlug* pPlug = *it; 
    2119  
    2120         if (    ( subunitType == pPlug->getSubunitType() ) 
    2121              && ( subunitId == pPlug->getSubunitId() ) 
    2122              && ( functionBlockType == pPlug->getFunctionBlockType() ) 
    2123              && ( functionBlockId == pPlug->getFunctionBlockId() ) 
    2124              && ( plugAddressType == pPlug->getPlugAddressType() ) 
    2125              && ( plugDirection == pPlug->getPlugDirection() ) 
    2126              && ( type == pPlug->getPlugType() ) ) 
    2127         { 
    2128             plugVector.push_back( pPlug ); 
    2129         } 
    2130     } 
    2131  
    2132     return plugVector; 
    2133 
    2134  
    2135 bool 
    2136 AvPlugManager::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    2137 
    2138     bool result = true; 
    2139     int i = 0; 
    2140     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
    2141           it !=  m_plugs.end(); 
    2142           ++it ) 
    2143     { 
    2144         AvPlug* pPlug = *it; 
    2145         std::ostringstream strstrm; 
    2146         strstrm << basePath << i; 
    2147         result &= pPlug->serialize( strstrm.str() + "/", ser ); 
    2148         i++; 
    2149     } 
    2150  
    2151     return result; 
    2152 
    2153  
    2154 AvPlugManager* 
    2155 AvPlugManager::deserialize( Glib::ustring basePath, 
    2156                             Util::IODeserialize& deser, 
    2157                             AvDevice& avDevice ) 
    2158  
    2159 
    2160     AvPlugManager* pMgr = new AvPlugManager; 
    2161  
    2162     if ( !pMgr ) { 
    2163         return 0; 
    2164     } 
    2165  
    2166     int i = 0; 
    2167     bool bFinished = false; 
    2168     do { 
    2169         std::ostringstream strstrm; 
    2170         strstrm << basePath << i; 
    2171         // avDevice still holds a null pointer for the plug manager 
    2172         // therefore we have to *this as additional argument 
    2173         AvPlug* pPlug = AvPlug::deserialize( strstrm.str() + "/", 
    2174                                              deser, 
    2175                                              avDevice, 
    2176                                              *pMgr ); 
    2177         if ( pPlug ) { 
    2178             pMgr->m_plugs.push_back( pPlug ); 
    2179             i++; 
    2180         } else { 
    2181             bFinished = true; 
    2182         } 
    2183     } while ( !bFinished ); 
    2184  
    2185     return pMgr; 
    2186 
    2187  
    2188  
    2189 //////////////////////////////////// 
    2190  
    2191 AvPlugConnection::AvPlugConnection( AvPlug& srcPlug, AvPlug& destPlug ) 
    2192     : m_srcPlug( &srcPlug ) 
    2193     , m_destPlug( &destPlug ) 
    2194 
    2195 
    2196  
    2197 AvPlugConnection::AvPlugConnection() 
    2198     : m_srcPlug( 0 ) 
    2199     , m_destPlug( 0 ) 
    2200 
    2201 
    2202  
    2203 bool 
    2204 AvPlugConnection::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    2205 
    2206     bool result; 
    2207     result  = ser.write( basePath + "m_srcPlug", m_srcPlug->getGlobalId() ); 
    2208     result &= ser.write( basePath + "m_destPlug", m_destPlug->getGlobalId() ); 
    2209     return result; 
    2210 
    2211  
    2212 AvPlugConnection* 
    2213 AvPlugConnection::deserialize( Glib::ustring basePath, 
    2214                                Util::IODeserialize& deser, 
    2215                                AvDevice& avDevice ) 
    2216 
    2217     AvPlugConnection* pConnection = new AvPlugConnection; 
    2218     if ( !pConnection ) { 
    2219         return 0; 
    2220     } 
    2221  
    2222     bool result; 
    2223     int iSrcPlugId; 
    2224     int iDestPlugId; 
    2225     result  = deser.read( basePath + "m_srcPlug", iSrcPlugId ); 
    2226     result &= deser.read( basePath + "m_destPlug",  iDestPlugId ); 
    2227  
    2228     if ( !result ) { 
    2229         delete pConnection; 
    2230         return 0; 
    2231     } 
    2232  
    2233     pConnection->m_srcPlug  = avDevice.getPlugManager().getPlug( iSrcPlugId ); 
    2234     pConnection->m_destPlug = avDevice.getPlugManager().getPlug( iDestPlugId ); 
    2235  
    2236     if ( !pConnection->m_srcPlug || !pConnection->m_destPlug ) { 
    2237         delete pConnection; 
    2238         return 0; 
    2239     } 
    2240  
    2241     return pConnection; 
    2242 
    2243  
    2244 
     897
  • branches/echoaudio/src/bebob/bebob_avplug.h

    r505 r507  
    3131#include "libavc/avc_definitions.h" 
    3232#include "libavc/general/avc_generic.h" 
     33#include "libavc/general/avc_plug.h" 
    3334 
    3435#include "libutil/serialize.h" 
     
    4445 
    4546class AvDevice; 
    46 class AvPlugManager; 
    47 class AvPlug; 
    4847 
    49 typedef std::vector<AvPlug*> AvPlugVector; 
    50  
    51 class AvPlug { 
     48class Plug : public AVC::Plug { 
    5249public: 
    5350 
    54     enum EAvPlugAddressType { 
    55     eAPA_PCR, 
    56     eAPA_ExternalPlug, 
    57     eAPA_AsynchronousPlug, 
    58     eAPA_SubunitPlug, 
    59     eAPA_FunctionBlockPlug, 
    60     eAPA_Undefined, 
    61     }; 
    62  
    63     enum EAvPlugType { 
    64         eAPT_IsoStream, 
    65         eAPT_AsyncStream, 
    66         eAPT_Midi, 
    67         eAPT_Sync, 
    68         eAPT_Analog, 
    69         eAPT_Digital, 
    70         eAPT_Unknown, 
    71     }; 
    72  
    73     enum EAvPlugDirection { 
    74     eAPD_Input, 
    75     eAPD_Output, 
    76     eAPD_Unknown, 
    77     }; 
    78  
    7951    // \todo This constructors sucks. too many parameters. fix it. 
    80     AvPlug( Ieee1394Service& ieee1394Service, 
    81         ConfigRom& configRom, 
    82             AvPlugManager& plugManager, 
    83         AVC::ESubunitType subunitType, 
    84         AVC::subunit_id_t subunitId, 
    85         AVC::function_block_type_t functionBlockType, 
    86         AVC::function_block_type_t functionBlockId, 
    87         EAvPlugAddressType plugAddressType, 
    88         EAvPlugDirection plugDirection, 
    89         AVC::plug_id_t plugId, 
    90         int verboseLevel ); 
    91     AvPlug( const AvPlug& rhs ); 
    92     virtual ~AvPlug(); 
     52    Plug( AVC::Unit* unit, 
     53          AVC::Subunit* subunit, 
     54          AVC::function_block_type_t functionBlockType, 
     55          AVC::function_block_type_t functionBlockId, 
     56          AVC::Plug::EPlugAddressType plugAddressType, 
     57          AVC::Plug::EPlugDirection plugDirection, 
     58          AVC::plug_id_t plugId ); 
     59    Plug( const Plug& rhs ); 
     60    virtual ~Plug(); 
    9361 
    9462    bool discover(); 
    9563    bool discoverConnections(); 
    9664 
    97     bool inquireConnnection( AvPlug& plug ); 
    98     bool setConnection( AvPlug& plug ); 
    99  
    100     int getGlobalId() const 
    101         { return m_globalId; } 
    102     AVC::plug_id_t getPlugId() const 
    103         { return m_id; } 
    104     AVC::ESubunitType getSubunitType() const 
    105         { return m_subunitType; } 
    106     AVC::subunit_id_t getSubunitId() const 
    107         { return m_subunitId; } 
    108     const char* getName() const 
    109         { return m_name.c_str(); } 
    110     EAvPlugDirection getPlugDirection() const 
    111         { return m_direction; } 
    112     AVC::sampling_frequency_t getSamplingFrequency() const 
    113         { return m_samplingFrequency; } 
    114     int getSampleRate() const; // 22050, 24000, 32000, ... 
    115     int getNrOfChannels() const; 
    116     int getNrOfStreams() const; 
    117  
    118     EAvPlugDirection getDirection() const 
    119         { return m_direction; } 
    120     EAvPlugAddressType getPlugAddressType() const 
    121         { return m_addressType; } 
    122     EAvPlugType getPlugType() const 
    123         { return m_infoPlugType; } 
    124  
    125     AVC::function_block_type_t getFunctionBlockType() const 
    126         { return m_functionBlockType; } 
    127     AVC::function_block_id_t getFunctionBlockId() const 
    128         { return m_functionBlockId; } 
    129  
    130     const AvPlugVector& getInputConnections() const 
    131         { return m_inputConnections; } 
    132     const AvPlugVector& getOutputConnections() const 
    133         { return m_outputConnections; } 
    134  
    135     static AVC::PlugAddress::EPlugDirection convertPlugDirection( 
    136     EAvPlugDirection direction); 
    137  
    138     void showPlug() const; 
    139  
    140     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    141     static AvPlug* deserialize( Glib::ustring basePath, 
    142                                 Util::IODeserialize& deser, 
    143                                 AvDevice& avDevice, 
    144                                 AvPlugManager& plugManager ); 
    145  
    146     bool deserializeUpdate( Glib::ustring basePath, 
    147                             Util::IODeserialize& deser ); 
    148  
    14965 public: 
    150     struct ChannelInfo { 
    151         AVC::stream_position_t          m_streamPosition; 
    152         AVC::stream_position_location_t m_location; 
    153         Glib::ustring                   m_name; 
    154     }; 
    155     typedef std::vector<ChannelInfo> ChannelInfoVector; 
    156  
    157     struct ClusterInfo { 
    158         int                      m_index; 
    159         AVC::port_type_t         m_portType; 
    160         Glib::ustring            m_name; 
    161  
    162         AVC::nr_of_channels_t    m_nrOfChannels; 
    163         ChannelInfoVector        m_channelInfos; 
    164         AVC::stream_format_t     m_streamFormat; 
    165     }; 
    166     typedef std::vector<ClusterInfo> ClusterInfoVector; 
    167  
    168     ClusterInfoVector& getClusterInfos() 
    169         { return m_clusterInfos; } 
    17066 
    17167protected: 
    172     AvPlug(); 
     68    Plug(); 
    17369 
    17470    bool discoverPlugType(); 
     
    18884            AVC::ExtendedStreamFormatCmd::ESubFunction subFunction); 
    18985 
    190     AVC::SignalSourceCmd setSrcPlugAddrToSignalCmd(); 
     86private: 
    19187 
    192     void setDestPlugAddrToSignalCmd( 
    193             AVC::SignalSourceCmd& signalSourceCmd, AvPlug& plug ); 
    194  
    195     void debugOutputClusterInfos( int debugLevel ); 
    196  
    197     bool copyClusterInfo(AVC::ExtendedPlugInfoPlugChannelPositionSpecificData& 
    198                          channelPositionData ); 
    199  
    200     bool addPlugConnection( AvPlugVector& connections, AvPlug& plug ); 
    201  
    202     bool discoverConnectionsFromSpecificData( 
    203         EAvPlugDirection discoverDirection, 
    204         AVC::PlugAddressSpecificData* plugAddress, 
    205         AvPlugVector& connections ); 
    206  
    207     AvPlug* getPlugDefinedBySpecificData( 
    208         AVC::UnitPlugSpecificDataPlugAddress* pUnitPlugAddress, 
    209         AVC::SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress, 
    210         AVC::FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress ); 
    211  
    212     EAvPlugDirection toggleDirection( EAvPlugDirection direction ) const; 
    213  
    214     const ClusterInfo* getClusterInfoByIndex( int index ) const; 
    215  
    216     bool serializeChannelInfos( Glib::ustring basePath, 
    217                                 Util::IOSerialize& ser, 
    218                                 const ClusterInfo& clusterInfo ) const; 
    219     bool deserializeChannelInfos( Glib::ustring basePath, 
    220                                   Util::IODeserialize& deser, 
    221                                   ClusterInfo& clusterInfo ); 
    222  
    223     bool serializeClusterInfos( Glib::ustring basePath, 
    224                                 Util::IOSerialize& ser ) const; 
    225     bool deserializeClusterInfos( Glib::ustring basePath, 
    226                                   Util::IODeserialize& deser ); 
    227  
    228     bool serializeFormatInfos( Glib::ustring basePath, 
    229                                Util::IOSerialize& ser ) const; 
    230     bool deserializeFormatInfos( Glib::ustring basePath, 
    231                                  Util::IODeserialize& deser ); 
    232  
    233     bool serializeAvPlugVector( Glib::ustring basePath, 
    234                                 Util::IOSerialize& ser, 
    235                                 const AvPlugVector& vec) const; 
    236     bool deserializeAvPlugVector( Glib::ustring basePath, 
    237                                   Util::IODeserialize& deser, 
    238                                   AvPlugVector& vec ); 
    239  
    240 private: 
    241     // Supported stream formats 
    242     struct FormatInfo { 
    243         FormatInfo() 
    244             : m_samplingFrequency( AVC::eSF_DontCare ) 
    245             , m_isSyncStream( false ) 
    246             , m_audioChannels( 0 ) 
    247             , m_midiChannels( 0 ) 
    248             , m_index( 0xff ) 
    249             {} 
    250     AVC::sampling_frequency_t  m_samplingFrequency; 
    251     bool                       m_isSyncStream; 
    252     AVC::number_of_channels_t  m_audioChannels; 
    253     AVC::number_of_channels_t  m_midiChannels; 
    254     byte_t                     m_index; 
    255     }; 
    256     typedef std::vector<FormatInfo> FormatInfoVector; 
    257  
    258  
    259     Ieee1394Service*             m_p1394Service; 
    260     ConfigRom*                   m_pConfigRom; 
    261     AVC::ESubunitType     m_subunitType; 
    262     AVC::subunit_id_t                 m_subunitId; 
    263     AVC::function_block_type_t        m_functionBlockType; 
    264     AVC::function_block_id_t          m_functionBlockId; 
    265     EAvPlugAddressType           m_addressType; 
    266     EAvPlugDirection             m_direction; 
    267     AVC::plug_id_t                    m_id; 
    268     EAvPlugType                  m_infoPlugType; 
    269     AVC::nr_of_channels_t             m_nrOfChannels; 
    270     Glib::ustring                m_name; 
    271     ClusterInfoVector            m_clusterInfos; 
    272     AVC::sampling_frequency_t         m_samplingFrequency; 
    273     FormatInfoVector             m_formatInfos; 
    274     AvPlugVector                 m_inputConnections; 
    275     AvPlugVector                 m_outputConnections; 
    276     AvPlugManager*               m_plugManager; 
    277     int                          m_verboseLevel; 
    278     int                          m_globalId; 
    279     static int                   m_globalIdCounter; 
    280  
    281     DECLARE_DEBUG_MODULE; 
    28288}; 
    283  
    284 const char* avPlugAddressTypeToString( AvPlug::EAvPlugAddressType addressType ); 
    285 const char* avPlugTypeToString( AvPlug::EAvPlugType type ); 
    286 const char* avPlugDirectionToString( AvPlug::EAvPlugDirection direction ); 
    287  
    288 class AvPlugManager 
    289 { 
    290 public: 
    291     AvPlugManager( int verboseLevel ); 
    292     AvPlugManager( const AvPlugManager& rhs ); 
    293     ~AvPlugManager(); 
    294  
    295     bool addPlug( AvPlug& plug ); 
    296     bool remPlug( AvPlug& plug ); 
    297  
    298     void showPlugs() const; 
    299  
    300     AvPlug* getPlug( AVC::ESubunitType subunitType, 
    301                      AVC::subunit_id_t subunitId, 
    302                      AVC::function_block_type_t functionBlockType, 
    303                      AVC::function_block_id_t functionBlockId, 
    304                      AvPlug::EAvPlugAddressType plugAddressType, 
    305                      AvPlug::EAvPlugDirection plugDirection, 
    306                      AVC::plug_id_t plugId ) const; 
    307     AvPlug* getPlug( int iGlobalId ) const; 
    308     AvPlugVector getPlugsByType( AVC::ESubunitType subunitType, 
    309                  AVC::subunit_id_t subunitId, 
    310                  AVC::function_block_type_t functionBlockType, 
    311                  AVC::function_block_id_t functionBlockId, 
    312                  AvPlug::EAvPlugAddressType plugAddressType, 
    313                  AvPlug::EAvPlugDirection plugDirection, 
    314                  AvPlug::EAvPlugType type) const; 
    315  
    316     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    317     static  AvPlugManager* deserialize( Glib::ustring basePath, 
    318                                         Util::IODeserialize& deser, 
    319                                         AvDevice& avDevice ); 
    320  
    321 private: 
    322     AvPlugManager(); 
    323  
    324     int          m_verboseLevel; 
    325     AvPlugVector m_plugs; 
    326  
    327     DECLARE_DEBUG_MODULE; 
    328 }; 
    329  
    330 class AvPlugConnection { 
    331 public: 
    332     AvPlugConnection( AvPlug& srcPlug, AvPlug& destPlug ); 
    333  
    334     AvPlug& getSrcPlug() const 
    335         { return *m_srcPlug; } 
    336     AvPlug& getDestPlug() const 
    337         { return *m_destPlug; } 
    338  
    339     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    340     static AvPlugConnection* deserialize( Glib::ustring basePath, 
    341                                           Util::IODeserialize& deser, 
    342                                           AvDevice& avDevice ); 
    343 private: 
    344     AvPlugConnection(); 
    345  
    346 private: 
    347     AvPlug* m_srcPlug; 
    348     AvPlug* m_destPlug; 
    349 }; 
    350  
    351 typedef std::vector<AvPlugConnection*> AvPlugConnectionVector; 
    352 typedef std::vector<AvPlugConnection> AvPlugConnectionOwnerVector; 
    35389 
    35490} 
  • branches/echoaudio/src/bebob/bebob_functionblock.cpp

    r503 r507  
    2929using namespace AVC; 
    3030 
    31 IMPL_DEBUG_MODULE( BeBoB::FunctionBlock, BeBoB::FunctionBlock, DEBUG_LEVEL_NORMAL ); 
    32  
    33 BeBoB::FunctionBlock::FunctionBlock( 
    34     AvDeviceSubunit& subunit, 
     31namespace BeBoB { 
     32 
     33IMPL_DEBUG_MODULE( FunctionBlock, FunctionBlock, DEBUG_LEVEL_NORMAL ); 
     34 
     35FunctionBlock::FunctionBlock( 
     36    Subunit& subunit, 
    3537    function_block_type_t type, 
    3638    function_block_type_t subtype, 
     
    5254} 
    5355 
    54 BeBoB::FunctionBlock::FunctionBlock( const FunctionBlock& rhs ) 
     56FunctionBlock::FunctionBlock( const FunctionBlock& rhs ) 
    5557    : m_subunit( rhs.m_subunit ) 
    5658    , m_type( rhs.m_type ) 
     
    6466} 
    6567 
    66 BeBoB::FunctionBlock::FunctionBlock() 
    67 { 
    68 } 
    69  
    70 BeBoB::FunctionBlock::~FunctionBlock() 
    71 { 
    72     for ( AvPlugVector::iterator it = m_plugs.begin(); 
     68FunctionBlock::FunctionBlock() 
     69{ 
     70} 
     71 
     72FunctionBlock::~FunctionBlock() 
     73{ 
     74    for ( PlugVector::iterator it = m_plugs.begin(); 
    7375          it != m_plugs.end(); 
    7476          ++it ) 
     
    8082 
    8183bool 
    82 BeBoB::FunctionBlock::discover() 
     84FunctionBlock::discover() 
    8385{ 
    8486    debugOutput( DEBUG_LEVEL_NORMAL, 
     
    8991                 m_nrOfOutputPlugs ); 
    9092 
    91     if ( !discoverPlugs( AvPlug::eAPD_Input, m_nrOfInputPlugs ) ) { 
     93    if ( !discoverPlugs( AVC::Plug::eAPD_Input, m_nrOfInputPlugs ) ) { 
    9294        debugError( "Could not discover input plug for '%s'\n", 
    9395                    getName() ); 
     
    9597    } 
    9698 
    97     if ( !discoverPlugs( AvPlug::eAPD_Output, m_nrOfOutputPlugs ) ) { 
     99    if ( !discoverPlugs( AVC::Plug::eAPD_Output, m_nrOfOutputPlugs ) ) { 
    98100        debugError( "Could not discover output plugs for '%s'\n", 
    99101                    getName() ); 
     
    105107 
    106108bool 
    107 BeBoB::FunctionBlock::discoverPlugs( AvPlug::EAvPlugDirection plugDirection, 
     109FunctionBlock::discoverPlugs( AVC::Plug::EPlugDirection plugDirection, 
    108110                                     plug_id_t plugMaxId ) 
    109111{ 
    110112    for ( int plugId = 0; plugId < plugMaxId; ++plugId ) { 
    111         AvPlug* plug = new AvPlug( 
    112             m_subunit->getAvDevice().get1394Service(), 
    113             m_subunit->getAvDevice().getConfigRom(), 
    114             m_subunit->getAvDevice().getPlugManager(), 
    115             m_subunit->getSubunitType(), 
    116             m_subunit->getSubunitId(), 
     113        AVC::Plug* plug = new BeBoB::Plug( 
     114            &m_subunit->getUnit(), 
     115            m_subunit, 
    117116            m_type, 
    118117            m_id, 
    119             AvPlug::eAPA_FunctionBlockPlug, 
     118            AVC::Plug::eAPA_FunctionBlockPlug, 
    120119            plugDirection, 
    121             plugId, 
    122             m_verbose ); 
     120            plugId); 
    123121 
    124122        if ( !plug || !plug->discover() ) { 
     
    138136 
    139137bool 
    140 BeBoB::FunctionBlock::discoverConnections() 
     138FunctionBlock::discoverConnections() 
    141139{ 
    142140    debugOutput( DEBUG_LEVEL_VERBOSE, 
     
    144142                 getName() ); 
    145143 
    146     for ( AvPlugVector::iterator it = m_plugs.begin(); 
     144    for ( PlugVector::iterator it = m_plugs.begin(); 
    147145          it != m_plugs.end(); 
    148146          ++it ) 
    149147    { 
    150         AvPlug* plug = *it; 
     148        AVC::Plug* plug = *it; 
    151149        if ( !plug->discoverConnections() ) { 
    152150            debugError( "Could not discover plug connections\n" ); 
     
    158156 
    159157bool 
    160 serializeAvPlugVector( Glib::ustring basePath, 
     158serializePlugVector( Glib::ustring basePath, 
    161159                       Util::IOSerialize& ser, 
    162                        const BeBoB::AvPlugVector& vec ) 
     160                       const PlugVector& vec ) 
    163161{ 
    164162    bool result = true; 
    165163    int i = 0; 
    166     for ( BeBoB::AvPlugVector::const_iterator it = vec.begin(); 
     164    for ( PlugVector::const_iterator it = vec.begin(); 
    167165          it != vec.end(); 
    168166          ++it ) 
     
    177175 
    178176bool 
    179 deserializeAvPlugVector( Glib::ustring basePath, 
     177deserializePlugVector( Glib::ustring basePath, 
    180178                         Util::IODeserialize& deser, 
    181                          BeBoB::AvDevice& avDevice
    182                          BeBoB::AvPlugVector& vec ) 
     179                         AVC::Unit& unit
     180                         PlugVector& vec ) 
    183181{ 
    184182    int i = 0; 
     
    191189 
    192190        result &= deser.read( strstrm.str(), plugId ); 
    193         BeBoB::AvPlug* pPlug = avDevice.getPlugManager().getPlug( plugId ); 
     191        AVC::Plug* pPlug = unit.getPlugManager().getPlug( plugId ); 
    194192 
    195193        if ( pPlug ) { 
     
    205203 
    206204bool 
    207 BeBoB::FunctionBlock::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     205FunctionBlock::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    208206{ 
    209207    bool result; 
     
    216214    result &= ser.write( basePath + "m_nrOfOutputPlugs", m_nrOfOutputPlugs ); 
    217215    result &= ser.write( basePath + "m_verbose", m_verbose ); 
    218     result &= serializeAvPlugVector( basePath + "m_plugs", ser, m_plugs ); 
     216    result &= serializePlugVector( basePath + "m_plugs", ser, m_plugs ); 
    219217 
    220218    return result; 
    221219} 
    222220 
    223 BeBoB::FunctionBlock* 
    224 BeBoB::FunctionBlock::deserialize( Glib::ustring basePath, 
     221FunctionBlock* 
     222FunctionBlock::deserialize( Glib::ustring basePath, 
    225223                                   Util::IODeserialize& deser, 
    226                                    AvDevice& avDevice
    227                                    AvDeviceSubunit& subunit ) 
     224                                   AVC::Unit& unit
     225                                   AVC::Subunit& subunit ) 
    228226{ 
    229227    bool result; 
     
    272270    result &= deser.read( basePath + "m_nrOfOutputPlugs", pFB->m_nrOfOutputPlugs ); 
    273271    result &= deser.read( basePath + "m_verbose", pFB->m_verbose ); 
    274     result &= deserializeAvPlugVector( basePath + "m_plugs", deser, avDevice, pFB->m_plugs ); 
     272    result &= deserializePlugVector( basePath + "m_plugs", deser, unit, pFB->m_plugs ); 
    275273 
    276274    return 0; 
     
    279277/////////////////////// 
    280278 
    281 BeBoB::FunctionBlockSelector::FunctionBlockSelector( 
    282     AvDeviceSubunit& subunit, 
     279FunctionBlockSelector::FunctionBlockSelector( 
     280    AVC::Subunit& subunit, 
    283281    function_block_id_t id, 
    284282    ESpecialPurpose purpose, 
     
    297295} 
    298296 
    299 BeBoB::FunctionBlockSelector::FunctionBlockSelector( 
     297FunctionBlockSelector::FunctionBlockSelector( 
    300298    const FunctionBlockSelector& rhs ) 
    301299    : FunctionBlock( rhs ) 
     
    303301} 
    304302 
    305 BeBoB::FunctionBlockSelector::FunctionBlockSelector() 
     303FunctionBlockSelector::FunctionBlockSelector() 
    306304    : FunctionBlock() 
    307305{ 
    308306} 
    309307 
    310 BeBoB::FunctionBlockSelector::~FunctionBlockSelector() 
     308FunctionBlockSelector::~FunctionBlockSelector() 
    311309{ 
    312310} 
    313311 
    314312const char* 
    315 BeBoB::FunctionBlockSelector::getName() 
     313FunctionBlockSelector::getName() 
    316314{ 
    317315    return "Selector"; 
     
    319317 
    320318bool 
    321 BeBoB::FunctionBlockSelector::serializeChild( Glib::ustring basePath, 
     319FunctionBlockSelector::serializeChild( Glib::ustring basePath, 
    322320                                              Util::IOSerialize& ser ) const 
    323321{ 
     
    326324 
    327325bool 
    328 BeBoB::FunctionBlockSelector::deserializeChild( Glib::ustring basePath, 
     326FunctionBlockSelector::deserializeChild( Glib::ustring basePath, 
    329327                                                Util::IODeserialize& deser, 
    330                                                 AvDevice& avDevice
     328                                                AvDevice& unit
    331329{ 
    332330    return true; 
     
    335333/////////////////////// 
    336334 
    337 BeBoB::FunctionBlockFeature::FunctionBlockFeature( 
    338     AvDeviceSubunit& subunit, 
     335FunctionBlockFeature::FunctionBlockFeature( 
     336    AVC::Subunit& subunit, 
    339337    function_block_id_t id, 
    340338    ESpecialPurpose purpose, 
     
    353351} 
    354352 
    355 BeBoB::FunctionBlockFeature::FunctionBlockFeature( 
     353FunctionBlockFeature::FunctionBlockFeature( 
    356354    const FunctionBlockFeature& rhs ) 
    357355    : FunctionBlock( rhs ) 
     
    359357} 
    360358 
    361 BeBoB::FunctionBlockFeature::FunctionBlockFeature() 
     359FunctionBlockFeature::FunctionBlockFeature() 
    362360    : FunctionBlock() 
    363361{ 
    364362} 
    365363 
    366 BeBoB::FunctionBlockFeature::~FunctionBlockFeature() 
     364FunctionBlockFeature::~FunctionBlockFeature() 
    367365{ 
    368366} 
    369367 
    370368const char* 
    371 BeBoB::FunctionBlockFeature::getName() 
     369FunctionBlockFeature::getName() 
    372370{ 
    373371    return "Feature"; 
     
    375373 
    376374bool 
    377 BeBoB::FunctionBlockFeature::serializeChild( Glib::ustring basePath, 
     375FunctionBlockFeature::serializeChild( Glib::ustring basePath, 
    378376                                             Util::IOSerialize& ser ) const 
    379377{ 
     
    382380 
    383381bool 
    384 BeBoB::FunctionBlockFeature::deserializeChild( Glib::ustring basePath, 
     382FunctionBlockFeature::deserializeChild( Glib::ustring basePath, 
    385383                                               Util::IODeserialize& deser, 
    386                                                AvDevice& avDevice
     384                                               AvDevice& unit
    387385{ 
    388386    return true; 
     
    391389/////////////////////// 
    392390 
    393 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer( 
    394     AvDeviceSubunit& subunit, 
     391FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer( 
     392    AVC::Subunit& subunit, 
    395393    function_block_id_t id, 
    396394    ESpecialPurpose purpose, 
     
    409407} 
    410408 
    411 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer( 
     409FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer( 
    412410    const FunctionBlockEnhancedMixer& rhs ) 
    413411    : FunctionBlock( rhs ) 
     
    415413} 
    416414 
    417 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer() 
     415FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer() 
    418416    : FunctionBlock() 
    419417{ 
    420418} 
    421419 
    422 BeBoB::FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer() 
     420FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer() 
    423421{ 
    424422} 
    425423 
    426424const char* 
    427 BeBoB::FunctionBlockEnhancedMixer::getName() 
     425FunctionBlockEnhancedMixer::getName() 
    428426{ 
    429427    return "EnhancedMixer"; 
     
    431429 
    432430bool 
    433 BeBoB::FunctionBlockEnhancedMixer::serializeChild( Glib::ustring basePath, 
     431FunctionBlockEnhancedMixer::serializeChild( Glib::ustring basePath, 
    434432                                                   Util::IOSerialize& ser ) const 
    435433{ 
     
    438436 
    439437bool 
    440 BeBoB::FunctionBlockEnhancedMixer::deserializeChild( Glib::ustring basePath, 
     438FunctionBlockEnhancedMixer::deserializeChild( Glib::ustring basePath, 
    441439                                                     Util::IODeserialize& deser, 
    442                                                      AvDevice& avDevice
     440                                                     AvDevice& unit
    443441{ 
    444442    return true; 
     
    447445/////////////////////// 
    448446 
    449 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing( 
    450     AvDeviceSubunit& subunit, 
     447FunctionBlockProcessing::FunctionBlockProcessing( 
     448    AVC::Subunit& subunit, 
    451449    function_block_id_t id, 
    452450    ESpecialPurpose purpose, 
     
    465463} 
    466464 
    467 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing( 
     465FunctionBlockProcessing::FunctionBlockProcessing( 
    468466    const FunctionBlockProcessing& rhs ) 
    469467    : FunctionBlock( rhs ) 
     
    471469} 
    472470 
    473 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing() 
     471FunctionBlockProcessing::FunctionBlockProcessing() 
    474472    : FunctionBlock() 
    475473{ 
    476474} 
    477475 
    478 BeBoB::FunctionBlockProcessing::~FunctionBlockProcessing() 
     476FunctionBlockProcessing::~FunctionBlockProcessing() 
    479477{ 
    480478} 
    481479 
    482480const char* 
    483 BeBoB::FunctionBlockProcessing::getName() 
     481FunctionBlockProcessing::getName() 
    484482{ 
    485483    return "Dummy Processing"; 
     
    487485 
    488486bool 
    489 BeBoB::FunctionBlockProcessing::serializeChild( Glib::ustring basePath, 
     487FunctionBlockProcessing::serializeChild( Glib::ustring basePath, 
    490488                                                Util::IOSerialize& ser ) const 
    491489{ 
     
    494492 
    495493bool 
    496 BeBoB::FunctionBlockProcessing::deserializeChild( Glib::ustring basePath, 
     494FunctionBlockProcessing::deserializeChild( Glib::ustring basePath, 
    497495                                                  Util::IODeserialize& deser, 
    498                                                   AvDevice& avDevice
     496                                                  AvDevice& unit
    499497{ 
    500498    return true; 
     
    503501/////////////////////// 
    504502 
    505 BeBoB::FunctionBlockCodec::FunctionBlockCodec( 
    506     AvDeviceSubunit& subunit, 
     503FunctionBlockCodec::FunctionBlockCodec( 
     504    AVC::Subunit& subunit, 
    507505    function_block_id_t id, 
    508506    ESpecialPurpose purpose, 
     
    521519} 
    522520 
    523 BeBoB::FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs ) 
     521FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs ) 
    524522    : FunctionBlock( rhs ) 
    525523{ 
    526524} 
    527525 
    528 BeBoB::FunctionBlockCodec::FunctionBlockCodec() 
     526FunctionBlockCodec::FunctionBlockCodec() 
    529527    : FunctionBlock() 
    530528{ 
    531529} 
    532530 
    533 BeBoB::FunctionBlockCodec::~FunctionBlockCodec() 
     531FunctionBlockCodec::~FunctionBlockCodec() 
    534532{ 
    535533} 
    536534 
    537535const char* 
    538 BeBoB::FunctionBlockCodec::getName() 
     536FunctionBlockCodec::getName() 
    539537{ 
    540538    return "Dummy Codec"; 
     
    542540 
    543541bool 
    544 BeBoB::FunctionBlockCodec::serializeChild( Glib::ustring basePath, 
     542FunctionBlockCodec::serializeChild( Glib::ustring basePath, 
    545543                                           Util::IOSerialize& ser ) const 
    546544{ 
     
    549547 
    550548bool 
    551 BeBoB::FunctionBlockCodec::deserializeChild( Glib::ustring basePath, 
     549FunctionBlockCodec::deserializeChild( Glib::ustring basePath, 
    552550                                             Util::IODeserialize& deser, 
    553                                              AvDevice& avDevice ) 
    554 
    555     return true; 
    556 
     551                                             AvDevice& unit ) 
     552
     553    return true; 
     554
     555 
     556
  • branches/echoaudio/src/bebob/bebob_functionblock.h

    r503 r507  
    2828 
    2929#include "libavc/avc_definitions.h" 
     30// #include "libavc/general/avc_subunit.h" 
     31 
    3032#include "debugmodule/debugmodule.h" 
    3133 
     34namespace AVC { 
     35    class Subunit; 
     36} 
     37 
    3238namespace BeBoB { 
    33  
    34 class AvDeviceSubunit; 
    3539 
    3640class FunctionBlock { 
     
    5054    }; 
    5155 
    52     FunctionBlock( AvDeviceSubunit& subunit, 
    53            AVC::function_block_type_t type, 
     56    FunctionBlock( AVC::Subunit& subunit, 
     57                   AVC::function_block_type_t type, 
    5458                   AVC::function_block_type_t subtype, 
    5559                   AVC::function_block_id_t id, 
     
    7478    static FunctionBlock* deserialize( Glib::ustring basePath, 
    7579                       Util::IODeserialize& deser, 
    76                        AvDevice& avDevice
    77                                        AvDeviceSubunit& subunit); 
    78 protected: 
    79     bool discoverPlugs( AvPlug::EAvPlugDirection plugDirection, 
     80                       AVC::Unit& unit
     81                       AVC::Subunit& subunit); 
     82protected: 
     83    bool discoverPlugs( AVC::Plug::EPlugDirection plugDirection, 
    8084                        AVC::plug_id_t plugMaxId ); 
    8185 
    8286protected: 
    83     AvDeviceSubunit*      m_subunit; 
     87    AVC::Subunit*      m_subunit; 
    8488    AVC::function_block_type_t m_type; 
    8589    AVC::function_block_type_t m_subtype; 
     
    8993    AVC::no_of_output_plugs_t  m_nrOfOutputPlugs; 
    9094    int                   m_verbose; 
    91     AvPlugVector          m_plugs; 
     95    AVC::PlugVector          m_plugs; 
    9296 
    9397    DECLARE_DEBUG_MODULE; 
     
    102106{ 
    103107public: 
    104     FunctionBlockSelector(AvDeviceSubunit& subunit, 
     108    FunctionBlockSelector(AVC::Subunit& subunit, 
    105109                          AVC::function_block_id_t id, 
    106110                          ESpecialPurpose purpose, 
     
    127131{ 
    128132public: 
    129     FunctionBlockFeature(AvDeviceSubunit& subunit, 
     133    FunctionBlockFeature(AVC::Subunit& subunit, 
    130134                         AVC::function_block_id_t id, 
    131135                         ESpecialPurpose purpose, 
     
    169173{ 
    170174public: 
    171     FunctionBlockEnhancedMixer( AvDeviceSubunit& subunit, 
     175    FunctionBlockEnhancedMixer( AVC::Subunit& subunit, 
    172176                                AVC::function_block_id_t id, 
    173177                                ESpecialPurpose purpose, 
     
    194198{ 
    195199public: 
    196     FunctionBlockProcessing( AvDeviceSubunit& subunit, 
     200    FunctionBlockProcessing( AVC::Subunit& subunit, 
    197201                             AVC::function_block_id_t id, 
    198202                             ESpecialPurpose purpose, 
     
    219223{ 
    220224public: 
    221     FunctionBlockCodec(AvDeviceSubunit& subunit, 
     225    FunctionBlockCodec(AVC::Subunit& subunit, 
    222226                       AVC::function_block_id_t id, 
    223227                       ESpecialPurpose purpose, 
  • branches/echoaudio/src/libavc/general/avc_plug.cpp

    r503 r507  
    11/* 
     2 * Copyright (C)      2007 by Pieter Palmers 
    23 * Copyright (C) 2005-2007 by Daniel Wagner 
    34 * 
     
    2223 */ 
    2324 
    24 #include "bebob/bebob_avplug.h" 
    25 #include "bebob/bebob_avdevice.h" 
     25#include "avc_plug.h" 
     26#include "avc_unit.h" 
    2627#include "libieee1394/configrom.h" 
    2728 
    2829#include "libieee1394/ieee1394service.h" 
    29 #include "libavc/util/avc_serialize.h" 
     30#include "../util/avc_serialize.h" 
    3031 
    3132#include <sstream> 
    3233 
    33 using namespace AVC; 
    34  
    35 namespace BeBoB { 
    36  
    37 int AvPlug::m_globalIdCounter = 0; 
    38  
    39 IMPL_DEBUG_MODULE( AvPlug, AvPlug, DEBUG_LEVEL_NORMAL ); 
    40 IMPL_DEBUG_MODULE( AvPlugManager, AvPlugManager, DEBUG_LEVEL_NORMAL ); 
    41  
    42 AvPlug::AvPlug( Ieee1394Service& ieee1394Service, 
    43                 ConfigRom& configRom, 
    44                 AvPlugManager& plugManager, 
    45                 ESubunitType subunitType, 
    46                 subunit_id_t subunitId, 
    47                 function_block_type_t functionBlockType, 
    48                 function_block_id_t functionBlockId, 
    49                 EAvPlugAddressType plugAddressType, 
    50                 EAvPlugDirection plugDirection, 
    51                 plug_id_t plugId, 
    52                 int verboseLevel ) 
    53     : m_p1394Service( &ieee1394Service ) 
    54     , m_pConfigRom( &configRom ) 
    55     , m_subunitType( subunitType ) 
    56     , m_subunitId( subunitId ) 
     34namespace AVC { 
     35 
     36int Plug::m_globalIdCounter = 0; 
     37 
     38IMPL_DEBUG_MODULE( Plug, Plug, DEBUG_LEVEL_NORMAL ); 
     39IMPL_DEBUG_MODULE( PlugManager, PlugManager, DEBUG_LEVEL_NORMAL ); 
     40 
     41Plug::Plug( Unit* unit, 
     42            Subunit* subunit, 
     43            function_block_type_t functionBlockType, 
     44            function_block_id_t functionBlockId, 
     45            EPlugAddressType plugAddressType, 
     46            EPlugDirection plugDirection, 
     47            plug_id_t plugId ) 
     48    : m_unit(unit) 
     49    , m_subunit(subunit) 
    5750    , m_functionBlockType( functionBlockType ) 
    5851    , m_functionBlockId( functionBlockId ) 
     
    6255    , m_infoPlugType( eAPT_Unknown ) 
    6356    , m_nrOfChannels( 0 ) 
    64     , m_plugManager( &plugManager ) 
    65     , m_verboseLevel( verboseLevel ) 
    6657    , m_globalId( m_globalIdCounter++ ) 
    6758{ 
    68     setDebugLevel( m_verboseLevel ); 
    6959    debugOutput( DEBUG_LEVEL_VERBOSE, 
    7060                 "nodeId = %d, subunitType = %d, " 
     
    7262                 "functionBlockId = %d, addressType = %d, " 
    7363                 "direction = %d, id = %d\n", 
    74                  m_pConfigRom->getNodeId(), 
    75                  m_subunitType
    76                  m_subunitId
     64                 m_unit->getConfigRom().getNodeId(), 
     65                 getSubunitType()
     66                 getSubunitId()
    7767                 m_functionBlockType, 
    7868                 m_functionBlockId, 
     
    8272} 
    8373 
    84 AvPlug::AvPlug( const AvPlug& rhs ) 
    85     : m_p1394Service( rhs.m_p1394Service ) 
    86     , m_pConfigRom( rhs.m_pConfigRom ) 
    87     , m_subunitType( rhs.m_subunitType ) 
    88     , m_subunitId( rhs.m_subunitId ) 
     74Plug::Plug( const Plug& rhs ) 
     75    : m_unit ( rhs.m_unit ) 
     76    , m_subunit ( rhs.m_subunit ) 
    8977    , m_functionBlockType( rhs.m_functionBlockType ) 
    9078    , m_functionBlockId( rhs.m_functionBlockId ) 
     
    9785    , m_clusterInfos( rhs.m_clusterInfos ) 
    9886    , m_formatInfos( rhs.m_formatInfos ) 
    99     , m_plugManager( rhs.m_plugManager ) 
    100     , m_verboseLevel( rhs.m_verboseLevel ) 
    101 
    102     if ( m_verboseLevel ) { 
     87
     88    if ( getDebugLevel() ) { 
    10389        setDebugLevel( DEBUG_LEVEL_VERBOSE ); 
    10490     } 
    10591} 
    10692 
    107 AvPlug::AvPlug() 
    108     : m_p1394Service( 0 ) 
    109     , m_pConfigRom( 0 ) 
    110     , m_subunitType( eST_Reserved ) // a good value for unknown/undefined? 
    111     , m_subunitId( 0 ) 
     93Plug::Plug() 
     94    : m_unit( NULL ) 
     95    , m_subunit( NULL ) 
    11296    , m_functionBlockType( 0 ) 
    11397    , m_functionBlockId( 0 ) 
     
    117101    , m_infoPlugType( eAPT_Unknown ) 
    118102    , m_nrOfChannels( 0 ) 
    119     , m_plugManager( 0 ) 
    120     , m_verboseLevel( 0 ) 
    121103    , m_globalId( 0 ) 
    122104{ 
    123105} 
    124106 
    125 AvPlug::~AvPlug() 
    126 
    127     if ( m_plugManager ) { 
    128         m_plugManager->remPlug( *this ); 
    129     } 
    130 
    131  
    132 bool 
    133 AvPlug::discover() 
     107Plug::~Plug() 
     108
     109    m_unit->getPlugManager().remPlug( *this ); 
     110
     111 
     112ESubunitType 
     113Plug::getSubunitType() const 
     114
     115    return (m_subunit==NULL?eST_Unit:m_subunit->getSubunitType());  
     116
     117 
     118subunit_id_t  
     119Plug::getSubunitId() const 
     120
     121    return (m_subunit==NULL?eST_Unit:m_subunit->getSubunitId()); 
     122
     123 
     124/* 
     125bool 
     126Plug::discover() 
    134127{ 
    135128    if ( !discoverPlugType() ) { 
    136129        debugError( "discover: Could not discover plug type (%d,%d,%d,%d,%d)\n", 
    137                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     130                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    138131        return false; 
    139132    } 
     
    141134    if ( !discoverName() ) { 
    142135        debugError( "Could not discover name (%d,%d,%d,%d,%d)\n", 
    143                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     136                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    144137        return false; 
    145138    } 
     
    148141        debugError( "Could not discover number of channels " 
    149142                    "(%d,%d,%d,%d,%d)\n", 
    150                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     143                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    151144        return false; 
    152145    } 
     
    155148        debugError( "Could not discover channel positions " 
    156149                    "(%d,%d,%d,%d,%d)\n", 
    157                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     150                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    158151        return false; 
    159152    } 
     
    162155        debugError( "Could not discover channel name " 
    163156                    "(%d,%d,%d,%d,%d)\n", 
    164                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     157                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    165158        return false; 
    166159    } 
     
    169162        debugError( "Could not discover channel name " 
    170163                    "(%d,%d,%d,%d,%d)\n", 
    171                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     164                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    172165        return false; 
    173166    } 
     
    176169        debugError( "Could not discover stream format " 
    177170                    "(%d,%d,%d,%d,%d)\n", 
    178                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     171                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    179172        return false; 
    180173    } 
     
    183176        debugError( "Could not discover supported stream formats " 
    184177                    "(%d,%d,%d,%d,%d)\n", 
    185                     m_pConfigRom->getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
     178                    m_unit->getConfigRom().getNodeId(), m_subunitType, m_subunitId, m_direction, m_id ); 
    186179        return false; 
    187180    } 
    188181 
    189     return m_plugManager->addPlug( *this ); 
    190 } 
    191  
    192 bool 
    193 AvPlug::discoverConnections() 
     182    return unit->getPlugManager().addPlug( *this ); 
     183} 
     184 
     185bool 
     186Plug::discoverConnections() 
    194187{ 
    195188    return discoverConnectionsInput() && discoverConnectionsOutput(); 
    196189} 
    197  
    198 bool 
    199 AvPlug::inquireConnnection( AvPlug& plug ) 
     190*/ 
     191 
     192bool 
     193Plug::inquireConnnection( Plug& plug ) 
    200194{ 
    201195    SignalSourceCmd signalSourceCmd = setSrcPlugAddrToSignalCmd(); 
    202196    setDestPlugAddrToSignalCmd( signalSourceCmd, plug ); 
    203197    signalSourceCmd.setCommandType( AVCCommand::eCT_SpecificInquiry ); 
    204     signalSourceCmd.setVerbose( m_verboseLevel ); 
     198    signalSourceCmd.setVerbose( getDebugLevel() ); 
    205199 
    206200    if ( !signalSourceCmd.fire() ) { 
     
    223217 
    224218bool 
    225 AvPlug::setConnection( AvPlug& plug ) 
     219Plug::setConnection( Plug& plug ) 
    226220{ 
    227221    SignalSourceCmd signalSourceCmd = setSrcPlugAddrToSignalCmd(); 
    228222    setDestPlugAddrToSignalCmd( signalSourceCmd, plug ); 
    229223    signalSourceCmd.setCommandType( AVCCommand::eCT_Control ); 
    230     signalSourceCmd.setVerbose( m_verboseLevel ); 
     224    signalSourceCmd.setVerbose( getDebugLevel() ); 
    231225 
    232226    if ( !signalSourceCmd.fire() ) { 
     
    249243 
    250244int 
    251 AvPlug::getNrOfStreams() const 
     245Plug::getNrOfStreams() const 
    252246{ 
    253247    int nrOfChannels = 0; 
     
    263257 
    264258int 
    265 AvPlug::getNrOfChannels() const 
     259Plug::getNrOfChannels() const 
    266260{ 
    267261    return m_nrOfChannels; 
     
    269263 
    270264int 
    271 AvPlug::getSampleRate() const 
     265Plug::getSampleRate() const 
    272266{ 
    273267    return convertESamplingFrequency( static_cast<ESamplingFrequency>( m_samplingFrequency ) ); 
     
    275269 
    276270bool 
    277 AvPlug::discoverPlugType() 
    278 
    279     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    280     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    281         ExtendedPlugInfoInfoType::eIT_PlugType ); 
    282     extendedPlugInfoInfoType.initialize(); 
    283     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    284     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    285  
    286     if ( !extPlugInfoCmd.fire() ) { 
    287         debugError( "plug type command failed\n" ); 
    288         return false; 
    289     } 
    290  
    291     m_infoPlugType = eAPT_Unknown; 
    292  
    293     if ( extPlugInfoCmd.getResponse() == AVCCommand::eR_Implemented ) { 
    294  
    295         ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    296         if ( infoType 
    297              && infoType->m_plugType ) 
    298         { 
    299             plug_type_t plugType = infoType->m_plugType->m_plugType; 
    300  
    301             debugOutput( DEBUG_LEVEL_VERBOSE, 
    302                          "plug %d is of type %d (%s)\n", 
    303                          m_id, 
    304                          plugType, 
    305                          extendedPlugInfoPlugTypeToString( plugType ) ); 
    306             switch ( plugType ) { 
    307             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_IsoStream: 
    308                 m_infoPlugType = eAPT_IsoStream; 
    309                 break; 
    310             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_AsyncStream: 
    311                 m_infoPlugType = eAPT_AsyncStream; 
    312                 break; 
    313             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_Midi: 
    314                 m_infoPlugType = eAPT_Midi; 
    315                 break; 
    316             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_Sync: 
    317                 m_infoPlugType = eAPT_Sync; 
    318                 break; 
    319             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_Analog: 
    320                 m_infoPlugType = eAPT_Analog; 
    321                 break; 
    322             case ExtendedPlugInfoPlugTypeSpecificData::eEPIPT_Digital: 
    323                 m_infoPlugType = eAPT_Digital; 
    324                 break; 
    325             default: 
    326                 m_infoPlugType = eAPT_Unknown; 
    327  
    328             } 
    329         } 
    330     } else { 
    331         debugError( "Plug does not implement extended plug info plug " 
    332                     "type info command\n" ); 
    333         return false; 
    334     } 
    335  
    336    return true; 
    337 
    338  
    339 bool 
    340 AvPlug::discoverName() 
    341 
    342     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    343     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    344         ExtendedPlugInfoInfoType::eIT_PlugName ); 
    345     extendedPlugInfoInfoType.initialize(); 
    346     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    347     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    348  
    349     if ( !extPlugInfoCmd.fire() ) { 
    350         debugError( "name command failed\n" ); 
    351         return false; 
    352     } 
    353  
    354     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    355     if ( infoType 
    356          && infoType->m_plugName ) 
    357     { 
    358         std::string name = 
    359             infoType->m_plugName->m_name; 
    360  
    361         debugOutput( DEBUG_LEVEL_VERBOSE, 
    362                      "plug %d has name '%s'\n", 
    363                      m_id, 
    364                      name.c_str() ); 
    365  
    366         m_name = name; 
    367     } 
    368     return true; 
    369 
    370  
    371 bool 
    372 AvPlug::discoverNoOfChannels() 
    373 
    374     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    375     //extPlugInfoCmd.setVerbose( true ); 
    376     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    377         ExtendedPlugInfoInfoType::eIT_NoOfChannels ); 
    378     extendedPlugInfoInfoType.initialize(); 
    379     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    380     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    381  
    382     if ( !extPlugInfoCmd.fire() ) { 
    383         debugError( "number of channels command failed\n" ); 
    384         return false; 
    385     } 
    386  
    387     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    388     if ( infoType 
    389          && infoType->m_plugNrOfChns ) 
    390     { 
    391         nr_of_channels_t nrOfChannels 
    392             = infoType->m_plugNrOfChns->m_nrOfChannels; 
    393  
    394         debugOutput( DEBUG_LEVEL_VERBOSE, 
    395                      "plug %d has %d channels\n", 
    396                      m_id, 
    397                      nrOfChannels ); 
    398  
    399         m_nrOfChannels = nrOfChannels; 
    400     } 
    401     return true; 
    402 
    403  
    404 bool 
    405 AvPlug::discoverChannelPosition() 
    406 
    407     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    408     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    409         ExtendedPlugInfoInfoType::eIT_ChannelPosition ); 
    410     extendedPlugInfoInfoType.initialize(); 
    411     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    412     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    413  
    414     if ( !extPlugInfoCmd.fire() ) { 
    415         debugError( "channel position command failed\n" ); 
    416         return false; 
    417     } 
    418  
    419     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    420     if ( infoType 
    421          && infoType->m_plugChannelPosition ) 
    422     { 
    423         if ( !copyClusterInfo( *( infoType->m_plugChannelPosition ) ) ) { 
    424             debugError( "Could not copy channel position " 
    425                         "information\n" ); 
    426             return false; 
    427         } 
    428  
    429         debugOutput( DEBUG_LEVEL_VERBOSE, 
    430                      "plug %d: channel position information " 
    431                      "retrieved\n", 
    432                      m_id ); 
    433  
    434         debugOutputClusterInfos( DEBUG_LEVEL_VERBOSE ); 
    435     } 
    436  
    437     return true; 
    438 
    439  
    440 bool 
    441 AvPlug::discoverChannelName() 
    442 
    443     for ( ClusterInfoVector::iterator clit = m_clusterInfos.begin(); 
    444           clit != m_clusterInfos.end(); 
    445           ++clit ) 
    446     { 
    447         ClusterInfo* clitInfo = &*clit; 
    448  
    449         for ( ChannelInfoVector::iterator pit =  clitInfo->m_channelInfos.begin(); 
    450               pit != clitInfo->m_channelInfos.end(); 
    451               ++pit ) 
    452         { 
    453             ChannelInfo* channelInfo = &*pit; 
    454  
    455             ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    456             ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    457                 ExtendedPlugInfoInfoType::eIT_ChannelName ); 
    458             extendedPlugInfoInfoType.initialize(); 
    459             extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    460             extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    461  
    462             ExtendedPlugInfoInfoType* infoType = 
    463                 extPlugInfoCmd.getInfoType(); 
    464             if ( infoType ) { 
    465                 infoType->m_plugChannelName->m_streamPosition = 
    466                     channelInfo->m_streamPosition; 
    467             } 
    468             if ( !extPlugInfoCmd.fire() ) { 
    469                 debugError( "channel name command failed\n" ); 
    470                 return false; 
    471             } 
    472             infoType = extPlugInfoCmd.getInfoType(); 
    473             if ( infoType 
    474                  && infoType->m_plugChannelName ) 
    475             { 
    476                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    477                              "plug %d stream " 
    478                              "position %d: channel name = %s\n", 
    479                              m_id, 
    480                              channelInfo->m_streamPosition, 
    481                              infoType->m_plugChannelName->m_plugChannelName.c_str() ); 
    482                 channelInfo->m_name = 
    483                     infoType->m_plugChannelName->m_plugChannelName; 
    484             } 
    485  
    486         } 
    487     } 
    488  
    489     return true; 
    490 
    491  
    492 bool 
    493 AvPlug::discoverClusterInfo() 
    494 
    495     if ( m_infoPlugType == eAPT_Sync ) 
    496     { 
    497         // If the plug is of type sync it is either a normal 2 channel 
    498         // stream (not compound stream) or it is a compound stream 
    499         // with exactly one cluster. This depends on the 
    500         // extended stream format command version which is used. 
    501         // We are not interested in this plug so we skip it. 
    502         debugOutput( DEBUG_LEVEL_VERBOSE, 
    503                      "%s plug %d is of type sync -> skip\n", 
    504                      getName(), 
    505                      m_id ); 
    506         return true; 
    507     } 
    508  
    509     for ( ClusterInfoVector::iterator clit = m_clusterInfos.begin(); 
    510           clit != m_clusterInfos.end(); 
    511           ++clit ) 
    512     { 
    513         ClusterInfo* clusterInfo = &*clit; 
    514  
    515         ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    516         ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    517             ExtendedPlugInfoInfoType::eIT_ClusterInfo ); 
    518         extendedPlugInfoInfoType.initialize(); 
    519         extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    520         extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    521  
    522         extPlugInfoCmd.getInfoType()->m_plugClusterInfo->m_clusterIndex = 
    523             clusterInfo->m_index; 
    524  
    525         if ( !extPlugInfoCmd.fire() ) { 
    526             debugError( "cluster info command failed\n" ); 
    527             return false; 
    528         } 
    529  
    530         ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    531         if ( infoType 
    532              && infoType->m_plugClusterInfo ) 
    533         { 
    534             debugOutput( DEBUG_LEVEL_VERBOSE, 
    535                          "%s plug %d: cluster index = %d, " 
    536                          "portType %s, cluster name = %s\n", 
    537                          getName(), 
    538                          m_id, 
    539                          infoType->m_plugClusterInfo->m_clusterIndex, 
    540                          extendedPlugInfoClusterInfoPortTypeToString( 
    541                              infoType->m_plugClusterInfo->m_portType ), 
    542                          infoType->m_plugClusterInfo->m_clusterName.c_str() ); 
    543  
    544             clusterInfo->m_portType = infoType->m_plugClusterInfo->m_portType; 
    545             clusterInfo->m_name = infoType->m_plugClusterInfo->m_clusterName; 
    546         } 
    547     } 
    548  
    549     return true; 
    550 
    551  
    552 bool 
    553 AvPlug::discoverStreamFormat() 
    554 
    555     ExtendedStreamFormatCmd extStreamFormatCmd = 
    556         setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
    557     extStreamFormatCmd.setVerbose( m_verboseLevel ); 
    558  
    559     if ( !extStreamFormatCmd.fire() ) { 
    560         debugError( "stream format command failed\n" ); 
    561         return false; 
    562     } 
    563  
    564     if ( ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NoStreamFormat ) 
    565          || ( extStreamFormatCmd.getStatus() ==  ExtendedStreamFormatCmd::eS_NotUsed ) ) 
    566     { 
    567         debugOutput( DEBUG_LEVEL_VERBOSE, 
    568                      "No stream format information available\n" ); 
    569         return true; 
    570     } 
    571  
    572     if ( !extStreamFormatCmd.getFormatInformation() ) { 
    573         debugWarning( "No stream format information for plug found -> skip\n" ); 
    574         return true; 
    575     } 
    576  
    577     if ( extStreamFormatCmd.getFormatInformation()->m_root 
    578            != FormatInformation::eFHR_AudioMusic  ) 
    579     { 
    580         debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 
    581         return true; 
    582     } 
    583  
    584     FormatInformation* formatInfo = 
    585         extStreamFormatCmd.getFormatInformation(); 
    586     FormatInformationStreamsCompound* compoundStream 
    587         = dynamic_cast< FormatInformationStreamsCompound* > ( 
    588             formatInfo->m_streams ); 
    589     if ( compoundStream ) { 
    590         m_samplingFrequency = 
    591             compoundStream->m_samplingFrequency; 
    592         debugOutput( DEBUG_LEVEL_VERBOSE, 
    593                      "%s plug %d uses " 
    594                      "sampling frequency %d, nr of stream infos = %d\n", 
    595                      getName(), 
    596                      m_id, 
    597                      m_samplingFrequency, 
    598                      compoundStream->m_numberOfStreamFormatInfos ); 
    599  
    600         for ( int i = 1; 
    601               i <= compoundStream->m_numberOfStreamFormatInfos; 
    602               ++i ) 
    603         { 
    604             ClusterInfo* clusterInfo = 
    605                 const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 
    606  
    607             if ( !clusterInfo ) { 
    608                 debugError( "No matching cluster " 
    609                             "info found for index %d\n",  i ); 
    610                     return false; 
    611             } 
    612             StreamFormatInfo* streamFormatInfo = 
    613                 compoundStream->m_streamFormatInfos[ i - 1 ]; 
    614  
    615             debugOutput( DEBUG_LEVEL_VERBOSE, 
    616                          "number of channels = %d, stream format = %d\n", 
    617                          streamFormatInfo->m_numberOfChannels, 
    618                          streamFormatInfo->m_streamFormat ); 
    619  
    620             int nrOfChannels = clusterInfo->m_nrOfChannels; 
    621             if ( streamFormatInfo->m_streamFormat == 
    622                  FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 
    623             { 
    624                 // 8 logical midi channels fit into 1 channel 
    625                 nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 
    626             } 
    627             // sanity check 
    628             if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 
    629             { 
    630                 debugWarning( "Number of channels " 
    631                               "mismatch: '%s' plug discovering reported " 
    632                               "%d channels for cluster '%s', while stream " 
    633                               "format reported %d\n", 
    634                               getName(), 
    635                               nrOfChannels, 
    636                               clusterInfo->m_name.c_str(), 
    637                               streamFormatInfo->m_numberOfChannels); 
    638             } 
    639             clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 
    640  
    641             debugOutput( DEBUG_LEVEL_VERBOSE, 
    642                          "%s plug %d cluster info %d ('%s'): " 
    643                          "stream format %d\n", 
    644                          getName(), 
    645                          m_id, 
    646                          i, 
    647                          clusterInfo->m_name.c_str(), 
    648                          clusterInfo->m_streamFormat ); 
    649         } 
    650     } 
    651  
    652     FormatInformationStreamsSync* syncStream 
    653         = dynamic_cast< FormatInformationStreamsSync* > ( 
    654             formatInfo->m_streams ); 
    655     if ( syncStream ) { 
    656         m_samplingFrequency = 
    657             syncStream->m_samplingFrequency; 
    658         debugOutput( DEBUG_LEVEL_VERBOSE, 
    659                      "%s plug %d is sync stream with sampling frequency %d\n", 
    660                      getName(), 
    661                      m_id, 
    662                      m_samplingFrequency ); 
    663     } 
    664  
    665  
    666     if ( !compoundStream && !syncStream ) 
    667     { 
    668         debugError( "Unsupported stream format\n" ); 
    669         return false; 
    670     } 
    671  
    672     return true; 
    673 
    674  
    675 bool 
    676 AvPlug::discoverSupportedStreamFormats() 
    677 
    678     ExtendedStreamFormatCmd extStreamFormatCmd = 
    679         setPlugAddrToStreamFormatCmd( 
    680             ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 
    681     extStreamFormatCmd.setVerbose( m_verboseLevel ); 
    682  
    683     int i = 0; 
    684     bool cmdSuccess = false; 
    685  
    686     do { 
    687         extStreamFormatCmd.setIndexInStreamFormat( i ); 
    688         extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
    689         cmdSuccess = extStreamFormatCmd.fire(); 
    690         if ( cmdSuccess 
    691              && ( extStreamFormatCmd.getResponse() 
    692                   == AVCCommand::eR_Implemented ) ) 
    693         { 
    694             FormatInfo formatInfo; 
    695             formatInfo.m_index = i; 
    696             bool formatInfoIsValid = true; 
    697  
    698             FormatInformationStreamsSync* syncStream 
    699                 = dynamic_cast< FormatInformationStreamsSync* > 
    700                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
    701             if ( syncStream ) { 
    702                 formatInfo.m_samplingFrequency = 
    703                     syncStream->m_samplingFrequency; 
    704                 formatInfo.m_isSyncStream = true ; 
    705             } 
    706  
    707             FormatInformationStreamsCompound* compoundStream 
    708                 = dynamic_cast< FormatInformationStreamsCompound* > 
    709                 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 
    710             if ( compoundStream ) { 
    711                 formatInfo.m_samplingFrequency = 
    712                     compoundStream->m_samplingFrequency; 
    713                 formatInfo.m_isSyncStream = false; 
    714                 for ( int j = 0; 
    715                       j < compoundStream->m_numberOfStreamFormatInfos; 
    716                       ++j ) 
    717                 { 
    718                     switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 
    719                     case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 
    720                         formatInfo.m_audioChannels += 
    721                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    722                         break; 
    723                     case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 
    724                         formatInfo.m_audioChannels += 
    725                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    726                         break; 
    727                     case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 
    728                         formatInfo.m_midiChannels += 
    729                             compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 
    730                         break; 
    731                     default: 
    732                         formatInfoIsValid = false; 
    733                         debugWarning("unknown stream format (0x%02x) for channel " 
    734                                       "(%d)\n", 
    735                                      compoundStream->m_streamFormatInfos[j]->m_streamFormat, 
    736                                      j ); 
    737                     } 
    738                 } 
    739             } 
    740  
    741             if ( formatInfoIsValid ) { 
    742                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    743                              "[%s:%d] formatInfo[%d].m_samplingFrequency " 
    744                              "= %d\n", 
    745                              getName(), m_id, 
    746                              i, formatInfo.m_samplingFrequency ); 
    747                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    748                              "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 
    749                              getName(), m_id, 
    750                              i, formatInfo.m_isSyncStream ); 
    751                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    752                              "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 
    753                              getName(), m_id, 
    754                              i, formatInfo.m_audioChannels ); 
    755                 debugOutput( DEBUG_LEVEL_VERBOSE, 
    756                              "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 
    757                              getName(), m_id, 
    758                              i, formatInfo.m_midiChannels ); 
    759                 m_formatInfos.push_back( formatInfo ); 
    760             } 
    761         } 
    762  
    763         ++i; 
    764     } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 
    765                               == ExtendedStreamFormatCmd::eR_Implemented ) ); 
    766  
    767     return true; 
    768 
    769  
    770  
    771 bool 
    772 AvPlug::discoverConnectionsInput() 
    773 
    774     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    775     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    776         ExtendedPlugInfoInfoType::eIT_PlugInput ); 
    777     extendedPlugInfoInfoType.initialize(); 
    778     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    779     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    780  
    781     if ( !extPlugInfoCmd.fire() ) { 
    782         debugError( "plug type command failed\n" ); 
    783         return false; 
    784     } 
    785  
    786     if ( extPlugInfoCmd.getResponse() == AVCCommand::eR_Rejected ) { 
    787         // Plugs does not like to be asked about connections 
    788         debugOutput( DEBUG_LEVEL_VERBOSE, "Plug '%s' rejects " 
    789                      "connections command\n", 
    790                      getName() ); 
    791         return true; 
    792     } 
    793  
    794     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    795     if ( infoType 
    796          && infoType->m_plugInput ) 
    797     { 
    798         PlugAddressSpecificData* plugAddress 
    799             = infoType->m_plugInput->m_plugAddress; 
    800  
    801         if ( plugAddress->m_addressMode == 
    802              PlugAddressSpecificData::ePAM_Undefined ) 
    803         { 
    804             // This plug has no input connection 
    805             return true; 
    806         } 
    807  
    808         if ( !discoverConnectionsFromSpecificData( eAPD_Input, 
    809                                                    plugAddress, 
    810                                                    m_inputConnections ) ) 
    811         { 
    812             debugWarning( "Could not discover connnections for plug '%s'\n", 
    813                           getName() ); 
    814         } 
    815     } else { 
    816         debugError( "no valid info type for plug '%s'\n", getName() ); 
    817         return false; 
    818     } 
    819  
    820     return true; 
    821 
    822  
    823 bool 
    824 AvPlug::discoverConnectionsOutput() 
    825 
    826     ExtendedPlugInfoCmd extPlugInfoCmd = setPlugAddrToPlugInfoCmd(); 
    827     ExtendedPlugInfoInfoType extendedPlugInfoInfoType( 
    828         ExtendedPlugInfoInfoType::eIT_PlugOutput ); 
    829     extendedPlugInfoInfoType.initialize(); 
    830     extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); 
    831     extPlugInfoCmd.setVerbose( m_verboseLevel ); 
    832  
    833     if ( !extPlugInfoCmd.fire() ) { 
    834         debugError( "plug type command failed\n" ); 
    835         return false; 
    836     } 
    837  
    838     if ( extPlugInfoCmd.getResponse() == AVCCommand::eR_Rejected ) { 
    839         // Plugs does not like to be asked about connections 
    840         debugOutput( DEBUG_LEVEL_VERBOSE, "Plug '%s' rejects " 
    841                      "connections command\n", 
    842                      getName() ); 
    843         return true; 
    844     } 
    845  
    846     ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); 
    847     if ( infoType 
    848          && infoType->m_plugOutput ) 
    849     { 
    850         if ( infoType->m_plugOutput->m_nrOfOutputPlugs 
    851              != infoType->m_plugOutput->m_outputPlugAddresses.size() ) 
    852         { 
    853             debugError( "number of output plugs (%d) disagree with " 
    854                         "number of elements in plug address vector (%d)\n", 
    855                         infoType->m_plugOutput->m_nrOfOutputPlugs, 
    856                         infoType->m_plugOutput->m_outputPlugAddresses.size()); 
    857         } 
    858  
    859         if ( infoType->m_plugOutput->m_nrOfOutputPlugs == 0 ) { 
    860             // This plug has no output connections 
    861             return true; 
    862         } 
    863  
    864         for ( unsigned int i = 0; 
    865               i < infoType->m_plugOutput->m_outputPlugAddresses.size(); 
    866               ++i ) 
    867         { 
    868             PlugAddressSpecificData* plugAddress 
    869                 = infoType->m_plugOutput->m_outputPlugAddresses[i]; 
    870  
    871             if ( !discoverConnectionsFromSpecificData( eAPD_Output, 
    872                                                        plugAddress, 
    873                                                        m_outputConnections ) ) 
    874             { 
    875                 debugWarning( "Could not discover connnections for " 
    876                               "plug '%s'\n", getName() ); 
    877             } 
    878         } 
    879     } else { 
    880         debugError( "no valid info type for plug '%s'\n", getName() ); 
    881         return false; 
    882     } 
    883  
    884     return true; 
    885 
    886  
    887 bool 
    888 AvPlug::discoverConnectionsFromSpecificData( 
    889     EAvPlugDirection discoverDirection, 
     271Plug::discoverConnectionsFromSpecificData( 
     272    EPlugDirection discoverDirection, 
    890273    PlugAddressSpecificData* plugAddress, 
    891     AvPlugVector& connections ) 
     274    PlugVector& connections ) 
    892275{ 
    893276    UnitPlugSpecificDataPlugAddress* pUnitPlugAddress = 
     
    904287        ( plugAddress->m_plugAddressData ); 
    905288 
    906     AvPlug* plug = getPlugDefinedBySpecificData( 
     289    Plug* plug = getPlugDefinedBySpecificData( 
    907290        pUnitPlugAddress, 
    908291        pSubunitPlugAddress, 
     
    928311 
    929312bool 
    930 AvPlug::addPlugConnection( AvPlugVector& connections, 
    931                            AvPlug& plug ) 
    932  
    933 { 
    934     for ( AvPlugVector::iterator it = connections.begin(); 
     313Plug::addPlugConnection( PlugVector& connections, 
     314                           Plug& plug ) 
     315 
     316{ 
     317    for ( PlugVector::iterator it = connections.begin(); 
    935318          it != connections.end(); 
    936319          ++it ) 
    937320    { 
    938         AvPlug* cPlug = *it; 
     321        Plug* cPlug = *it; 
    939322        if ( cPlug == &plug ) { 
    940323            debugOutput( DEBUG_LEVEL_VERBOSE, 
     
    949332} 
    950333 
    951 ExtendedPlugInfoCmd 
    952 AvPlug::setPlugAddrToPlugInfoCmd() 
    953 { 
    954     ExtendedPlugInfoCmd extPlugInfoCmd( *m_p1394Service ); 
    955  
    956     switch( m_subunitType ) { 
    957     case eST_Unit: 
    958         { 
    959             UnitPlugAddress::EPlugType ePlugType = 
    960                 UnitPlugAddress::ePT_Unknown; 
    961             switch ( m_addressType ) { 
    962                 case eAPA_PCR: 
    963                     ePlugType = UnitPlugAddress::ePT_PCR; 
    964                     break; 
    965                 case eAPA_ExternalPlug: 
    966                     ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
    967                     break; 
    968                 case eAPA_AsynchronousPlug: 
    969                     ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
    970                     break; 
    971                 default: 
    972                     ePlugType = UnitPlugAddress::ePT_Unknown; 
    973             } 
    974             UnitPlugAddress unitPlugAddress( ePlugType, 
    975                                              m_id ); 
    976             extPlugInfoCmd.setPlugAddress( 
    977                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    978                              PlugAddress::ePAM_Unit, 
    979                              unitPlugAddress ) ); 
    980         } 
    981         break; 
    982     case eST_Music: 
    983     case eST_Audio: 
    984         { 
    985             switch( m_addressType ) { 
    986             case eAPA_SubunitPlug: 
    987             { 
    988                 SubunitPlugAddress subunitPlugAddress( m_id ); 
    989                 extPlugInfoCmd.setPlugAddress( 
    990                     PlugAddress( 
    991                         convertPlugDirection( getPlugDirection() ), 
    992                         PlugAddress::ePAM_Subunit, 
    993                         subunitPlugAddress ) ); 
    994             } 
    995             break; 
    996             case eAPA_FunctionBlockPlug: 
    997             { 
    998                 FunctionBlockPlugAddress functionBlockPlugAddress( 
    999                     m_functionBlockType, 
    1000                     m_functionBlockId, 
    1001                     m_id ); 
    1002                 extPlugInfoCmd.setPlugAddress( 
    1003                     PlugAddress( 
    1004                         convertPlugDirection( getPlugDirection() ), 
    1005                         PlugAddress::ePAM_FunctionBlock, 
    1006                         functionBlockPlugAddress ) ); 
    1007             } 
    1008             break; 
    1009             default: 
    1010                 extPlugInfoCmd.setPlugAddress(PlugAddress()); 
    1011             } 
    1012         } 
    1013         break; 
    1014     default: 
    1015         debugError( "Unknown subunit type\n" ); 
    1016     } 
    1017  
    1018     extPlugInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    1019     extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    1020     extPlugInfoCmd.setSubunitId( m_subunitId ); 
    1021     extPlugInfoCmd.setSubunitType( m_subunitType ); 
    1022  
    1023     return extPlugInfoCmd; 
    1024 } 
    1025  
    1026 ExtendedStreamFormatCmd 
    1027 AvPlug::setPlugAddrToStreamFormatCmd( 
    1028     ExtendedStreamFormatCmd::ESubFunction subFunction) 
    1029 { 
    1030     ExtendedStreamFormatCmd extStreamFormatInfoCmd( 
    1031         *m_p1394Service, 
    1032         subFunction ); 
    1033     switch( m_subunitType ) { 
    1034     case eST_Unit: 
    1035     { 
    1036             UnitPlugAddress::EPlugType ePlugType = 
    1037                 UnitPlugAddress::ePT_Unknown; 
    1038             switch ( m_addressType ) { 
    1039                 case eAPA_PCR: 
    1040                     ePlugType = UnitPlugAddress::ePT_PCR; 
    1041                     break; 
    1042                 case eAPA_ExternalPlug: 
    1043                     ePlugType = UnitPlugAddress::ePT_ExternalPlug; 
    1044                     break; 
    1045                 case eAPA_AsynchronousPlug: 
    1046                     ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 
    1047                     break; 
    1048                 default: 
    1049                     ePlugType = UnitPlugAddress::ePT_Unknown; 
    1050             } 
    1051         UnitPlugAddress unitPlugAddress( ePlugType, 
    1052                                          m_id ); 
    1053         extStreamFormatInfoCmd.setPlugAddress( 
    1054             PlugAddress( convertPlugDirection( getPlugDirection() ), 
    1055                          PlugAddress::ePAM_Unit, 
    1056                          unitPlugAddress ) ); 
    1057         } 
    1058         break; 
    1059     case eST_Music: 
    1060     case eST_Audio: 
    1061     { 
    1062         switch( m_addressType ) { 
    1063         case eAPA_SubunitPlug: 
    1064         { 
    1065             SubunitPlugAddress subunitPlugAddress( m_id ); 
    1066             extStreamFormatInfoCmd.setPlugAddress( 
    1067                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    1068                              PlugAddress::ePAM_Subunit, 
    1069                              subunitPlugAddress ) ); 
    1070         } 
    1071         break; 
    1072         case eAPA_FunctionBlockPlug: 
    1073         { 
    1074             FunctionBlockPlugAddress functionBlockPlugAddress( 
    1075                 m_functionBlockType, 
    1076                 m_functionBlockId, 
    1077                 m_id ); 
    1078             extStreamFormatInfoCmd.setPlugAddress( 
    1079                 PlugAddress( convertPlugDirection( getPlugDirection() ), 
    1080                              PlugAddress::ePAM_FunctionBlock, 
    1081                              functionBlockPlugAddress ) ); 
    1082         } 
    1083         break; 
    1084         default: 
    1085             extStreamFormatInfoCmd.setPlugAddress(PlugAddress()); 
    1086         } 
    1087     } 
    1088     break; 
    1089     default: 
    1090         debugError( "Unknown subunit type\n" ); 
    1091     } 
    1092  
    1093     extStreamFormatInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    1094     extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    1095     extStreamFormatInfoCmd.setSubunitId( m_subunitId ); 
    1096     extStreamFormatInfoCmd.setSubunitType( m_subunitType ); 
    1097  
    1098     return extStreamFormatInfoCmd; 
    1099 } 
    1100  
    1101334SignalSourceCmd 
    1102 AvPlug::setSrcPlugAddrToSignalCmd() 
    1103 { 
    1104     SignalSourceCmd signalSourceCmd( *m_p1394Service ); 
    1105  
    1106     switch( m_subunitType ) { 
     335Plug::setSrcPlugAddrToSignalCmd() 
     336{ 
     337    SignalSourceCmd signalSourceCmd( m_unit->get1394Service() ); 
     338 
     339    switch( getSubunitType() ) { 
    1107340    case eST_Unit: 
    1108341    { 
     
    1120353    { 
    1121354        SignalSubunitAddress signalSubunitAddr; 
    1122         signalSubunitAddr.m_subunitType = m_subunitType
    1123         signalSubunitAddr.m_subunitId = m_subunitId
     355        signalSubunitAddr.m_subunitType = getSubunitType()
     356        signalSubunitAddr.m_subunitId = getSubunitId()
    1124357        signalSubunitAddr.m_plugId = m_id; 
    1125358        signalSourceCmd.setSignalSource( signalSubunitAddr ); 
     
    1130363    } 
    1131364 
    1132     signalSourceCmd.setNodeId( m_pConfigRom->getNodeId() ); 
     365    signalSourceCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
    1133366    signalSourceCmd.setSubunitType( eST_Unit  ); 
    1134367    signalSourceCmd.setSubunitId( 0xff ); 
     
    1138371 
    1139372void 
    1140 AvPlug::setDestPlugAddrToSignalCmd(SignalSourceCmd& signalSourceCmd, 
    1141                                    AvPlug& plug) 
    1142 { 
    1143     switch( plug.m_subunitType ) { 
     373Plug::setDestPlugAddrToSignalCmd(SignalSourceCmd& signalSourceCmd, 
     374                                   Plug& plug) 
     375{ 
     376    switch( plug.getSubunitType() ) { 
    1144377    case eST_Unit: 
    1145378    { 
     
    1157390    { 
    1158391        SignalSubunitAddress signalSubunitAddr; 
    1159         signalSubunitAddr.m_subunitType = plug.m_subunitType
    1160         signalSubunitAddr.m_subunitId = plug.m_subunitId
     392        signalSubunitAddr.m_subunitType = plug.getSubunitType()
     393        signalSubunitAddr.m_subunitId = plug.getSubunitId()
    1161394        signalSubunitAddr.m_plugId = plug.m_id; 
    1162395        signalSourceCmd.setSignalDestination( signalSubunitAddr ); 
     
    1170403 
    1171404bool 
    1172 AvPlug::copyClusterInfo(ExtendedPlugInfoPlugChannelPositionSpecificData& 
     405Plug::copyClusterInfo(ExtendedPlugInfoPlugChannelPositionSpecificData& 
    1173406                        channelPositionData ) 
    1174407{ 
     
    1210443 
    1211444void 
    1212 AvPlug::debugOutputClusterInfos( int debugLevel ) 
     445Plug::debugOutputClusterInfos( int debugLevel ) 
    1213446{ 
    1214447    for ( ClusterInfoVector::const_iterator it = m_clusterInfos.begin(); 
     
    1238471} 
    1239472 
    1240 const AvPlug::ClusterInfo* 
    1241 AvPlug::getClusterInfoByIndex(int index) const 
    1242 { 
    1243     for ( AvPlug::ClusterInfoVector::const_iterator clit = 
     473const Plug::ClusterInfo* 
     474Plug::getClusterInfoByIndex(int index) const 
     475{ 
     476    for ( Plug::ClusterInfoVector::const_iterator clit = 
    1244477              m_clusterInfos.begin(); 
    1245478          clit != m_clusterInfos.end(); 
     
    1255488 
    1256489PlugAddress::EPlugDirection 
    1257 AvPlug::convertPlugDirection( EAvPlugDirection direction ) 
     490Plug::convertPlugDirection( EPlugDirection direction ) 
    1258491{ 
    1259492    PlugAddress::EPlugDirection dir; 
    1260493    switch ( direction ) { 
    1261     case AvPlug::eAPD_Input: 
     494    case Plug::eAPD_Input: 
    1262495        dir = PlugAddress::ePD_Input; 
    1263496        break; 
    1264     case AvPlug::eAPD_Output: 
     497    case Plug::eAPD_Output: 
    1265498        dir = PlugAddress::ePD_Output; 
    1266499        break; 
     
    1272505 
    1273506void 
    1274 AvPlug::showPlug() const 
     507Plug::showPlug() const 
    1275508{ 
    1276509    debugOutput( DEBUG_LEVEL_VERBOSE, "\tName               = %s\n", 
     
    1297530 
    1298531 
    1299 AvPlug* 
    1300 AvPlug::getPlugDefinedBySpecificData( 
     532Plug* 
     533Plug::getPlugDefinedBySpecificData( 
    1301534    UnitPlugSpecificDataPlugAddress* pUnitPlugAddress, 
    1302535    SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress, 
     
    1307540    function_block_type_t functionBlockType = 0xff; 
    1308541    function_block_id_t   functionBlockId   = 0xff; 
    1309     EAvPlugAddressType    addressType       = eAPA_Undefined; 
    1310     EAvPlugDirection      direction         = eAPD_Unknown; 
     542    EPlugAddressType    addressType       = eAPA_Undefined; 
     543    EPlugDirection      direction         = eAPD_Unknown; 
    1311544    plug_id_t             plugId            = 0xff; 
    1312545 
     
    1413646        static_cast<ESubunitType>( subunitType ); 
    1414647 
    1415     return m_plugManager->getPlug( 
     648    return m_unit->getPlugManager().getPlug( 
    1416649        enumSubunitType, 
    1417650        subunitId, 
     
    1423656} 
    1424657 
    1425 AvPlug::EAvPlugDirection 
    1426 AvPlug::toggleDirection( EAvPlugDirection direction ) const 
    1427 { 
    1428     EAvPlugDirection newDirection; 
     658Plug::EPlugDirection 
     659Plug::toggleDirection( EPlugDirection direction ) const 
     660{ 
     661    EPlugDirection newDirection; 
    1429662    switch ( direction ) { 
    1430663    case eAPD_Output: 
     
    1442675 
    1443676bool 
    1444 AvPlug::serializeChannelInfos( Glib::ustring basePath, 
     677Plug::serializeChannelInfos( Glib::ustring basePath, 
    1445678                               Util::IOSerialize& ser, 
    1446679                               const ClusterInfo& clusterInfo ) const 
     
    1465698 
    1466699bool 
    1467 AvPlug::deserializeChannelInfos( Glib::ustring basePath, 
     700Plug::deserializeChannelInfos( Glib::ustring basePath, 
    1468701                                 Util::IODeserialize& deser, 
    1469702                                 ClusterInfo& clusterInfo ) 
     
    1501734 
    1502735bool 
    1503 AvPlug::serializeClusterInfos( Glib::ustring basePath, 
     736Plug::serializeClusterInfos( Glib::ustring basePath, 
    1504737                               Util::IOSerialize& ser ) const 
    1505738{ 
     
    1527760 
    1528761bool 
    1529 AvPlug::deserializeClusterInfos( Glib::ustring basePath, 
     762Plug::deserializeClusterInfos( Glib::ustring basePath, 
    1530763                                 Util::IODeserialize& deser ) 
    1531764{ 
     
    1565798 
    1566799bool 
    1567 AvPlug::serializeFormatInfos( Glib::ustring basePath, 
     800Plug::serializeFormatInfos( Glib::ustring basePath, 
    1568801                              Util::IOSerialize& ser ) const 
    1569802{ 
     
    1588821 
    1589822bool 
    1590 AvPlug::deserializeFormatInfos( Glib::ustring basePath, 
     823Plug::deserializeFormatInfos( Glib::ustring basePath, 
    1591824                                Util::IODeserialize& deser ) 
    1592825{ 
     
    1625858 
    1626859bool 
    1627 AvPlug::serializeAvPlugVector( Glib::ustring basePath, 
     860Plug::serializePlugVector( Glib::ustring basePath, 
    1628861                               Util::IOSerialize& ser, 
    1629                                const AvPlugVector& vec) const 
     862                               const PlugVector& vec) const 
    1630863{ 
    1631864    bool result = true; 
    1632865    int i = 0; 
    1633     for ( AvPlugVector::const_iterator it = vec.begin(); 
     866    for ( PlugVector::const_iterator it = vec.begin(); 
    1634867          it != vec.end(); 
    1635868          ++it ) 
    1636869    { 
    1637         const AvPlug* pPlug = *it; 
     870        const Plug* pPlug = *it; 
    1638871        std::ostringstream strstrm; 
    1639872        strstrm << basePath << i; 
     
    1646879 
    1647880bool 
    1648 AvPlug::deserializeAvPlugVector( Glib::ustring basePath, 
     881Plug::deserializePlugVector( Glib::ustring basePath, 
    1649882                                 Util::IODeserialize& deser, 
    1650                                  AvPlugVector& vec ) 
     883                                 PlugVector& vec ) 
    1651884{ 
    1652885    int i = 0; 
     
    1664897 
    1665898            if ( result ) { 
    1666                 AvPlug* pPlug = m_plugManager->getPlug( iPlugId ); 
     899                Plug* pPlug = m_unit->getPlugManager().getPlug( iPlugId ); 
    1667900                if ( pPlug ) { 
    1668901                    vec.push_back( pPlug ); 
     
    1684917 
    1685918bool 
    1686 AvPlug::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    1687 { 
    1688     bool result
    1689     result = ser.write( basePath + "m_subunitType", m_subunitType ); 
    1690     result &= ser.write( basePath + "m_subunitId", m_subunitId ); 
     919Plug::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     920{ 
     921    bool result=true
     922    result &= ser.write( basePath + "m_subunitType", getSubunitType()); 
     923    result &= ser.write( basePath + "m_subunitId", getSubunitId()); 
    1691924    result &= ser.write( basePath + "m_functionBlockType", m_functionBlockType); 
    1692925    result &= ser.write( basePath + "m_functionBlockId", m_functionBlockId); 
     
    1700933    result &= ser.write( basePath + "m_samplingFrequency", m_samplingFrequency); 
    1701934    result &= serializeFormatInfos( basePath + "m_formatInfo", ser ); 
    1702     result &= serializeAvPlugVector( basePath + "m_inputConnections", ser, m_inputConnections ); 
    1703     result &= serializeAvPlugVector( basePath + "m_outputConnections", ser, m_outputConnections ); 
    1704     result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel); 
     935    result &= serializePlugVector( basePath + "m_inputConnections", ser, m_inputConnections ); 
     936    result &= serializePlugVector( basePath + "m_outputConnections", ser, m_outputConnections ); 
     937    result &= ser.write( basePath + "m_verbose_level", getDebugLevel()); 
    1705938    result &= ser.write( basePath + "m_globalId", m_globalId); 
    1706939    result &= ser.write( basePath + "m_globalIdCounter", m_globalIdCounter ); 
     
    1709942} 
    1710943 
    1711 AvPlug* 
    1712 AvPlug::deserialize( Glib::ustring basePath, 
     944Plug* 
     945Plug::deserialize( Glib::ustring basePath, 
    1713946                     Util::IODeserialize& deser, 
    1714                      AvDevice& avDevice
    1715                      AvPlugManager& plugManager ) 
    1716 { 
    1717     AvPlug* pPlug = new AvPlug; 
     947                     Unit& unit
     948                     PlugManager& plugManager ) 
     949{ 
     950    Plug* pPlug = new Plug; 
    1718951    if ( !pPlug ) { 
    1719952        return 0; 
    1720953    } 
    1721954 
    1722     pPlug->m_p1394Service = &avDevice.get1394Service(); 
    1723     pPlug->m_pConfigRom   = &avDevice.getConfigRom(); 
    1724     pPlug->m_plugManager  = &plugManager; 
    1725     bool result; 
    1726     result  = deser.read( basePath + "m_subunitType", pPlug->m_subunitType ); 
    1727     result &= deser.read( basePath + "m_subunitId", pPlug->m_subunitId ); 
     955    pPlug->m_unit = &unit; 
     956     
     957    bool result=true; 
     958     
     959    ESubunitType subunitType; 
     960    result  = deser.read( basePath + "m_subunitType", subunitType ); 
     961    subunit_t subunitId; 
     962    result &= deser.read( basePath + "m_subunitId", subunitId ); 
     963    pPlug->m_subunit = unit.getSubunit( subunitType, subunitType ); 
     964     
    1728965    result &= deser.read( basePath + "m_functionBlockType", pPlug->m_functionBlockType ); 
    1729966    result &= deser.read( basePath + "m_functionBlockId", pPlug->m_functionBlockId ); 
     
    1739976    // input and output connections can't be processed here because not all plugs might 
    1740977    // deserialized at this point. so we do that in deserializeUpdate. 
    1741     result &= deser.read( basePath + "m_verboseLevel", pPlug->m_verboseLevel ); 
     978    int level; 
     979    result &= deser.read( basePath + "m_verbose_level", level ); 
     980    setDebugLevel(level); 
    1742981    result &= deser.read( basePath + "m_globalId", pPlug->m_globalId ); 
    1743982    result &= deser.read( basePath + "m_globalIdCounter", pPlug->m_globalIdCounter ); 
     
    1752991 
    1753992bool 
    1754 AvPlug::deserializeUpdate( Glib::ustring basePath, 
     993Plug::deserializeUpdate( Glib::ustring basePath, 
    1755994                           Util::IODeserialize& deser ) 
    1756995{ 
    1757996    bool result; 
    1758997 
    1759     result  = deserializeAvPlugVector( basePath + "m_inputConnections", deser, m_inputConnections ); 
    1760     result &= deserializeAvPlugVector( basePath + "m_outputConnections", deser, m_outputConnections ); 
     998    result  = deserializePlugVector( basePath + "m_inputConnections", deser, m_inputConnections ); 
     999    result &= deserializePlugVector( basePath + "m_outputConnections", deser, m_outputConnections ); 
    17611000 
    17621001    return result; 
     
    17761015}; 
    17771016 
    1778 const char* avPlugAddressTypeToString( AvPlug::EAvPlugAddressType type ) 
     1017const char* avPlugAddressTypeToString( Plug::EPlugAddressType type ) 
    17791018{ 
    17801019    if ( type > ( int )( sizeof( avPlugAddressTypeStrings ) 
    17811020                         / sizeof( avPlugAddressTypeStrings[0] ) ) ) 
    17821021    { 
    1783         type = AvPlug::eAPA_Undefined; 
     1022        type = Plug::eAPA_Undefined; 
    17841023    } 
    17851024    return avPlugAddressTypeStrings[type]; 
     
    17971036}; 
    17981037 
    1799 const char* avPlugTypeToString( AvPlug::EAvPlugType type ) 
     1038const char* avPlugTypeToString( Plug::EPlugType type ) 
    18001039{ 
    18011040    if ( type > ( int )( sizeof( avPlugTypeStrings ) 
    18021041                         / sizeof( avPlugTypeStrings[0] ) ) ) 
    18031042    { 
    1804         type = AvPlug::eAPT_Unknown; 
     1043        type = Plug::eAPT_Unknown; 
    18051044    } 
    18061045    return avPlugTypeStrings[type]; 
     
    18141053}; 
    18151054 
    1816 const char* avPlugDirectionToString( AvPlug::EAvPlugDirection type ) 
     1055const char* avPlugDirectionToString( Plug::EPlugDirection type ) 
    18171056{ 
    18181057    if ( type > ( int )( sizeof( avPlugDirectionStrings ) 
    18191058                         / sizeof( avPlugDirectionStrings[0] ) ) ) 
    18201059    { 
    1821         type = AvPlug::eAPD_Unknown; 
     1060        type = Plug::eAPD_Unknown; 
    18221061    } 
    18231062    return avPlugDirectionStrings[type]; 
     
    18271066 
    18281067 
    1829 AvPlugManager::AvPlugManager( int verboseLevel ) 
    1830     : m_verboseLevel( verboseLevel ) 
    1831 
    1832     setDebugLevel( m_verboseLevel ); 
    1833 
    1834  
    1835 AvPlugManager::AvPlugManager() 
    1836     : m_verboseLevel( 0 ) 
    1837 
    1838     setDebugLevel( 0 ); 
    1839 
    1840  
    1841 AvPlugManager::AvPlugManager( const AvPlugManager& rhs ) 
    1842     : m_verboseLevel( rhs.m_verboseLevel ) 
    1843 
    1844     setDebugLevel( m_verboseLevel ); 
    1845 
    1846  
    1847 AvPlugManager::~AvPlugManager() 
    1848 
    1849 
    1850  
    1851 bool 
    1852 AvPlugManager::addPlug( AvPlug& plug ) 
     1068PlugManager::PlugManager(  ) 
     1069
     1070 
     1071
     1072 
     1073PlugManager::PlugManager( const PlugManager& rhs ) 
     1074
     1075    setDebugLevel( rhs.getDebugLevel() ); 
     1076
     1077 
     1078PlugManager::~PlugManager() 
     1079
     1080
     1081 
     1082bool 
     1083PlugManager::addPlug( Plug& plug ) 
    18531084{ 
    18541085    m_plugs.push_back( &plug ); 
     
    18571088 
    18581089bool 
    1859 AvPlugManager::remPlug( AvPlug& plug ) 
    1860 { 
    1861     for ( AvPlugVector::iterator it = m_plugs.begin(); 
     1090PlugManager::remPlug( Plug& plug ) 
     1091{ 
     1092    for ( PlugVector::iterator it = m_plugs.begin(); 
    18621093          it !=  m_plugs.end(); 
    18631094          ++it ) 
    18641095    { 
    1865         AvPlug* plugIt = *it; 
     1096        Plug* plugIt = *it; 
    18661097        if ( plugIt == &plug ) { 
    18671098            m_plugs.erase( it ); 
     
    18731104 
    18741105// helper function 
    1875 static void addConnection( AvPlugConnectionOwnerVector& connections, 
    1876                            AvPlug& srcPlug, 
    1877                            AvPlug& destPlug ) 
    1878 { 
    1879     for ( AvPlugConnectionOwnerVector::iterator it = connections.begin(); 
     1106static void addConnection( PlugConnectionOwnerVector& connections, 
     1107                           Plug& srcPlug, 
     1108                           Plug& destPlug ) 
     1109{ 
     1110    for ( PlugConnectionOwnerVector::iterator it = connections.begin(); 
    18801111          it != connections.end(); 
    18811112          ++it ) 
    18821113    { 
    1883         AvPlugConnection& con = *it; 
     1114        PlugConnection& con = *it; 
    18841115        if ( ( &( con.getSrcPlug() ) == &srcPlug ) 
    18851116             && ( &( con.getDestPlug() ) == &destPlug ) ) 
     
    18881119        } 
    18891120    } 
    1890     connections.push_back( AvPlugConnection( srcPlug, destPlug ) ); 
     1121    connections.push_back( PlugConnection( srcPlug, destPlug ) ); 
    18911122} 
    18921123 
    18931124void 
    1894 AvPlugManager::showPlugs() const 
     1125PlugManager::showPlugs() const 
    18951126{ 
    18961127    // \todo The information provided here could be better arranged. For a start it is ok, but 
     
    19031134    printf( "---+-----------------+-----------+-------------+-----------+-------------------+-----------------+------+--------------+------\n" ); 
    19041135 
    1905     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1136    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    19061137          it !=  m_plugs.end(); 
    19071138          ++it ) 
    19081139    { 
    1909         AvPlug* plug = *it; 
     1140        Plug* plug = *it; 
    19101141 
    19111142        printf( "%2d | %15s | %9s | %11s |      0x%02x |              0x%02x |            0x%02x | 0x%02x | %12s | %s\n", 
     
    19251156    printf( "-----------\n" ); 
    19261157 
    1927     AvPlugConnectionOwnerVector connections; 
    1928  
    1929     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1158    PlugConnectionOwnerVector connections; 
     1159 
     1160    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    19301161          it !=  m_plugs.end(); 
    19311162          ++it ) 
    19321163    { 
    1933         AvPlug* plug = *it; 
    1934         for ( AvPlugVector::const_iterator it = 
     1164        Plug* plug = *it; 
     1165        for ( PlugVector::const_iterator it = 
    19351166                  plug->getInputConnections().begin(); 
    19361167            it != plug->getInputConnections().end(); 
     
    19391170            addConnection( connections, *( *it ), *plug ); 
    19401171        } 
    1941         for ( AvPlugVector::const_iterator it = 
     1172        for ( PlugVector::const_iterator it = 
    19421173                  plug->getOutputConnections().begin(); 
    19431174            it != plug->getOutputConnections().end(); 
     
    19491180 
    19501181    printf( "digraph avcconnections {\n" ); 
    1951     for ( AvPlugConnectionOwnerVector::iterator it = connections.begin(); 
     1182    for ( PlugConnectionOwnerVector::iterator it = connections.begin(); 
    19521183          it != connections.end(); 
    19531184          ++it ) 
    19541185    { 
    1955         AvPlugConnection& con = *it; 
     1186        PlugConnection& con = *it; 
    19561187        printf( "\t\"(%d) %s\" -> \"(%d) %s\"\n", 
    19571188                con.getSrcPlug().getGlobalId(), 
     
    19601191                con.getDestPlug().getName() ); 
    19611192    } 
    1962     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1193    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    19631194          it != m_plugs.end(); 
    19641195          ++it ) 
    19651196    { 
    1966         AvPlug* plug = *it; 
     1197        Plug* plug = *it; 
    19671198        if ( plug->getFunctionBlockType() != 0xff ) { 
    19681199            std::ostringstream strstrm; 
     
    19841215            } 
    19851216             
    1986             if ( plug->getPlugDirection() == AvPlug::eAPD_Input ) { 
     1217            if ( plug->getPlugDirection() == Plug::eAPD_Input ) { 
    19871218                printf( "\t\"(%d) %s\" -> \"(%s, ID %d)\"\n", 
    19881219                        plug->getGlobalId(), 
     
    20091240    }; 
    20101241 
    2011     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1242    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    20121243          it !=  m_plugs.end(); 
    20131244          ++it ) 
    20141245    { 
    2015         AvPlug* plug = *it; 
     1246        Plug* plug = *it; 
    20161247        printf( "\t\"(%d) %s\" [color=%s,style=filled];\n", 
    20171248                plug->getGlobalId(), plug->getName(), 
     
    20251256    debugOutput( DEBUG_LEVEL_VERBOSE, "Plug details\n" ); 
    20261257    debugOutput( DEBUG_LEVEL_VERBOSE, "------------\n" ); 
    2027     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1258    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    20281259          it !=  m_plugs.end(); 
    20291260          ++it ) 
    20301261    { 
    2031         AvPlug* plug = *it; 
     1262        Plug* plug = *it; 
    20321263        debugOutput( DEBUG_LEVEL_VERBOSE, "Plug %d:\n", plug->getGlobalId() ); 
    20331264        plug->showPlug(); 
     
    20361267} 
    20371268 
    2038 AvPlug* 
    2039 AvPlugManager::getPlug( ESubunitType subunitType, 
     1269Plug* 
     1270PlugManager::getPlug( ESubunitType subunitType, 
    20401271                        subunit_id_t subunitId, 
    20411272                        function_block_type_t functionBlockType, 
    20421273                        function_block_id_t functionBlockId, 
    2043                         AvPlug::EAvPlugAddressType plugAddressType, 
    2044                         AvPlug::EAvPlugDirection plugDirection, 
     1274                        Plug::EPlugAddressType plugAddressType, 
     1275                        Plug::EPlugDirection plugDirection, 
    20451276                        plug_id_t plugId ) const 
    20461277{ 
     
    20551286                 plugId ); 
    20561287 
    2057     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1288    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    20581289          it !=  m_plugs.end(); 
    20591290          ++it ) 
    20601291    { 
    2061         AvPlug* plug = *it; 
     1292        Plug* plug = *it; 
    20621293 
    20631294        if (    ( subunitType == plug->getSubunitType() ) 
     
    20761307} 
    20771308 
    2078 AvPlug* 
    2079 AvPlugManager::getPlug( int iGlobalId ) const 
    2080 { 
    2081     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1309Plug* 
     1310PlugManager::getPlug( int iGlobalId ) const 
     1311{ 
     1312    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    20821313          it !=  m_plugs.end(); 
    20831314          ++it ) 
    20841315    { 
    2085         AvPlug* pPlug = *it; 
     1316        Plug* pPlug = *it; 
    20861317        if ( pPlug->getGlobalId() == iGlobalId ) { 
    20871318            return pPlug; 
     
    20921323} 
    20931324 
    2094 AvPlugVector 
    2095 AvPlugManager::getPlugsByType( ESubunitType subunitType, 
     1325PlugVector 
     1326PlugManager::getPlugsByType( ESubunitType subunitType, 
    20961327                               subunit_id_t subunitId, 
    20971328                               function_block_type_t functionBlockType, 
    20981329                               function_block_id_t functionBlockId, 
    2099                                AvPlug::EAvPlugAddressType plugAddressType, 
    2100                                AvPlug::EAvPlugDirection plugDirection, 
    2101                                AvPlug::EAvPlugType type) const 
     1330                               Plug::EPlugAddressType plugAddressType, 
     1331                               Plug::EPlugDirection plugDirection, 
     1332                               Plug::EPlugType type) const 
    21021333{ 
    21031334    debugOutput( DEBUG_LEVEL_VERBOSE, "SBT, SBID, FBT, FBID, AT, PD, T = " 
     
    21111342                 type ); 
    21121343 
    2113     AvPlugVector plugVector; 
    2114     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1344    PlugVector plugVector; 
     1345    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    21151346          it !=  m_plugs.end(); 
    21161347          ++it ) 
    21171348    { 
    2118         AvPlug* pPlug = *it; 
     1349        Plug* pPlug = *it; 
    21191350 
    21201351        if (    ( subunitType == pPlug->getSubunitType() ) 
     
    21341365 
    21351366bool 
    2136 AvPlugManager::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     1367PlugManager::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    21371368{ 
    21381369    bool result = true; 
    21391370    int i = 0; 
    2140     for ( AvPlugVector::const_iterator it = m_plugs.begin(); 
     1371    for ( PlugVector::const_iterator it = m_plugs.begin(); 
    21411372          it !=  m_plugs.end(); 
    21421373          ++it ) 
    21431374    { 
    2144         AvPlug* pPlug = *it; 
     1375        Plug* pPlug = *it; 
    21451376        std::ostringstream strstrm; 
    21461377        strstrm << basePath << i; 
     
    21521383} 
    21531384 
    2154 AvPlugManager* 
    2155 AvPlugManager::deserialize( Glib::ustring basePath, 
     1385PlugManager* 
     1386PlugManager::deserialize( Glib::ustring basePath, 
    21561387                            Util::IODeserialize& deser, 
    2157                             AvDevice& avDevice
    2158  
    2159 { 
    2160     AvPlugManager* pMgr = new AvPlugManager; 
     1388                            Unit& unit
     1389 
     1390{ 
     1391    PlugManager* pMgr = new PlugManager; 
    21611392 
    21621393    if ( !pMgr ) { 
     
    21691400        std::ostringstream strstrm; 
    21701401        strstrm << basePath << i; 
    2171         // avDevice still holds a null pointer for the plug manager 
     1402        // unit still holds a null pointer for the plug manager 
    21721403        // therefore we have to *this as additional argument 
    2173         AvPlug* pPlug = AvPlug::deserialize( strstrm.str() + "/", 
     1404        Plug* pPlug = Plug::deserialize( strstrm.str() + "/", 
    21741405                                             deser, 
    2175                                              avDevice
     1406                                             unit
    21761407                                             *pMgr ); 
    21771408        if ( pPlug ) { 
     
    21891420//////////////////////////////////// 
    21901421 
    2191 AvPlugConnection::AvPlugConnection( AvPlug& srcPlug, AvPlug& destPlug ) 
     1422PlugConnection::PlugConnection( Plug& srcPlug, Plug& destPlug ) 
    21921423    : m_srcPlug( &srcPlug ) 
    21931424    , m_destPlug( &destPlug ) 
     
    21951426} 
    21961427 
    2197 AvPlugConnection::AvPlugConnection() 
     1428PlugConnection::PlugConnection() 
    21981429    : m_srcPlug( 0 ) 
    21991430    , m_destPlug( 0 ) 
     
    22021433 
    22031434bool 
    2204 AvPlugConnection::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
     1435PlugConnection::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const 
    22051436{ 
    22061437    bool result; 
     
    22101441} 
    22111442 
    2212 AvPlugConnection* 
    2213 AvPlugConnection::deserialize( Glib::ustring basePath, 
     1443PlugConnection* 
     1444PlugConnection::deserialize( Glib::ustring basePath, 
    22141445                               Util::IODeserialize& deser, 
    2215                                AvDevice& avDevice
    2216 { 
    2217     AvPlugConnection* pConnection = new AvPlugConnection; 
     1446                               Unit& unit
     1447{ 
     1448    PlugConnection* pConnection = new PlugConnection; 
    22181449    if ( !pConnection ) { 
    22191450        return 0; 
     
    22311462    } 
    22321463 
    2233     pConnection->m_srcPlug  = avDevice.getPlugManager().getPlug( iSrcPlugId ); 
    2234     pConnection->m_destPlug = avDevice.getPlugManager().getPlug( iDestPlugId ); 
     1464    pConnection->m_srcPlug  = unit.getPlugManager().getPlug( iSrcPlugId ); 
     1465    pConnection->m_destPlug = unit.getPlugManager().getPlug( iDestPlugId ); 
    22351466 
    22361467    if ( !pConnection->m_srcPlug || !pConnection->m_destPlug ) { 
  • branches/echoaudio/src/libavc/general/avc_plug.h

    r505 r507  
    11/* 
     2 * Copyright (C)      2007 by Pieter Palmers 
    23 * Copyright (C) 2005-2007 by Daniel Wagner 
    34 * 
     
    2223 */ 
    2324 
    24 #ifndef BEBOB_AVPLUG_H 
    25 #define BEBOB_AVPLUG_H 
    26  
    27 #include "libavc/ccm/avc_signal_source.h" 
    28 #include "libavc/streamformat/avc_extended_stream_format.h" 
    29 #include "libavc/general/avc_extended_plug_info.h" 
    30 #include "libavc/general/avc_extended_cmd_generic.h" 
    31 #include "libavc/avc_definitions.h" 
    32 #include "libavc/general/avc_generic.h" 
     25#ifndef AVC_PLUG 
     26#define AVC_PLUG 
     27 
     28#include "../ccm/avc_signal_source.h" 
     29#include "../streamformat/avc_extended_stream_format.h" 
     30#include "avc_extended_plug_info.h" 
     31#include "avc_extended_cmd_generic.h" 
     32#include "../avc_definitions.h" 
     33#include "avc_generic.h" 
    3334 
    3435#include "libutil/serialize.h" 
     
    4142class ConfigRom; 
    4243 
    43 namespace BeBoB { 
    44  
    45 class AvDevice; 
    46 class AvPlugManager; 
    47 class AvPlug; 
    48  
    49 typedef std::vector<AvPlug*> AvPlugVector; 
    50  
    51 class AvPlug { 
     44namespace AVC { 
     45 
     46class Unit; 
     47class Subunit; 
     48class PlugManager; 
     49class Plug; 
     50 
     51typedef std::vector<Plug*> PlugVector; 
     52 
     53class Plug { 
    5254public: 
    5355 
    54     enum EAvPlugAddressType { 
    55     eAPA_PCR, 
    56     eAPA_ExternalPlug, 
    57     eAPA_AsynchronousPlug, 
    58     eAPA_SubunitPlug, 
    59     eAPA_FunctionBlockPlug, 
    60     eAPA_Undefined, 
    61     }; 
    62  
    63     enum EAvPlugType { 
     56    enum EPlugAddressType { 
     57        eAPA_PCR, 
     58        eAPA_ExternalPlug, 
     59        eAPA_AsynchronousPlug, 
     60        eAPA_SubunitPlug, 
     61        eAPA_FunctionBlockPlug, 
     62        eAPA_Undefined, 
     63    }; 
     64 
     65    enum EPlugType { 
    6466        eAPT_IsoStream, 
    6567        eAPT_AsyncStream, 
     
    7173    }; 
    7274 
    73     enum EAvPlugDirection { 
    74     eAPD_Input, 
    75     eAPD_Output, 
    76     eAPD_Unknown, 
     75    enum EPlugDirection { 
     76        eAPD_Input, 
     77        eAPD_Output, 
     78        eAPD_Unknown, 
    7779    }; 
    7880 
    7981    // \todo This constructors sucks. too many parameters. fix it. 
    80     AvPlug( Ieee1394Service& ieee1394Service, 
    81         ConfigRom& configRom, 
    82             AvPlugManager& plugManager, 
    83         AVC::ESubunitType subunitType, 
    84         AVC::subunit_id_t subunitId, 
    85         AVC::function_block_type_t functionBlockType, 
    86         AVC::function_block_type_t functionBlockId, 
    87         EAvPlugAddressType plugAddressType, 
    88         EAvPlugDirection plugDirection, 
    89         AVC::plug_id_t plugId, 
    90         int verboseLevel ); 
    91     AvPlug( const AvPlug& rhs ); 
    92     virtual ~AvPlug(); 
    93  
    94     bool discover(); 
    95     bool discoverConnections(); 
    96  
    97     bool inquireConnnection( AvPlug& plug ); 
    98     bool setConnection( AvPlug& plug ); 
     82    Plug( Unit* unit, 
     83          Subunit* subunit, 
     84          function_block_type_t functionBlockType, 
     85          function_block_type_t functionBlockId, 
     86          EPlugAddressType plugAddressType, 
     87          EPlugDirection plugDirection, 
     88          plug_id_t plugId ); 
     89    Plug( const Plug& rhs ); 
     90    virtual ~Plug(); 
     91 
     92    virtual bool discover()  
     93    {//FIXME: 
     94    #warning FIXME 
     95    };; 
     96    virtual bool discoverConnections()  
     97    {//FIXME: 
     98    #warning FIXME 
     99    };; 
     100 
     101    bool inquireConnnection( Plug& plug ); 
     102    bool setConnection( Plug& plug ); 
    99103 
    100104    int getGlobalId() const 
    101105        { return m_globalId; } 
    102     AVC::plug_id_t getPlugId() const 
     106    plug_id_t getPlugId() const 
    103107        { return m_id; } 
    104     AVC::ESubunitType getSubunitType() const 
    105         { return m_subunitType; } 
    106     AVC::subunit_id_t getSubunitId() const 
    107         { return m_subunitId; } 
     108    ESubunitType getSubunitType() const; 
     109    subunit_id_t getSubunitId() const; 
     110     
    108111    const char* getName() const 
    109112        { return m_name.c_str(); } 
    110     EAvPlugDirection getPlugDirection() const 
     113    EPlugDirection getPlugDirection() const 
    111114        { return m_direction; } 
    112     AVC::sampling_frequency_t getSamplingFrequency() const 
     115    sampling_frequency_t getSamplingFrequency() const 
    113116        { return m_samplingFrequency; } 
    114117    int getSampleRate() const; // 22050, 24000, 32000, ... 
     
    116119    int getNrOfStreams() const; 
    117120 
    118     EAvPlugDirection getDirection() const 
     121    EPlugDirection getDirection() const 
    119122        { return m_direction; } 
    120     EAvPlugAddressType getPlugAddressType() const 
     123    EPlugAddressType getPlugAddressType() const 
    121124        { return m_addressType; } 
    122     EAvPlugType getPlugType() const 
     125    EPlugType getPlugType() const 
    123126        { return m_infoPlugType; } 
    124127 
    125     AVC::function_block_type_t getFunctionBlockType() const 
     128    function_block_type_t getFunctionBlockType() const 
    126129        { return m_functionBlockType; } 
    127     AVC::function_block_id_t getFunctionBlockId() const 
     130    function_block_id_t getFunctionBlockId() const 
    128131        { return m_functionBlockId; } 
    129132 
    130     const AvPlugVector& getInputConnections() const 
     133    const PlugVector& getInputConnections() const 
    131134        { return m_inputConnections; } 
    132     const AvPlugVector& getOutputConnections() const 
     135    const PlugVector& getOutputConnections() const 
    133136        { return m_outputConnections; } 
    134137 
    135     static AVC::PlugAddress::EPlugDirection convertPlugDirection( 
    136     EAvPlugDirection direction); 
     138    static PlugAddress::EPlugDirection convertPlugDirection( 
     139    EPlugDirection direction); 
    137140 
    138141    void showPlug() const; 
    139142 
    140143    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    141     static AvPlug* deserialize( Glib::ustring basePath, 
     144    static Plug* deserialize( Glib::ustring basePath, 
    142145                                Util::IODeserialize& deser, 
    143                                 AvDevice& avDevice, 
    144                                 AvPlugManager& plugManager ); 
     146                                Unit& avDevice, 
     147                                PlugManager& plugManager ); 
    145148 
    146149    bool deserializeUpdate( Glib::ustring basePath, 
     
    149152 public: 
    150153    struct ChannelInfo { 
    151         AVC::stream_position_t          m_streamPosition; 
    152         AVC::stream_position_location_t m_location; 
    153         Glib::ustring                   m_name; 
     154        stream_position_t          m_streamPosition; 
     155        stream_position_location_t m_location; 
     156        Glib::ustring              m_name; 
    154157    }; 
    155158    typedef std::vector<ChannelInfo> ChannelInfoVector; 
    156159 
    157160    struct ClusterInfo { 
    158         int                      m_index; 
    159         AVC::port_type_t         m_portType; 
    160         Glib::ustring            m_name; 
    161  
    162         AVC::nr_of_channels_t    m_nrOfChannels; 
    163         ChannelInfoVector        m_channelInfos; 
    164         AVC::stream_format_t     m_streamFormat; 
     161        int                 m_index; 
     162        port_type_t         m_portType; 
     163        Glib::ustring       m_name; 
     164 
     165        nr_of_channels_t    m_nrOfChannels; 
     166        ChannelInfoVector   m_channelInfos; 
     167        stream_format_t     m_streamFormat; 
    165168    }; 
    166169    typedef std::vector<ClusterInfo> ClusterInfoVector; 
     
    170173 
    171174protected: 
    172     AvPlug(); 
    173  
    174     bool discoverPlugType(); 
    175     bool discoverName(); 
    176     bool discoverNoOfChannels(); 
    177     bool discoverChannelPosition(); 
    178     bool discoverChannelName(); 
    179     bool discoverClusterInfo(); 
    180     bool discoverStreamFormat(); 
    181     bool discoverSupportedStreamFormats(); 
    182     bool discoverConnectionsInput(); 
    183     bool discoverConnectionsOutput(); 
    184  
    185     AVC::ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd(); 
    186  
    187     AVC::ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd( 
    188             AVC::ExtendedStreamFormatCmd::ESubFunction subFunction); 
    189  
    190     AVC::SignalSourceCmd setSrcPlugAddrToSignalCmd(); 
     175    Plug(); 
     176 
     177    SignalSourceCmd setSrcPlugAddrToSignalCmd(); 
    191178 
    192179    void setDestPlugAddrToSignalCmd( 
    193             AVC::SignalSourceCmd& signalSourceCmd, AvPlug& plug ); 
     180            SignalSourceCmd& signalSourceCmd, Plug& plug ); 
    194181 
    195182    void debugOutputClusterInfos( int debugLevel ); 
    196183 
    197     bool copyClusterInfo(AVC::ExtendedPlugInfoPlugChannelPositionSpecificData& 
     184    bool copyClusterInfo(ExtendedPlugInfoPlugChannelPositionSpecificData& 
    198185                         channelPositionData ); 
    199186 
    200     bool addPlugConnection( AvPlugVector& connections, AvPlug& plug ); 
     187    bool addPlugConnection( PlugVector& connections, Plug& plug ); 
    201188 
    202189    bool discoverConnectionsFromSpecificData( 
    203         EAvPlugDirection discoverDirection, 
    204         AVC::PlugAddressSpecificData* plugAddress, 
    205         AvPlugVector& connections ); 
    206  
    207     AvPlug* getPlugDefinedBySpecificData( 
    208         AVC::UnitPlugSpecificDataPlugAddress* pUnitPlugAddress, 
    209         AVC::SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress, 
    210         AVC::FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress ); 
    211  
    212     EAvPlugDirection toggleDirection( EAvPlugDirection direction ) const; 
     190        EPlugDirection discoverDirection, 
     191        PlugAddressSpecificData* plugAddress, 
     192        PlugVector& connections ); 
     193 
     194    Plug* getPlugDefinedBySpecificData( 
     195        UnitPlugSpecificDataPlugAddress* pUnitPlugAddress, 
     196        SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress, 
     197        FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress ); 
     198 
     199    EPlugDirection toggleDirection( EPlugDirection direction ) const; 
    213200 
    214201    const ClusterInfo* getClusterInfoByIndex( int index ) const; 
     
    231218                                 Util::IODeserialize& deser ); 
    232219 
    233     bool serializeAvPlugVector( Glib::ustring basePath, 
     220    bool serializePlugVector( Glib::ustring basePath, 
    234221                                Util::IOSerialize& ser, 
    235                                 const AvPlugVector& vec) const; 
    236     bool deserializeAvPlugVector( Glib::ustring basePath, 
     222                                const PlugVector& vec) const; 
     223    bool deserializePlugVector( Glib::ustring basePath, 
    237224                                  Util::IODeserialize& deser, 
    238                                   AvPlugVector& vec ); 
    239  
    240 private
     225                                  PlugVector& vec ); 
     226 
     227protected
    241228    // Supported stream formats 
    242229    struct FormatInfo { 
    243230        FormatInfo() 
    244             : m_samplingFrequency( AVC::eSF_DontCare ) 
     231            : m_samplingFrequency( eSF_DontCare ) 
    245232            , m_isSyncStream( false ) 
    246233            , m_audioChannels( 0 ) 
     
    248235            , m_index( 0xff ) 
    249236            {} 
    250     AVC::sampling_frequency_t  m_samplingFrequency; 
    251     bool                       m_isSyncStream; 
    252     AVC::number_of_channels_t  m_audioChannels; 
    253     AVC::number_of_channels_t  m_midiChannels; 
    254     byte_t                     m_index; 
     237        sampling_frequency_t  m_samplingFrequency; 
     238        bool                       m_isSyncStream; 
     239        number_of_channels_t  m_audioChannels; 
     240        number_of_channels_t  m_midiChannels; 
     241        byte_t                     m_index; 
    255242    }; 
    256243    typedef std::vector<FormatInfo> FormatInfoVector; 
    257244 
    258245 
    259     Ieee1394Service*             m_p1394Service; 
    260     ConfigRom*                   m_pConfigRom; 
    261     AVC::ESubunitType     m_subunitType; 
    262     AVC::subunit_id_t                 m_subunitId; 
    263     AVC::function_block_type_t        m_functionBlockType; 
    264     AVC::function_block_id_t          m_functionBlockId; 
    265     EAvPlugAddressType           m_addressType; 
    266     EAvPlugDirection             m_direction; 
    267     AVC::plug_id_t                    m_id; 
    268     EAvPlugType                  m_infoPlugType; 
    269     AVC::nr_of_channels_t             m_nrOfChannels; 
    270     Glib::ustring                m_name; 
    271     ClusterInfoVector            m_clusterInfos; 
    272     AVC::sampling_frequency_t         m_samplingFrequency; 
    273     FormatInfoVector             m_formatInfos; 
    274     AvPlugVector                 m_inputConnections; 
    275     AvPlugVector                 m_outputConnections; 
    276     AvPlugManager*               m_plugManager; 
    277     int                          m_verboseLevel; 
    278     int                          m_globalId; 
    279     static int                   m_globalIdCounter; 
     246    Unit*                       m_unit; 
     247    Subunit*                    m_subunit; 
     248    function_block_type_t       m_functionBlockType; 
     249    function_block_id_t         m_functionBlockId; 
     250    EPlugAddressType            m_addressType; 
     251    EPlugDirection              m_direction; 
     252    plug_id_t                   m_id; 
     253    EPlugType                   m_infoPlugType; 
     254    nr_of_channels_t            m_nrOfChannels; 
     255    Glib::ustring               m_name; 
     256    ClusterInfoVector           m_clusterInfos; 
     257    sampling_frequency_t        m_samplingFrequency; 
     258    FormatInfoVector            m_formatInfos; 
     259    PlugVector                  m_inputConnections; 
     260    PlugVector                  m_outputConnections; 
     261    int                         m_globalId; 
     262    static int                  m_globalIdCounter; 
    280263 
    281264    DECLARE_DEBUG_MODULE; 
    282265}; 
    283266 
    284 const char* avPlugAddressTypeToString( AvPlug::EAvPlugAddressType addressType ); 
    285 const char* avPlugTypeToString( AvPlug::EAvPlugType type ); 
    286 const char* avPlugDirectionToString( AvPlug::EAvPlugDirection direction ); 
    287  
    288 class AvPlugManager 
     267const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType ); 
     268const char* avPlugTypeToString( Plug::EPlugType type ); 
     269const char* avPlugDirectionToString( Plug::EPlugDirection direction ); 
     270 
     271class PlugManager 
    289272{ 
    290273public: 
    291     AvPlugManager( int verboseLevel ); 
    292     AvPlugManager( const AvPlugManager& rhs ); 
    293     ~AvPlugManager(); 
    294  
    295     bool addPlug( AvPlug& plug ); 
    296     bool remPlug( AvPlug& plug ); 
     274    PlugManager( ); 
     275    PlugManager( const PlugManager& rhs ); 
     276    ~PlugManager(); 
     277 
     278    bool addPlug( Plug& plug ); 
     279    bool remPlug( Plug& plug ); 
    297280 
    298281    void showPlugs() const; 
    299282 
    300     AvPlug* getPlug( AVC::ESubunitType subunitType, 
    301                      AVC::subunit_id_t subunitId, 
    302                      AVC::function_block_type_t functionBlockType, 
    303                      AVC::function_block_id_t functionBlockId, 
    304                      AvPlug::EAvPlugAddressType plugAddressType, 
    305                      AvPlug::EAvPlugDirection plugDirection, 
    306                      AVC::plug_id_t plugId ) const; 
    307     AvPlug* getPlug( int iGlobalId ) const; 
    308     AvPlugVector getPlugsByType( AVC::ESubunitType subunitType, 
    309                  AVC::subunit_id_t subunitId, 
    310                  AVC::function_block_type_t functionBlockType, 
    311                  AVC::function_block_id_t functionBlockId, 
    312                  AvPlug::EAvPlugAddressType plugAddressType, 
    313                  AvPlug::EAvPlugDirection plugDirection, 
    314                  AvPlug::EAvPlugType type) const; 
     283    Plug* getPlug( ESubunitType subunitType, 
     284                   subunit_id_t subunitId, 
     285                   function_block_type_t functionBlockType, 
     286                   function_block_id_t functionBlockId, 
     287                   Plug::EPlugAddressType plugAddressType, 
     288                   Plug::EPlugDirection plugDirection, 
     289                   plug_id_t plugId ) const; 
     290    Plug* getPlug( int iGlobalId ) const; 
     291    PlugVector getPlugsByType( ESubunitType subunitType, 
     292                 subunit_id_t subunitId, 
     293                 function_block_type_t functionBlockType, 
     294                 function_block_id_t functionBlockId, 
     295                 Plug::EPlugAddressType plugAddressType, 
     296                 Plug::EPlugDirection plugDirection, 
     297                 Plug::EPlugType type) const; 
    315298 
    316299    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    317     static  AvPlugManager* deserialize( Glib::ustring basePath, 
     300    static  PlugManager* deserialize( Glib::ustring basePath, 
    318301                                        Util::IODeserialize& deser, 
    319                                         AvDevice& avDevice ); 
    320  
     302                                        Unit& avDevice ); 
     303    void setVerboseLevel( int i )  
     304            {setDebugLevel(i);}; 
    321305private: 
    322     AvPlugManager(); 
    323  
    324     int          m_verboseLevel; 
    325     AvPlugVector m_plugs; 
     306 
     307    PlugVector   m_plugs; 
    326308 
    327309    DECLARE_DEBUG_MODULE; 
    328310}; 
    329311 
    330 class AvPlugConnection { 
     312class PlugConnection { 
    331313public: 
    332     AvPlugConnection( AvPlug& srcPlug, AvPlug& destPlug ); 
    333  
    334     AvPlug& getSrcPlug() const 
     314    PlugConnection( Plug& srcPlug, Plug& destPlug ); 
     315 
     316    Plug& getSrcPlug() const 
    335317        { return *m_srcPlug; } 
    336     AvPlug& getDestPlug() const 
     318    Plug& getDestPlug() const 
    337319        { return *m_destPlug; } 
    338320 
    339321    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    340     static AvPlugConnection* deserialize( Glib::ustring basePath, 
     322    static PlugConnection* deserialize( Glib::ustring basePath, 
    341323                                          Util::IODeserialize& deser, 
    342                                           AvDevice& avDevice ); 
     324                                          Unit& avDevice ); 
    343325private: 
    344     AvPlugConnection(); 
     326    PlugConnection(); 
    345327 
    346328private: 
    347     AvPlug* m_srcPlug; 
    348     AvPlug* m_destPlug; 
     329    Plug* m_srcPlug; 
     330    Plug* m_destPlug; 
    349331}; 
    350332 
    351 typedef std::vector<AvPlugConnection*> AvPlugConnectionVector; 
    352 typedef std::vector<AvPlugConnection> AvPlugConnectionOwnerVector; 
     333typedef std::vector<PlugConnection*> PlugConnectionVector; 
     334typedef std::vector<PlugConnection> PlugConnectionOwnerVector; 
    353335 
    354336} 
    355337 
    356 #endif // BEBOB_AVPLUG_H 
     338#endif // AVC_PLUG 
  • branches/echoaudio/src/libavc/general/avc_subunit.cpp

    r503 r507  
    2222 */ 
    2323 
    24 #include "bebob/bebob_functionblock.h" 
    25 #include "bebob/bebob_avdevice_subunit.h" 
    26 #include "bebob/bebob_avdevice.h" 
     24 
     25#include "avc_subunit.h" 
     26#include "avc_unit.h" 
    2727#include "bebob/bebob_avplug.h" 
    2828#include "libieee1394/configrom.h" 
    2929 
    30 #include "libavc/general/avc_plug_info.h" 
    31 #include "libavc/streamformat/avc_extended_stream_format.h" 
    32 #include "libavc/util/avc_serialize.h" 
     30#include "../general/avc_plug_info.h" 
     31#include "../streamformat/avc_extended_stream_format.h" 
     32#include "../util/avc_serialize.h" 
    3333 
    3434#include <sstream> 
    3535 
    36 using namespace AVC; 
    37  
    38 IMPL_DEBUG_MODULE( BeBoB::AvDeviceSubunit, BeBoB::AvDeviceSubunit, DEBUG_LEVEL_VERBOSE ); 
     36namespace AVC { 
     37 
     38IMPL_DEBUG_MODULE( Subunit, Subunit, DEBUG_LEVEL_VERBOSE ); 
    3939 
    4040//////////////////////////////////////////// 
    4141 
    42 BeBoB::AvDeviceSubunit::AvDeviceSubunit( AvDevice& avDevice, 
    43                                          ESubunitType type, 
    44                                          subunit_t id, 
    45                                          int verboseLevel ) 
    46     : m_avDevice( &avDevice ) 
     42Subunit::Subunit( Unit& unit, 
     43                  ESubunitType type, 
     44                  subunit_t id ) 
     45    : m_unit( &unit ) 
    4746    , m_sbType( type ) 
    4847    , m_sbId( id ) 
    49     , m_verboseLevel( verboseLevel ) 
    50 
    51     setDebugLevel( m_verboseLevel ); 
    52 
    53  
    54 BeBoB::AvDeviceSubunit::AvDeviceSubunit() 
    55 
    56 
    57  
    58 BeBoB::AvDeviceSubunit::~AvDeviceSubunit() 
    59 
    60     for ( AvPlugVector::iterator it = m_plugs.begin(); 
     48
     49 
     50
     51 
     52Subunit::Subunit() 
     53
     54
     55 
     56Subunit::~Subunit() 
     57
     58    for ( PlugVector::iterator it = m_plugs.begin(); 
    6159          it != m_plugs.end(); 
    6260          ++it ) 
     
    6765 
    6866bool 
    69 BeBoB::AvDeviceSubunit::discover() 
    70 
    71     if ( !discoverPlugs() ) { 
    72         debugError( "plug discovering failed\n" ); 
    73         return false; 
    74     } 
    75  
     67Subunit::discover() 
     68
     69    // There is nothing we can discover for a generic subunit 
     70    // Maybe its plugs, but there are multiple ways of doing that. 
    7671    return true; 
    7772} 
    7873 
    7974bool 
    80 BeBoB::AvDeviceSubunit::discoverPlugs() 
    81 
    82     PlugInfoCmd plugInfoCmd( m_avDevice->get1394Service(), 
    83                              PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug ); 
    84     plugInfoCmd.setNodeId( m_avDevice->getConfigRom().getNodeId() ); 
    85     plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    86     plugInfoCmd.setSubunitType( m_sbType ); 
    87     plugInfoCmd.setSubunitId( m_sbId ); 
    88     plugInfoCmd.setVerbose( m_verboseLevel ); 
    89  
    90     if ( !plugInfoCmd.fire() ) { 
    91         debugError( "plug info command failed\n" ); 
    92         return false; 
    93     } 
    94  
    95     debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n", 
    96                  plugInfoCmd.m_sourcePlugs ); 
    97     debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output " 
    98                  "plugs = %d\n", plugInfoCmd.m_destinationPlugs ); 
    99  
    100     if ( !discoverPlugs( AvPlug::eAPD_Input, 
    101                          plugInfoCmd.m_destinationPlugs ) ) 
    102     { 
    103         debugError( "destination plug discovering failed\n" ); 
    104         return false; 
    105     } 
    106  
    107     if ( !discoverPlugs(  AvPlug::eAPD_Output, 
    108                           plugInfoCmd.m_sourcePlugs ) ) 
    109     { 
    110         debugError( "source plug discovering failed\n" ); 
    111         return false; 
    112     } 
    113  
     75Subunit::addPlug( Plug& plug ) 
     76
     77    m_plugs.push_back( &plug ); 
    11478    return true; 
    11579} 
    11680 
    117 bool 
    118 BeBoB::AvDeviceSubunit::discoverConnections() 
    119 
    120     for ( AvPlugVector::iterator it = m_plugs.begin(); 
     81 
     82Plug* 
     83Subunit::getPlug(Plug::EPlugDirection direction, plug_id_t plugId) 
     84
     85    for ( PlugVector::iterator it = m_plugs.begin(); 
    12186          it != m_plugs.end(); 
    12287          ++it ) 
    12388    { 
    124         AvPlug* plug = *it; 
    125         if ( !plug->discoverConnections() ) { 
    126             debugError( "plug connection discovering failed ('%s')\n", 
    127                         plug->getName() ); 
    128             return false; 
    129         } 
    130     } 
    131  
    132     return true; 
    133 
    134  
    135 bool 
    136 BeBoB::AvDeviceSubunit::discoverPlugs(AvPlug::EAvPlugDirection plugDirection, 
    137                                       plug_id_t plugMaxId ) 
    138 
    139     for ( int plugIdx = 0; 
    140           plugIdx < plugMaxId; 
    141           ++plugIdx ) 
    142     { 
    143         ESubunitType subunitType = 
    144             static_cast<ESubunitType>( getSubunitType() ); 
    145         AvPlug* plug = new AvPlug( m_avDevice->get1394Service(), 
    146                                    m_avDevice->getConfigRom(), 
    147                                    m_avDevice->getPlugManager(), 
    148                                    subunitType, 
    149                                    getSubunitId(), 
    150                                    0xff, 
    151                                    0xff, 
    152                                    AvPlug::eAPA_SubunitPlug, 
    153                                    plugDirection, 
    154                                    plugIdx, 
    155                                    m_verboseLevel ); 
    156         if ( !plug || !plug->discover() ) { 
    157             debugError( "plug discover failed\n" ); 
    158             return false; 
    159         } 
    160  
    161         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    162                      plug->getName() ); 
    163         m_plugs.push_back( plug ); 
    164     } 
    165     return true; 
    166 
    167  
    168 bool 
    169 BeBoB::AvDeviceSubunit::addPlug( AvPlug& plug ) 
    170 
    171     m_plugs.push_back( &plug ); 
    172     return true; 
    173 
    174  
    175  
    176 BeBoB::AvPlug* 
    177 BeBoB::AvDeviceSubunit::getPlug(AvPlug::EAvPlugDirection direction, plug_id_t plugId) 
    178 
    179     for ( AvPlugVector::iterator it = m_plugs.begin(); 
    180           it != m_plugs.end(); 
    181           ++it ) 
    182     { 
    183         AvPlug* plug = *it; 
     89        Plug* plug = *it; 
    18490        if ( ( plug->getPlugId() == plugId ) 
    18591            && ( plug->getDirection() == direction ) ) 
     
    19197} 
    19298 
    193  
    194 bool 
    195 BeBoB::AvDeviceSubunit::serialize( Glib::ustring basePath, 
     99bool 
     100Subunit::serialize( Glib::ustring basePath, 
    196101                                   Util::IOSerialize& ser ) const 
    197102{ 
     
    200105    result  = ser.write( basePath + "m_sbType", m_sbType ); 
    201106    result &= ser.write( basePath + "m_sbId", m_sbId ); 
    202     result &= ser.write( basePath + "m_verboseLevel", m_verboseLevel ); 
     107    result &= ser.write( basePath + "m_verboseLevel", getDebugLevel() ); 
    203108    result &= serializeChild( basePath, ser ); 
    204109 
     
    206111} 
    207112 
    208 BeBoB::AvDeviceSubunit* 
    209 BeBoB::AvDeviceSubunit::deserialize( Glib::ustring basePath, 
     113Subunit* 
     114Subunit::deserialize( Glib::ustring basePath, 
    210115                                     Util::IODeserialize& deser, 
    211                                      AvDevice& avDevice
     116                                     Unit& unit
    212117{ 
    213118    bool result; 
     
    215120    result  = deser.read( basePath + "m_sbType", sbType ); 
    216121 
    217     AvDeviceSubunit* pSubunit = 0; 
     122    Subunit* pSubunit = 0; 
    218123    switch( sbType ) { 
    219124    case eST_Audio: 
    220         pSubunit = new AvDeviceSubunitAudio; 
     125        pSubunit = new SubunitAudio; 
    221126        break; 
    222127    case eST_Music: 
    223         pSubunit = new AvDeviceSubunitMusic; 
     128        pSubunit = new SubunitMusic; 
    224129        break; 
    225130    default: 
     
    231136    } 
    232137 
    233     pSubunit->m_avDevice = &avDevice
     138    pSubunit->m_unit = &unit
    234139    pSubunit->m_sbType = sbType; 
    235140    result &= deser.read( basePath + "m_sbId", pSubunit->m_sbId ); 
    236     result &= deser.read( basePath + "m_verboseLevel", pSubunit->m_verboseLevel ); 
    237     result &= pSubunit->deserializeChild( basePath, deser, avDevice ); 
     141    int verboseLevel; 
     142    result &= deser.read( basePath + "m_verboseLevel", verboseLevel ); 
     143    setDebugLevel(verboseLevel); 
     144    result &= pSubunit->deserializeChild( basePath, deser, unit ); 
    238145 
    239146    if ( !result ) { 
     
    247154//////////////////////////////////////////// 
    248155 
    249 BeBoB::AvDeviceSubunitAudio::AvDeviceSubunitAudio( AvDevice& avDevice, 
    250                                                    subunit_t id, 
    251                                                    int verboseLevel ) 
    252     : AvDeviceSubunit( avDevice, eST_Audio, id, verboseLevel ) 
    253 
    254 
    255  
    256 BeBoB::AvDeviceSubunitAudio::AvDeviceSubunitAudio() 
    257     : AvDeviceSubunit() 
    258 
    259 
    260  
    261 BeBoB::AvDeviceSubunitAudio::~AvDeviceSubunitAudio() 
    262 
    263     for ( FunctionBlockVector::iterator it = m_functions.begin(); 
     156SubunitAudio::SubunitAudio( Unit& unit, subunit_t id ) 
     157    : Subunit( unit, eST_Audio, id ) 
     158
     159
     160 
     161SubunitAudio::SubunitAudio() 
     162    : Subunit() 
     163
     164
     165 
     166SubunitAudio::~SubunitAudio() 
     167
     168    for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin(); 
    264169          it != m_functions.end(); 
    265170          ++it ) 
     
    270175 
    271176bool 
    272 BeBoB::AvDeviceSubunitAudio::discover() 
     177SubunitAudio::discover() 
    273178{ 
    274179    debugOutput(DEBUG_LEVEL_NORMAL, "Discovering Audio Subunit...\n"); 
    275180     
    276     if ( !AvDeviceSubunit::discover() ) { 
     181    if ( !Subunit::discover() ) { 
    277182        return false; 
    278183    } 
    279184 
    280     if ( !discoverFunctionBlocks() ) { 
    281         debugError( "function block discovering failed\n" ); 
    282         return false; 
    283     } 
     185//     if ( !discoverBeBoB::FunctionBlocks() ) { 
     186//         debugError( "function block discovering failed\n" ); 
     187//         return false; 
     188//     } 
    284189 
    285190    return true; 
    286191} 
    287192 
    288 bool 
    289 BeBoB::AvDeviceSubunitAudio::discoverConnections() 
    290 
    291     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
    292     if ( !AvDeviceSubunit::discoverConnections() ) { 
    293         return false; 
    294     } 
    295  
    296     for ( FunctionBlockVector::iterator it = m_functions.begin(); 
     193 
     194const char* 
     195SubunitAudio::getName() 
     196
     197    return "AudioSubunit"; 
     198
     199 
     200// bool 
     201// SubunitAudio::discoverConnections() 
     202// { 
     203//     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 
     204//     if ( !Subunit::discoverConnections() ) { 
     205//         return false; 
     206//     } 
     207//  
     208//     for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin(); 
     209//           it != m_functions.end(); 
     210//           ++it ) 
     211//     { 
     212//         BeBoB::FunctionBlock* function = *it; 
     213//         if ( !function->discoverConnections() ) { 
     214//             debugError( "functionblock connection discovering failed ('%s')\n", 
     215//                         function->getName() ); 
     216//             return false; 
     217//         } 
     218//     } 
     219//  
     220//     return true; 
     221// } 
     222// bool 
     223// SubunitAudio::discoverBeBoB::FunctionBlocks() 
     224// { 
     225//     debugOutput( DEBUG_LEVEL_NORMAL, 
     226//                  "Discovering function blocks...\n"); 
     227//  
     228//     if ( !discoverBeBoB::FunctionBlocksDo( 
     229//              ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector) ) 
     230//     { 
     231//         debugError( "Could not discover function block selector\n" ); 
     232//         return false; 
     233//     } 
     234//     if ( !discoverBeBoB::FunctionBlocksDo( 
     235//              ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature) ) 
     236//     { 
     237//         debugError( "Could not discover function block feature\n" ); 
     238//         return false; 
     239//     } 
     240//     if ( !discoverBeBoB::FunctionBlocksDo( 
     241//              ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing) ) 
     242//     { 
     243//         debugError( "Could not discover function block processing\n" ); 
     244//         return false; 
     245//     } 
     246//     if ( !discoverBeBoB::FunctionBlocksDo( 
     247//              ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec) ) 
     248//     { 
     249//         debugError( "Could not discover function block codec\n" ); 
     250//         return false; 
     251//     } 
     252//  
     253//     // print a function block list 
     254// #ifdef DEBUG 
     255//     if (getDebugLevel() >= DEBUG_LEVEL_NORMAL) { 
     256//      
     257//         for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin(); 
     258//             it != m_functions.end(); 
     259//             ++it ) 
     260//         { 
     261//             debugOutput(DEBUG_LEVEL_NORMAL, "%20s FB, type 0x%X, id=%d\n", 
     262//                 (*it)->getName(), 
     263//                 (*it)->getType(), 
     264//                 (*it)->getId()); 
     265//         } 
     266//     } 
     267// #endif 
     268//  
     269//     return true; 
     270// } 
     271//  
     272// bool 
     273// SubunitAudio::discoverBeBoB::FunctionBlocksDo( 
     274//     ExtendedSubunitInfoCmd::EBeBoB::FunctionBlockType fbType ) 
     275// { 
     276//     int page = 0; 
     277//     bool cmdSuccess = false; 
     278//     bool finished = false; 
     279//  
     280//     do { 
     281//         ExtendedSubunitInfoCmd 
     282//             extSubunitInfoCmd( m_unit->get1394Service() ); 
     283//         extSubunitInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 
     284//         extSubunitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
     285//         extSubunitInfoCmd.setSubunitId( getSubunitId() ); 
     286//         extSubunitInfoCmd.setSubunitType( getSubunitType() ); 
     287//         extSubunitInfoCmd.setVerbose( m_verboseLevel ); 
     288//  
     289//         extSubunitInfoCmd.m_fbType = fbType; 
     290//         extSubunitInfoCmd.m_page = page; 
     291//  
     292//         cmdSuccess = extSubunitInfoCmd.fire(); 
     293//         if ( cmdSuccess 
     294//              && ( extSubunitInfoCmd.getResponse() 
     295//                   == AVCCommand::eR_Implemented ) ) 
     296//         { 
     297//             for ( ExtendedSubunitInfoPageDataVector::iterator it = 
     298//                       extSubunitInfoCmd.m_infoPageDatas.begin(); 
     299//                   cmdSuccess 
     300//                       && ( it != extSubunitInfoCmd.m_infoPageDatas.end() ); 
     301//                   ++it ) 
     302//             { 
     303//                 cmdSuccess = createBeBoB::FunctionBlock( fbType, **it ); 
     304//             } 
     305//             if ( ( extSubunitInfoCmd.m_infoPageDatas.size() != 0 ) 
     306//                  && ( extSubunitInfoCmd.m_infoPageDatas.size() == 5 ) ) 
     307//             { 
     308//                 page++; 
     309//             } else { 
     310//                 finished = true; 
     311//             } 
     312//         } else { 
     313//             finished = true; 
     314//         } 
     315//     } while ( cmdSuccess && !finished ); 
     316//  
     317//     return cmdSuccess; 
     318// } 
     319//  
     320// bool 
     321// SubunitAudio::createBeBoB::FunctionBlock( 
     322//     ExtendedSubunitInfoCmd::EBeBoB::FunctionBlockType fbType, 
     323//     ExtendedSubunitInfoPageData& data ) 
     324// { 
     325//     BeBoB::FunctionBlock::ESpecialPurpose purpose 
     326//         = convertSpecialPurpose(  data.m_functionBlockSpecialPupose ); 
     327//  
     328//     BeBoB::FunctionBlock* fb = 0; 
     329//  
     330//     switch ( fbType ) { 
     331//     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector: 
     332//     { 
     333//         fb = new BeBoB::FunctionBlockSelector( *this, 
     334//                                         data.m_functionBlockId, 
     335//                                         purpose, 
     336//                                         data.m_noOfInputPlugs, 
     337//                                         data.m_noOfOutputPlugs, 
     338//                                         m_verboseLevel ); 
     339//     } 
     340//     break; 
     341//     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature: 
     342//     { 
     343//         fb = new BeBoB::FunctionBlockFeature( *this, 
     344//                                        data.m_functionBlockId, 
     345//                                        purpose, 
     346//                                        data.m_noOfInputPlugs, 
     347//                                        data.m_noOfOutputPlugs, 
     348//                                        m_verboseLevel ); 
     349//     } 
     350//     break; 
     351//     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing: 
     352//     { 
     353//         switch ( data.m_functionBlockType ) { 
     354//         case ExtendedSubunitInfoCmd::ePT_EnhancedMixer: 
     355//         { 
     356//             fb = new BeBoB::FunctionBlockEnhancedMixer( *this, 
     357//                                                  data.m_functionBlockId, 
     358//                                                  purpose, 
     359//                                                  data.m_noOfInputPlugs, 
     360//                                                  data.m_noOfOutputPlugs, 
     361//                                                  m_verboseLevel ); 
     362//         } 
     363//         break; 
     364//         case ExtendedSubunitInfoCmd::ePT_Mixer: 
     365//         case ExtendedSubunitInfoCmd::ePT_Generic: 
     366//         case ExtendedSubunitInfoCmd::ePT_UpDown: 
     367//         case ExtendedSubunitInfoCmd::ePT_DolbyProLogic: 
     368//         case ExtendedSubunitInfoCmd::ePT_3DStereoExtender: 
     369//         case ExtendedSubunitInfoCmd::ePT_Reverberation: 
     370//         case ExtendedSubunitInfoCmd::ePT_Chorus: 
     371//         case ExtendedSubunitInfoCmd::ePT_DynamicRangeCompression: 
     372//         default: 
     373//             fb = new BeBoB::FunctionBlockProcessing( *this, 
     374//                                               data.m_functionBlockId, 
     375//                                               purpose, 
     376//                                               data.m_noOfInputPlugs, 
     377//                                               data.m_noOfOutputPlugs, 
     378//                                               m_verboseLevel ); 
     379//             debugWarning( "Dummy function block processing created. " 
     380//                           "Implementation is missing\n" ); 
     381//         } 
     382//     } 
     383//     break; 
     384//     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec: 
     385//     { 
     386//         fb = new BeBoB::FunctionBlockCodec( *this, 
     387//                                      data.m_functionBlockId, 
     388//                                      purpose, 
     389//                                      data.m_noOfInputPlugs, 
     390//                                      data.m_noOfOutputPlugs, 
     391//                                      m_verboseLevel ); 
     392//         debugWarning( "Dummy function block codec created. " 
     393//                       "Implementation is missing\n" ); 
     394//     } 
     395//     break; 
     396//     default: 
     397//         debugError( "Unhandled function block type found\n" ); 
     398//         return false; 
     399//     } 
     400//  
     401//     if ( !fb ) { 
     402//         debugError( "Could create function block\n" ); 
     403//         return false; 
     404//     } 
     405//     if ( !fb->discover() ) { 
     406//         debugError( "Could not discover function block %s\n", 
     407//                     fb->getName() ); 
     408//         delete fb; 
     409//         return false; 
     410//     } 
     411//     m_functions.push_back( fb ); 
     412//  
     413//     return true; 
     414// } 
     415//  
     416// BeBoB::FunctionBlock::ESpecialPurpose 
     417// SubunitAudio::convertSpecialPurpose( 
     418//     function_block_special_purpose_t specialPurpose ) 
     419// { 
     420//     BeBoB::FunctionBlock::ESpecialPurpose p; 
     421//     switch ( specialPurpose ) { 
     422//     case ExtendedSubunitInfoPageData::eSP_InputGain: 
     423//         p  = BeBoB::FunctionBlock::eSP_InputGain; 
     424//         break; 
     425//     case ExtendedSubunitInfoPageData::eSP_OutputVolume: 
     426//         p = BeBoB::FunctionBlock::eSP_OutputVolume; 
     427//     break; 
     428//     default: 
     429//         p = BeBoB::FunctionBlock::eSP_NoSpecialPurpose; 
     430//     } 
     431//     return p; 
     432// } 
     433//  
     434bool 
     435SubunitAudio::serializeChild( Glib::ustring basePath, 
     436                                             Util::IOSerialize& ser ) const 
     437
     438    bool result = true; 
     439    int i = 0; 
     440 
     441    for ( BeBoB::FunctionBlockVector::const_iterator it = m_functions.begin(); 
    297442          it != m_functions.end(); 
    298443          ++it ) 
    299444    { 
    300         FunctionBlock* function = *it; 
    301         if ( !function->discoverConnections() ) { 
    302             debugError( "functionblock connection discovering failed ('%s')\n", 
    303                         function->getName() ); 
    304             return false; 
    305         } 
    306     } 
    307  
    308     return true; 
    309 
    310  
    311 const char* 
    312 BeBoB::AvDeviceSubunitAudio::getName() 
    313 
    314     return "AudioSubunit"; 
    315 
    316  
    317 bool 
    318 BeBoB::AvDeviceSubunitAudio::discoverFunctionBlocks() 
    319 
    320     debugOutput( DEBUG_LEVEL_NORMAL, 
    321                  "Discovering function blocks...\n"); 
    322  
    323     if ( !discoverFunctionBlocksDo( 
    324              ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector) ) 
    325     { 
    326         debugError( "Could not discover function block selector\n" ); 
    327         return false; 
    328     } 
    329     if ( !discoverFunctionBlocksDo( 
    330              ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature) ) 
    331     { 
    332         debugError( "Could not discover function block feature\n" ); 
    333         return false; 
    334     } 
    335     if ( !discoverFunctionBlocksDo( 
    336              ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing) ) 
    337     { 
    338         debugError( "Could not discover function block processing\n" ); 
    339         return false; 
    340     } 
    341     if ( !discoverFunctionBlocksDo( 
    342              ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec) ) 
    343     { 
    344         debugError( "Could not discover function block codec\n" ); 
    345         return false; 
    346     } 
    347  
    348     // print a function block list 
    349 #ifdef DEBUG 
    350     if (getDebugLevel() >= DEBUG_LEVEL_NORMAL) { 
    351      
    352         for ( FunctionBlockVector::iterator it = m_functions.begin(); 
    353             it != m_functions.end(); 
    354             ++it ) 
    355         { 
    356             debugOutput(DEBUG_LEVEL_NORMAL, "%20s FB, type 0x%X, id=%d\n", 
    357                 (*it)->getName(), 
    358                 (*it)->getType(), 
    359                 (*it)->getId()); 
    360         } 
    361     } 
    362 #endif 
    363  
    364     return true; 
    365 
    366  
    367 bool 
    368 BeBoB::AvDeviceSubunitAudio::discoverFunctionBlocksDo( 
    369     ExtendedSubunitInfoCmd::EFunctionBlockType fbType ) 
    370 
    371     int page = 0; 
    372     bool cmdSuccess = false; 
    373     bool finished = false; 
    374  
    375     do { 
    376         ExtendedSubunitInfoCmd 
    377             extSubunitInfoCmd( m_avDevice->get1394Service() ); 
    378         extSubunitInfoCmd.setNodeId( m_avDevice->getConfigRom().getNodeId() ); 
    379         extSubunitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    380         extSubunitInfoCmd.setSubunitId( getSubunitId() ); 
    381         extSubunitInfoCmd.setSubunitType( getSubunitType() ); 
    382         extSubunitInfoCmd.setVerbose( m_verboseLevel ); 
    383  
    384         extSubunitInfoCmd.m_fbType = fbType; 
    385         extSubunitInfoCmd.m_page = page; 
    386  
    387         cmdSuccess = extSubunitInfoCmd.fire(); 
    388         if ( cmdSuccess 
    389              && ( extSubunitInfoCmd.getResponse() 
    390                   == AVCCommand::eR_Implemented ) ) 
    391         { 
    392             for ( ExtendedSubunitInfoPageDataVector::iterator it = 
    393                       extSubunitInfoCmd.m_infoPageDatas.begin(); 
    394                   cmdSuccess 
    395                       && ( it != extSubunitInfoCmd.m_infoPageDatas.end() ); 
    396                   ++it ) 
    397             { 
    398                 cmdSuccess = createFunctionBlock( fbType, **it ); 
    399             } 
    400             if ( ( extSubunitInfoCmd.m_infoPageDatas.size() != 0 ) 
    401                  && ( extSubunitInfoCmd.m_infoPageDatas.size() == 5 ) ) 
    402             { 
    403                 page++; 
    404             } else { 
    405                 finished = true; 
    406             } 
    407         } else { 
    408             finished = true; 
    409         } 
    410     } while ( cmdSuccess && !finished ); 
    411  
    412     return cmdSuccess; 
    413 
    414  
    415 bool 
    416 BeBoB::AvDeviceSubunitAudio::createFunctionBlock( 
    417     ExtendedSubunitInfoCmd::EFunctionBlockType fbType, 
    418     ExtendedSubunitInfoPageData& data ) 
    419 
    420     FunctionBlock::ESpecialPurpose purpose 
    421         = convertSpecialPurpose(  data.m_functionBlockSpecialPupose ); 
    422  
    423     FunctionBlock* fb = 0; 
    424  
    425     switch ( fbType ) { 
    426     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector: 
    427     { 
    428         fb = new FunctionBlockSelector( *this, 
    429                                         data.m_functionBlockId, 
    430                                         purpose, 
    431                                         data.m_noOfInputPlugs, 
    432                                         data.m_noOfOutputPlugs, 
    433                                         m_verboseLevel ); 
    434     } 
    435     break; 
    436     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature: 
    437     { 
    438         fb = new FunctionBlockFeature( *this, 
    439                                        data.m_functionBlockId, 
    440                                        purpose, 
    441                                        data.m_noOfInputPlugs, 
    442                                        data.m_noOfOutputPlugs, 
    443                                        m_verboseLevel ); 
    444     } 
    445     break; 
    446     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing: 
    447     { 
    448         switch ( data.m_functionBlockType ) { 
    449         case ExtendedSubunitInfoCmd::ePT_EnhancedMixer: 
    450         { 
    451             fb = new FunctionBlockEnhancedMixer( *this, 
    452                                                  data.m_functionBlockId, 
    453                                                  purpose, 
    454                                                  data.m_noOfInputPlugs, 
    455                                                  data.m_noOfOutputPlugs, 
    456                                                  m_verboseLevel ); 
    457         } 
    458         break; 
    459         case ExtendedSubunitInfoCmd::ePT_Mixer: 
    460         case ExtendedSubunitInfoCmd::ePT_Generic: 
    461         case ExtendedSubunitInfoCmd::ePT_UpDown: 
    462         case ExtendedSubunitInfoCmd::ePT_DolbyProLogic: 
    463         case ExtendedSubunitInfoCmd::ePT_3DStereoExtender: 
    464         case ExtendedSubunitInfoCmd::ePT_Reverberation: 
    465         case ExtendedSubunitInfoCmd::ePT_Chorus: 
    466         case ExtendedSubunitInfoCmd::ePT_DynamicRangeCompression: 
    467         default: 
    468             fb = new FunctionBlockProcessing( *this, 
    469                                               data.m_functionBlockId, 
    470                                               purpose, 
    471                                               data.m_noOfInputPlugs, 
    472                                               data.m_noOfOutputPlugs, 
    473                                               m_verboseLevel ); 
    474             debugWarning( "Dummy function block processing created. " 
    475                           "Implementation is missing\n" ); 
    476         } 
    477     } 
    478     break; 
    479     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec: 
    480     { 
    481         fb = new FunctionBlockCodec( *this, 
    482                                      data.m_functionBlockId, 
    483                                      purpose, 
    484                                      data.m_noOfInputPlugs, 
    485                                      data.m_noOfOutputPlugs, 
    486                                      m_verboseLevel ); 
    487         debugWarning( "Dummy function block codec created. " 
    488                       "Implementation is missing\n" ); 
    489     } 
    490     break; 
    491     default: 
    492         debugError( "Unhandled function block type found\n" ); 
    493         return false; 
    494     } 
    495  
    496     if ( !fb ) { 
    497         debugError( "Could create function block\n" ); 
    498         return false; 
    499     } 
    500     if ( !fb->discover() ) { 
    501         debugError( "Could not discover function block %s\n", 
    502                     fb->getName() ); 
    503         delete fb; 
    504         return false; 
    505     } 
    506     m_functions.push_back( fb ); 
    507  
    508     return true; 
    509 
    510  
    511 BeBoB::FunctionBlock::ESpecialPurpose 
    512 BeBoB::AvDeviceSubunitAudio::convertSpecialPurpose( 
    513     function_block_special_purpose_t specialPurpose ) 
    514 
    515     FunctionBlock::ESpecialPurpose p; 
    516     switch ( specialPurpose ) { 
    517     case ExtendedSubunitInfoPageData::eSP_InputGain: 
    518         p  = FunctionBlock::eSP_InputGain; 
    519         break; 
    520     case ExtendedSubunitInfoPageData::eSP_OutputVolume: 
    521         p = FunctionBlock::eSP_OutputVolume; 
    522     break; 
    523     default: 
    524         p = FunctionBlock::eSP_NoSpecialPurpose; 
    525     } 
    526     return p; 
    527 
    528  
    529 bool 
    530 BeBoB::AvDeviceSubunitAudio::serializeChild( Glib::ustring basePath, 
    531                                              Util::IOSerialize& ser ) const 
    532 
    533     bool result = true; 
    534     int i = 0; 
    535  
    536     for ( FunctionBlockVector::const_iterator it = m_functions.begin(); 
    537           it != m_functions.end(); 
    538           ++it ) 
    539     { 
    540         FunctionBlock* pFB = *it; 
     445        BeBoB::FunctionBlock* pFB = *it; 
    541446        std::ostringstream strstrm; 
    542         strstrm << basePath << "FunctionBlock" << i << "/"; 
     447        strstrm << basePath << "BeBoB::FunctionBlock" << i << "/"; 
    543448 
    544449        result &= pFB->serialize( strstrm.str() , ser ); 
     
    551456 
    552457bool 
    553 BeBoB::AvDeviceSubunitAudio::deserializeChild( Glib::ustring basePath, 
     458SubunitAudio::deserializeChild( Glib::ustring basePath, 
    554459                                               Util::IODeserialize& deser, 
    555                                                AvDevice& avDevice
     460                                               Unit& unit
    556461{ 
    557462    int i = 0; 
     
    559464    do { 
    560465        std::ostringstream strstrm; 
    561         strstrm << basePath << "FunctionBlock" << i << "/"; 
    562         FunctionBlock* pFB = FunctionBlock::deserialize( strstrm.str(), 
     466        strstrm << basePath << "BeBoB::FunctionBlock" << i << "/"; 
     467        BeBoB::FunctionBlock* pFB = BeBoB::FunctionBlock::deserialize( strstrm.str(), 
    563468                                                         deser, 
    564                                                          avDevice
     469                                                         unit
    565470                                                         *this ); 
    566471        if ( pFB ) { 
     
    577482//////////////////////////////////////////// 
    578483 
    579 BeBoB::AvDeviceSubunitMusic::AvDeviceSubunitMusic( AvDevice& avDevice, 
    580                                                    subunit_t id, 
    581                                                    int verboseLevel ) 
    582     : AvDeviceSubunit( avDevice, eST_Music, id, verboseLevel ) 
    583 
    584 
    585  
    586 BeBoB::AvDeviceSubunitMusic::AvDeviceSubunitMusic() 
    587     : AvDeviceSubunit() 
    588 
    589 
    590  
    591 BeBoB::AvDeviceSubunitMusic::~AvDeviceSubunitMusic() 
     484SubunitMusic::SubunitMusic( Unit& unit, subunit_t id ) 
     485    : Subunit( unit, eST_Music, id ) 
     486
     487
     488 
     489SubunitMusic::SubunitMusic() 
     490    : Subunit() 
     491
     492
     493 
     494SubunitMusic::~SubunitMusic() 
    592495{ 
    593496} 
    594497 
    595498const char* 
    596 BeBoB::AvDeviceSubunitMusic::getName() 
     499SubunitMusic::getName() 
    597500{ 
    598501    return "MusicSubunit"; 
     
    600503 
    601504bool 
    602 BeBoB::AvDeviceSubunitMusic::serializeChild( Glib::ustring basePath, 
     505SubunitMusic::serializeChild( Glib::ustring basePath, 
    603506                                             Util::IOSerialize& ser ) const 
    604507{ 
     
    607510 
    608511bool 
    609 BeBoB::AvDeviceSubunitMusic::deserializeChild( Glib::ustring basePath, 
     512SubunitMusic::deserializeChild( Glib::ustring basePath, 
    610513                                               Util::IODeserialize& deser, 
    611                                                AvDevice& avDevice
     514                                               Unit& unit
    612515{ 
    613516    return true; 
    614517} 
     518 
     519} 
  • branches/echoaudio/src/libavc/general/avc_subunit.h

    r503 r507  
    2222 */ 
    2323 
    24 #ifndef BEBOB_AVDEVICESUBUNIT_H 
    25 #define BEBOB_AVDEVICESUBUNIT_H 
     24#ifndef AVC_SUBUNIT_H 
     25#define AVC_SUBUNIT_H 
    2626 
    27 #include "bebob/bebob_avplug.h" 
    28 #include "bebob/bebob_functionblock.h" 
     27#include "avc_plug.h" 
    2928 
    3029#include "debugmodule/debugmodule.h" 
    31 #include "libavc/general/avc_extended_subunit_info.h" 
    32 #include "libavc/avc_definitions.h" 
    33 #include "libavc/general/avc_generic.h" 
     30#include "../general/avc_extended_subunit_info.h" 
     31#include "../avc_definitions.h" 
     32#include "../general/avc_generic.h" 
     33#include "../audiosubunit/avc_function_block.h" 
    3434 
    3535#include <vector> 
    3636 
    37 namespace BeBoB { 
     37#warning merge with bebob functionblock 
     38#include "bebob/bebob_functionblock.h" 
    3839 
    39 class AvDevice; 
     40namespace AVC { 
    4041 
    41 class AvDeviceSubunit { 
     42class Unit; 
     43 
     44 
     45 
     46class Subunit { 
    4247 public: 
    43     AvDeviceSubunit( AvDevice& avDevice, 
    44              AVC::ESubunitType type, 
    45              AVC::subunit_t id, 
    46              int verboseLevel ); 
    47     virtual ~AvDeviceSubunit(); 
     48    Subunit( Unit& avDevice, 
     49             ESubunitType type, 
     50             subunit_t id ); 
     51    virtual ~Subunit(); 
    4852 
    4953    virtual bool discover(); 
    50     virtual bool discoverConnections(); 
     54    virtual bool discoverConnections() 
     55    {//FIXME: 
     56    #warning FIXME 
     57    }; 
     58     
    5159    virtual const char* getName() = 0; 
    5260 
    53     bool addPlug( AvPlug& plug ); 
     61    subunit_t getSubunitId() 
     62    { return m_sbId; } 
     63    ESubunitType getSubunitType() 
     64    { return m_sbType; } 
     65     
     66    bool addPlug( Plug& plug ); 
    5467 
    55     AVC::subunit_t getSubunitId() 
    56     { return m_sbId; } 
    57     AVC::ESubunitType getSubunitType() 
    58     { return m_sbType; } 
    59  
    60     AvPlugVector& getPlugs() 
     68    PlugVector& getPlugs() 
    6169    { return m_plugs; } 
    62     AvPlug* getPlug(AvPlug::EAvPlugDirection direction, AVC::plug_id_t plugId); 
     70    Plug* getPlug(Plug::EPlugDirection direction, plug_id_t plugId); 
    6371 
    6472 
    65     AvDevice& getAvDevice() const 
    66         { return *m_avDevice; } 
     73    Unit& getUnit() const 
     74        { return *m_unit; } 
    6775 
    6876 
    6977    bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 
    70     static AvDeviceSubunit* deserialize( Glib::ustring basePath, 
     78    static Subunit* deserialize( Glib::ustring basePath, 
    7179                     Util::IODeserialize& deser, 
    72                                          AvDevice& avDevice ); 
     80                                         Unit& avDevice ); 
    7381 protected: 
    74     AvDeviceSubunit(); 
     82    Subunit(); 
    7583 
    76     bool discoverPlugs(); 
    77     bool discoverPlugs(AvPlug::EAvPlugDirection plugDirection, 
    78                        AVC::plug_id_t plugMaxId ); 
    79  
     84//     bool discoverPlugs(); 
     85//     bool discoverPlugs(Plug::EPlugDirection plugDirection, 
     86//                        plug_id_t plugMaxId ); 
     87//  
    8088    virtual bool serializeChild( Glib::ustring basePath, 
    8189                                 Util::IOSerialize& ser ) const = 0; 
    8290    virtual bool deserializeChild( Glib::ustring basePath, 
    8391                                   Util::IODeserialize& deser, 
    84                                    AvDevice& avDevice ) = 0; 
     92                                   Unit& avDevice ) = 0; 
    8593 
    8694 protected: 
    87     AvDevice*                m_avDevice; 
    88     AVC::ESubunitType m_sbType; 
    89     AVC::subunit_t                m_sbId; 
    90     int                      m_verboseLevel; 
     95    Unit*           m_unit; 
     96    ESubunitType    m_sbType; 
     97    subunit_t       m_sbId; 
    9198 
    92     AvPlugVector             m_plugs; 
     99    PlugVector             m_plugs; 
    93100 
    94101    DECLARE_DEBUG_MODULE; 
    95102}; 
    96103 
    97 typedef std::vector<AvDeviceSubunit*> AvDeviceSubunitVector; 
     104typedef std::vector<Subunit*> SubunitVector; 
    98105 
    99 ///////////////////////////// 
     106// ///////////////////////////// 
    100107 
    101 class AvDeviceSubunitAudio: public AvDeviceSubunit { 
     108class SubunitAudio: public Subunit { 
    102109 public: 
    103     AvDeviceSubunitAudio( AvDevice& avDevice, 
    104               AVC::subunit_t id, 
    105               int verboseLevel ); 
    106     AvDeviceSubunitAudio(); 
    107     virtual ~AvDeviceSubunitAudio(); 
     110    SubunitAudio( Unit& avDevice, 
     111                  subunit_t id ); 
     112    SubunitAudio(); 
     113    virtual ~SubunitAudio(); 
    108114 
    109115    virtual bool discover(); 
    110     virtual bool discoverConnections(); 
    111  
     116//     virtual bool discoverConnections(); 
     117//  
    112118    virtual const char* getName(); 
    113  
    114     FunctionBlockVector getFunctionBlocks() { return m_functions; }; 
    115      
    116 protected: 
    117     bool discoverFunctionBlocks(); 
    118     bool discoverFunctionBlocksDo( 
    119         AVC::ExtendedSubunitInfoCmd::EFunctionBlockType fbType ); 
    120     bool createFunctionBlock( 
    121         AVC::ExtendedSubunitInfoCmd::EFunctionBlockType fbType, 
    122         AVC::ExtendedSubunitInfoPageData& data ); 
    123  
    124     FunctionBlock::ESpecialPurpose convertSpecialPurpose( 
    125         AVC::function_block_special_purpose_t specialPurpose ); 
     119//  
     120    BeBoB::FunctionBlockVector getFunctionBlocks() { return m_functions; }; 
     121//      
     122// protected: 
     123//     bool discoverFunctionBlocks(); 
     124//     bool discoverFunctionBlocksDo( 
     125//         ExtendedSubunitInfoCmd::EFunctionBlockType fbType ); 
     126//     bool createFunctionBlock( 
     127//         ExtendedSubunitInfoCmd::EFunctionBlockType fbType, 
     128//         ExtendedSubunitInfoPageData& data ); 
     129//  
     130//     FunctionBlock::ESpecialPurpose convertSpecialPurpose( 
     131//         function_block_special_purpose_t specialPurpose ); 
    126132 
    127133    virtual bool serializeChild( Glib::ustring basePath, 
     
    129135    virtual bool deserializeChild( Glib::ustring basePath, 
    130136                                   Util::IODeserialize& deser, 
    131                                    AvDevice& avDevice ); 
     137                                   Unit& avDevice ); 
    132138 
    133139protected: 
    134     FunctionBlockVector m_functions; 
     140    BeBoB::FunctionBlockVector m_functions; 
    135141}; 
    136142 
    137 ///////////////////////////// 
     143// ///////////////////////////// 
    138144 
    139 class AvDeviceSubunitMusic: public AvDeviceSubunit { 
     145class SubunitMusic: public Subunit { 
    140146 public: 
    141     AvDeviceSubunitMusic( AvDevice& avDevice, 
    142               AVC::subunit_t id, 
    143               int verboseLevel ); 
    144     AvDeviceSubunitMusic(); 
    145     virtual ~AvDeviceSubunitMusic(); 
     147    SubunitMusic( Unit& avDevice, 
     148              subunit_t id ); 
     149    SubunitMusic(); 
     150    virtual ~SubunitMusic(); 
    146151 
    147152    virtual const char* getName(); 
     
    152157    virtual bool deserializeChild( Glib::ustring basePath, 
    153158                                   Util::IODeserialize& deser, 
    154                                    AvDevice& avDevice ); 
     159                                   Unit& avDevice ); 
    155160}; 
    156161 
  • branches/echoaudio/src/libavc/general/avc_unit.cpp

    r504 r507  
    11/* 
     2 * Copyright (C)      2007 by Pieter Palmers 
    23 * Copyright (C) 2005-2007 by Daniel Wagner 
    34 * 
     
    2223 */ 
    2324 
    24 #include "bebob/bebob_avdevice.h" 
    25 #include "bebob/bebob_avdevice_subunit.h" 
    26 #include "bebob/GenericMixer.h" 
     25#include "avc_unit.h" 
     26#include "avc_subunit.h" 
     27#include "avc_plug.h" 
    2728 
    2829#include "libieee1394/configrom.h" 
    2930#include "libieee1394/ieee1394service.h" 
    3031 
    31 #include "libavc/general/avc_plug_info.h" 
    32 #include "libavc/general/avc_extended_plug_info.h" 
    33 #include "libavc/general/avc_subunit_info.h" 
    34 #include "libavc/streamformat/avc_extended_stream_format.h" 
    35 #include "libavc/util/avc_serialize.h" 
    36 #include "libavc/avc_definitions.h" 
     32#include "../general/avc_plug_info.h" 
     33#include "../general/avc_extended_plug_info.h" 
     34#include "../general/avc_subunit_info.h" 
     35#include "../streamformat/avc_extended_stream_format.h" 
     36#include "../util/avc_serialize.h" 
     37#include "../avc_definitions.h" 
    3738 
    3839#include "debugmodule/debugmodule.h" 
     
    4142#include <sstream> 
    4243 
    43 using namespace AVC; 
    44  
    45 namespace BeBoB { 
    46  
    47 static VendorModelEntry supportedDeviceList[] = 
    48 
    49     {0x00000f, 0x00010065, "Mackie", "Onyx Firewire"}, 
    50  
    51     {0x0003db, 0x00010048, "Apogee Electronics", "Rosetta 200"}, 
    52  
    53     {0x0007f5, 0x00010048, "BridgeCo", "RD Audio1"}, 
    54  
    55     {0x000a92, 0x00010000, "PreSonus", "FIREBOX"}, 
    56     {0x000a92, 0x00010066, "PreSonus", "FirePOD"}, 
    57  
    58     {0x000aac, 0x00000003, "TerraTec Electronic GmbH", "Phase 88 FW"}, 
    59     {0x000aac, 0x00000004, "TerraTec Electronic GmbH", "Phase X24 FW (model version 4)"}, 
    60     {0x000aac, 0x00000007, "TerraTec Electronic GmbH", "Phase X24 FW (model version 7)"}, 
    61  
    62     {0x000f1b, 0x00010064, "ESI", "Quatafire 610"}, 
    63  
    64     {0x00130e, 0x00000003, "Focusrite", "Saffire Pro26IO"}, 
    65     {0x00130e, 0x00000006, "Focusrite", "Saffire Pro10IO"},  
    66  
    67     {0x0040ab, 0x00010048, "EDIROL", "FA-101"}, 
    68     {0x0040ab, 0x00010049, "EDIROL", "FA-66"}, 
    69 }; 
    70  
    71 AvDevice::AvDevice( std::auto_ptr< ConfigRom >( configRom ), 
    72                     Ieee1394Service& ieee1394service, 
    73                     int nodeId ) 
    74     : FFADODevice( configRom, ieee1394service, nodeId ) 
    75     , m_pPlugManager( new AvPlugManager( DEBUG_LEVEL_NORMAL ) ) 
     44namespace AVC { 
     45 
     46IMPL_DEBUG_MODULE( Unit, Unit, DEBUG_LEVEL_VERBOSE ); 
     47 
     48Unit::Unit( std::auto_ptr< ConfigRom >( configRom ), 
     49                  Ieee1394Service& ieee1394service, 
     50                  int nodeId ) 
     51    : m_pPlugManager( new PlugManager( ) ) 
    7652    , m_activeSyncInfo( 0 ) 
    77     , m_model ( NULL
    78     , m_Mixer ( NULL
    79 { 
    80     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::AvDevice (NodeID %d)\n", 
     53    , m_puConfigRom( configRom
     54    , m_pu1394Service( &ieee1394service
     55{ 
     56    debugOutput( DEBUG_LEVEL_VERBOSE, "Created AVC::Unit (NodeID %d)\n", 
    8157                 nodeId ); 
    82     addOption(Util::OptionContainer::Option("snoopMode",false)); 
    83 
    84  
    85 AvDevice::~AvDevice() 
    86 
    87     if(m_Mixer != NULL) { 
    88         if (!removeChildOscNode(m_Mixer)) { 
    89             debugWarning("failed to unregister mixer from OSC namespace\n"); 
    90         } 
    91         delete m_Mixer; 
    92     } 
    93  
    94     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); 
     58
     59 
     60Unit::~Unit() 
     61
     62    for ( SubunitVector::iterator it = m_subunits.begin(); 
    9563          it != m_subunits.end(); 
    9664          ++it ) 
     
    9866        delete *it; 
    9967    } 
    100     for ( AvPlugConnectionVector::iterator it = m_plugConnections.begin(); 
     68    for ( PlugConnectionVector::iterator it = m_plugConnections.begin(); 
    10169          it != m_plugConnections.end(); 
    10270          ++it ) 
     
    10472        delete *it; 
    10573    } 
    106     for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); 
     74    for ( PlugVector::iterator it = m_pcrPlugs.begin(); 
    10775          it != m_pcrPlugs.end(); 
    10876          ++it ) 
     
    11078        delete *it; 
    11179    } 
    112     for ( AvPlugVector::iterator it = m_externalPlugs.begin(); 
     80    for ( PlugVector::iterator it = m_externalPlugs.begin(); 
    11381          it != m_externalPlugs.end(); 
    11482          ++it ) 
     
    11987 
    12088void 
    121 AvDevice::setVerboseLevel(int l) 
    122 
    123 //     m_pPlugManager->setVerboseLevel(l); 
    124  
    125     FFADODevice::setVerboseLevel(l); 
     89Unit::setVerboseLevel(int l) 
     90
     91    m_pPlugManager->setVerboseLevel(l); 
    12692} 
    12793 
    12894bool 
    129 AvDevice::probe( ConfigRom& configRom ) 
    130 
    131     unsigned int vendorId = configRom.getNodeVendorId(); 
    132     unsigned int modelId = configRom.getModelId(); 
    133  
    134     for ( unsigned int i = 0; 
    135           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); 
    136           ++i ) 
    137     { 
    138         if ( ( supportedDeviceList[i].vendor_id == vendorId ) 
    139              && ( supportedDeviceList[i].model_id == modelId ) ) 
    140         { 
    141             return true; 
    142         } 
    143     } 
    144  
    145     return false; 
    146 
    147  
    148 bool 
    149 AvDevice::discover() 
    150 
    151     unsigned int vendorId = m_pConfigRom->getNodeVendorId(); 
    152     unsigned int modelId = m_pConfigRom->getModelId(); 
    153  
    154     for ( unsigned int i = 0; 
    155           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); 
    156           ++i ) 
    157     { 
    158         if ( ( supportedDeviceList[i].vendor_id == vendorId ) 
    159              && ( supportedDeviceList[i].model_id == modelId ) 
    160            ) 
    161         { 
    162             m_model = &(supportedDeviceList[i]); 
    163             break; 
    164         } 
    165     } 
    166  
    167     if (m_model != NULL) { 
    168         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 
    169                 m_model->vendor_name, m_model->model_name); 
    170     } else return false; 
     95Unit::discover() 
     96
    17197 
    17298    if ( !enumerateSubUnits() ) { 
     
    175101    } 
    176102 
    177     if ( !discoverPlugs() ) { 
    178         debugError( "Detecting plugs failed\n" ); 
    179         return false; 
    180     } 
    181  
    182     if ( !discoverPlugConnections() ) { 
    183         debugError( "Detecting plug connections failed\n" ); 
    184         return false; 
    185     } 
    186  
    187     if ( !discoverSubUnitsPlugConnections() ) { 
    188         debugError( "Detecting plug connnection failed\n" ); 
    189         return false; 
    190     } 
    191  
    192     if ( !discoverSyncModes() ) { 
    193         debugError( "Detecting sync modes failed\n" ); 
    194         return false; 
    195     } 
    196  
    197     // create a GenericMixer and add it as an OSC child node 
    198     //  remove if already there 
    199     if(m_Mixer != NULL) { 
    200         if (!removeChildOscNode(m_Mixer)) { 
    201             debugWarning("failed to unregister mixer from OSC namespace\n"); 
    202         } 
    203         delete m_Mixer; 
    204     } 
    205      
    206     //  create the mixer & register it 
    207     if(getAudioSubunit(0) == NULL) { 
    208         debugWarning("Could not find audio subunit, mixer not available.\n"); 
    209         m_Mixer = NULL; 
    210     } else { 
    211         m_Mixer = new GenericMixer(*m_p1394Service , *this); 
    212         if (!addChildOscNode(m_Mixer)) { 
    213             debugWarning("failed to register mixer in OSC namespace\n"); 
    214         } 
    215     } 
    216103    return true; 
    217104} 
    218105 
    219106bool 
    220 AvDevice::discoverPlugs() 
    221 
    222     ////////////////////////////////////////////// 
    223     // Get number of available isochronous input 
    224     // and output plugs of unit 
    225  
    226     PlugInfoCmd plugInfoCmd( *m_p1394Service ); 
    227     plugInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    228     plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    229     plugInfoCmd.setVerbose( m_verboseLevel ); 
    230  
    231     if ( !plugInfoCmd.fire() ) { 
    232         debugError( "plug info command failed\n" ); 
    233         return false; 
    234     } 
    235  
    236     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n", 
    237                  plugInfoCmd.m_serialBusIsochronousInputPlugs ); 
    238     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n", 
    239                  plugInfoCmd.m_serialBusIsochronousOutputPlugs ); 
    240     debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n", 
    241                  plugInfoCmd.m_externalInputPlugs ); 
    242     debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n", 
    243                  plugInfoCmd.m_externalOutputPlugs ); 
    244  
    245     if ( !discoverPlugsPCR( AvPlug::eAPD_Input, 
    246                             plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) 
    247     { 
    248         debugError( "pcr input plug discovering failed\n" ); 
    249         return false; 
    250     } 
    251  
    252     if ( !discoverPlugsPCR( AvPlug::eAPD_Output, 
    253                             plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) 
    254     { 
    255         debugError( "pcr output plug discovering failed\n" ); 
    256         return false; 
    257     } 
    258  
    259     if ( !discoverPlugsExternal( AvPlug::eAPD_Input, 
    260                                  plugInfoCmd.m_externalInputPlugs ) ) 
    261     { 
    262         debugError( "external input plug discovering failed\n" ); 
    263         return false; 
    264     } 
    265  
    266     if ( !discoverPlugsExternal( AvPlug::eAPD_Output, 
    267                                  plugInfoCmd.m_externalOutputPlugs ) ) 
    268     { 
    269         debugError( "external output plug discovering failed\n" ); 
    270         return false; 
    271     } 
    272  
    273     return true; 
    274 
    275  
    276 bool 
    277 AvDevice::discoverPlugsPCR( AvPlug::EAvPlugDirection plugDirection, 
    278                             plug_id_t plugMaxId ) 
    279 
    280     for ( int plugId = 0; 
    281           plugId < plugMaxId; 
    282           ++plugId ) 
    283     { 
    284         AvPlug* plug  = new AvPlug( *m_p1394Service, 
    285                                     *m_pConfigRom, 
    286                                     *m_pPlugManager, 
    287                                     eST_Unit, 
    288                                     0xff, 
    289                                     0xff, 
    290                                     0xff, 
    291                                     AvPlug::eAPA_PCR, 
    292                                     plugDirection, 
    293                                     plugId, 
    294                                     m_verboseLevel ); 
    295         if ( !plug || !plug->discover() ) { 
    296             debugError( "plug discovering failed\n" ); 
    297             delete plug; 
    298             return false; 
    299         } 
    300  
    301         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    302                      plug->getName() ); 
    303         m_pcrPlugs.push_back( plug ); 
    304     } 
    305  
    306     return true; 
    307 
    308  
    309 bool 
    310 AvDevice::discoverPlugsExternal( AvPlug::EAvPlugDirection plugDirection, 
    311                                  plug_id_t plugMaxId ) 
    312 
    313     for ( int plugId = 0; 
    314           plugId < plugMaxId; 
    315           ++plugId ) 
    316     { 
    317         AvPlug* plug  = new AvPlug( *m_p1394Service, 
    318                                     *m_pConfigRom, 
    319                                     *m_pPlugManager, 
    320                                     eST_Unit, 
    321                                     0xff, 
    322                                     0xff, 
    323                                     0xff, 
    324                                     AvPlug::eAPA_ExternalPlug, 
    325                                     plugDirection, 
    326                                     plugId, 
    327                                     m_verboseLevel ); 
    328         if ( !plug || !plug->discover() ) { 
    329             debugError( "plug discovering failed\n" ); 
    330             return false; 
    331         } 
    332  
    333         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 
    334                      plug->getName() ); 
    335         m_externalPlugs.push_back( plug ); 
    336     } 
    337  
    338     return true; 
    339 
    340  
    341 bool 
    342 AvDevice::discoverPlugConnections() 
    343 
    344     for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); 
    345           it != m_pcrPlugs.end(); 
    346           ++it ) 
    347     { 
    348         AvPlug* plug = *it; 
    349         if ( !plug->discoverConnections() ) { 
    350             debugError( "Could not discover plug connections\n" ); 
    351             return false; 
    352         } 
    353     } 
    354     for ( AvPlugVector::iterator it = m_externalPlugs.begin(); 
    355           it != m_externalPlugs.end(); 
    356           ++it ) 
    357     { 
    358         AvPlug* plug = *it; 
    359         if ( !plug->discoverConnections() ) { 
    360             debugError( "Could not discover plug connections\n" ); 
    361             return false; 
    362         } 
    363     } 
    364  
    365     return true; 
    366 
    367  
    368 bool 
    369 AvDevice::discoverSubUnitsPlugConnections() 
    370 
    371     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); 
    372           it != m_subunits.end(); 
    373           ++it ) 
    374     { 
    375         AvDeviceSubunit* subunit = *it; 
    376         if ( !subunit->discoverConnections() ) { 
    377             debugError( "Subunit '%s'  plug connections failed\n", 
    378                         subunit->getName() ); 
    379             return false; 
    380         } 
    381     } 
    382     return true; 
    383 
    384  
    385 bool 
    386 AvDevice::discoverSyncModes() 
    387 
    388     // Following possible sync plugs exists: 
    389     // - Music subunit sync output plug = internal sync (CSP) 
    390     // - Unit input plug 0 = SYT match 
    391     // - Unit input plut 1 = Sync stream 
    392     // 
    393     // If last sync mode is reported it is mostelikely not 
    394     // implemented *sic* 
    395     // 
    396     // Following sync sources are device specific: 
    397     // - All unit external input plugs which have a 
    398     //   sync information (WS, SPDIF, ...) 
    399  
    400     // First we have to find the sync input and output plug 
    401     // in the music subunit. 
    402  
    403     // Note PCR input means 1394bus-to-device where as 
    404     // MSU input means subunit-to-device 
    405  
    406     AvPlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    407                                                      AvPlug::eAPD_Input, 
    408                                                      AvPlug::eAPT_Sync ); 
    409     if ( !syncPCRInputPlugs.size() ) { 
    410         debugWarning( "No PCR sync input plug found\n" ); 
    411     } 
    412  
    413     AvPlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    414                                                       AvPlug::eAPD_Output, 
    415                                                       AvPlug::eAPT_Sync ); 
    416     if ( !syncPCROutputPlugs.size() ) { 
    417         debugWarning( "No PCR sync output plug found\n" ); 
    418     } 
    419  
    420     AvPlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 
    421                                                     AvPlug::eAPD_Input, 
    422                                                     AvPlug::eAPT_IsoStream ); 
    423     if ( !isoPCRInputPlugs.size() ) { 
    424         debugWarning( "No PCR iso input plug found\n" ); 
    425  
    426     } 
    427  
    428     AvPlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 
    429                                                     AvPlug::eAPD_Output, 
    430                                                     AvPlug::eAPT_IsoStream ); 
    431     if ( !isoPCROutputPlugs.size() ) { 
    432         debugWarning( "No PCR iso output plug found\n" ); 
    433  
    434     } 
    435  
    436     AvPlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 
    437                                                     AvPlug::eAPD_Input, 
    438                                                     AvPlug::eAPT_Digital ); 
    439  
    440     AvPlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
    441         eST_Music, 
    442         0, 
    443         0xff, 
    444         0xff, 
    445         AvPlug::eAPA_SubunitPlug, 
    446         AvPlug::eAPD_Input, 
    447         AvPlug::eAPT_Sync ); 
    448     if ( !syncMSUInputPlugs.size() ) { 
    449         debugWarning( "No sync input plug for MSU subunit found\n" ); 
    450     } 
    451  
    452     AvPlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 
    453         eST_Music, 
    454         0, 
    455         0xff, 
    456         0xff, 
    457         AvPlug::eAPA_SubunitPlug, 
    458         AvPlug::eAPD_Output, 
    459         AvPlug::eAPT_Sync ); 
    460     if ( !syncMSUOutputPlugs.size() ) { 
    461         debugWarning( "No sync output plug for MSU subunit found\n" ); 
    462     } 
    463  
    464     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); 
    465     showAvPlugs( syncPCRInputPlugs ); 
    466     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); 
    467     showAvPlugs( syncPCROutputPlugs ); 
    468     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); 
    469     showAvPlugs( isoPCRInputPlugs ); 
    470     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); 
    471     showAvPlugs( isoPCROutputPlugs ); 
    472     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); 
    473     showAvPlugs( digitalPCRInputPlugs ); 
    474     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); 
    475     showAvPlugs( syncMSUInputPlugs ); 
    476     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); 
    477     showAvPlugs( syncMSUOutputPlugs ); 
    478  
    479     // Check all possible PCR input to MSU input connections 
    480     // -> sync stream input 
    481     checkSyncConnectionsAndAddToList( syncPCRInputPlugs, 
    482                                       syncMSUInputPlugs, 
    483                                       "Sync Stream Input" ); 
    484  
    485     // Check all possible MSU output to PCR output connections 
    486     // -> sync stream output 
    487     checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
    488                                       syncPCROutputPlugs, 
    489                                       "Sync Stream Output" ); 
    490  
    491     // Check all PCR iso input to MSU input connections 
    492     // -> SYT match 
    493     checkSyncConnectionsAndAddToList( isoPCRInputPlugs, 
    494                                       syncMSUInputPlugs, 
    495                                       "Syt Match" ); 
    496  
    497     // Check all MSU sync output to MSU input connections 
    498     // -> CSP 
    499     checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 
    500                                       syncMSUInputPlugs, 
    501                                       "Internal (CSP)" ); 
    502  
    503     // Check all external PCR digital input to MSU input connections 
    504     // -> SPDIF/ADAT sync 
    505     checkSyncConnectionsAndAddToList( digitalPCRInputPlugs, 
    506                                       syncMSUInputPlugs, 
    507                                       "Digital Input Sync" ); 
    508  
    509     // Currently active connection signal source cmd, command type 
    510     // status, source unknown, destination MSU sync input plug 
    511  
    512     for ( AvPlugVector::const_iterator it = syncMSUInputPlugs.begin(); 
    513           it != syncMSUInputPlugs.end(); 
    514           ++it ) 
    515     { 
    516         AvPlug* msuPlug = *it; 
    517         for ( AvPlugVector::const_iterator jt = 
    518                   msuPlug->getInputConnections().begin(); 
    519               jt != msuPlug->getInputConnections().end(); 
    520               ++jt ) 
    521         { 
    522             AvPlug* plug = *jt; 
    523  
    524             for ( SyncInfoVector::iterator it = m_syncInfos.begin(); 
    525                   it != m_syncInfos.end(); 
    526                   ++it ) 
    527             { 
    528                 SyncInfo* pSyncInfo = &*it; 
    529                 if ( ( pSyncInfo->m_source == plug ) 
    530                      && ( pSyncInfo->m_destination == msuPlug ) ) 
    531                 { 
    532                     m_activeSyncInfo = pSyncInfo; 
    533                     break; 
    534                 } 
    535             } 
    536             debugOutput( DEBUG_LEVEL_NORMAL, 
    537                          "Active Sync Connection: '%s' -> '%s'\n", 
    538                          plug->getName(), 
    539                          msuPlug->getName() ); 
    540         } 
    541     } 
    542  
    543     return true; 
    544 
    545  
    546 bool 
    547 AvDevice::enumerateSubUnits() 
    548 
    549     bool musicSubunitFound=false; 
    550     bool audioSubunitFound=false; 
    551  
    552     SubUnitInfoCmd subUnitInfoCmd( *m_p1394Service ); 
    553     //subUnitInfoCmd.setVerbose( 1 ); 
     107Unit::enumerateSubUnits() 
     108
     109    SubUnitInfoCmd subUnitInfoCmd( *m_pu1394Service ); 
    554110    subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status ); 
    555111 
    556     // BeBoB has always exactly one audio and one music subunit. This 
     112    // NOTE: BeBoB has always exactly one audio and one music subunit. This 
    557113    // means is fits into the first page of the SubUnitInfo command. 
    558114    // So there is no need to do more than needed 
     115    // FIXME: to be fully spec compliant this needs to be fixed, but let's not 
     116    //        do that for now 
    559117 
    560118    subUnitInfoCmd.m_page = 0; 
    561     subUnitInfoCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    562     subUnitInfoCmd.setVerbose( m_verboseLevel ); 
     119    subUnitInfoCmd.setNodeId( m_puConfigRom->getNodeId() ); 
     120    subUnitInfoCmd.setVerbose( getDebugLevel() ); 
    563121    if ( !subUnitInfoCmd.fire() ) { 
    564122        debugError( "Subunit info command failed\n" ); 
     
    579137                     subunitTypeToString( subunit_type ) ); 
    580138 
    581         AvDeviceSubunit* subunit = 0; 
     139        Subunit* subunit = 0; 
    582140        switch( subunit_type ) { 
    583141        case eST_Audio: 
    584             subunit = new AvDeviceSubunitAudio( *this, 
    585                                                 subunitId, 
    586                                                 m_verboseLevel ); 
     142            subunit = new SubunitAudio( *this, 
     143                                                subunitId ); 
    587144            if ( !subunit ) { 
    588                 debugFatal( "Could not allocate AvDeviceSubunitAudio\n" ); 
    589                 return false; 
    590             } 
    591             if ( !subunit ) { 
    592                 debugFatal( "Could not allocate AvDeviceSubunitMusic\n" ); 
     145                debugFatal( "Could not allocate SubunitAudio\n" ); 
    593146                return false; 
    594147            } 
     
    604157            } else { 
    605158                m_subunits.push_back( subunit ); 
    606                 audioSubunitFound=true; 
    607159            } 
    608160             
    609161            break; 
    610162        case eST_Music: 
    611             subunit = new AvDeviceSubunitMusic( *this, 
    612                                                 subunitId, 
    613                                                 m_verboseLevel ); 
     163            subunit = new SubunitMusic( *this, 
     164                                        subunitId ); 
    614165            if ( !subunit ) { 
    615                 debugFatal( "Could not allocate AvDeviceSubunitMusic\n" ); 
     166                debugFatal( "Could not allocate SubunitMusic\n" ); 
    616167                return false; 
    617168            } 
     
    626177            } else { 
    627178                m_subunits.push_back( subunit ); 
    628                 musicSubunitFound=true; 
    629179            } 
    630180 
     
    638188 
    639189        } 
    640  
    641     } 
    642  
    643     // a BeBoB always has an audio and a music subunit 
    644     return (musicSubunitFound && audioSubunitFound); 
    645 
    646  
    647  
    648 AvDeviceSubunit* 
    649 AvDevice::getSubunit( subunit_type_t subunitType, 
     190    } 
     191 
     192    return true; 
     193
     194 
     195Subunit* 
     196Unit::getSubunit( subunit_type_t subunitType, 
    650197                      subunit_id_t subunitId ) const 
    651198{ 
    652     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); 
     199    for ( SubunitVector::const_iterator it = m_subunits.begin(); 
    653200          it != m_subunits.end(); 
    654201          ++it ) 
    655202    { 
    656         AvDeviceSubunit* subunit = *it; 
     203        Subunit* subunit = *it; 
    657204        if ( ( subunitType == subunit->getSubunitType() ) 
    658205             && ( subunitId == subunit->getSubunitId() ) ) 
     
    665212} 
    666213 
    667  
    668214unsigned int 
    669 AvDevice::getNrOfSubunits( subunit_type_t subunitType ) const 
     215Unit::getNrOfSubunits( subunit_type_t subunitType ) const 
    670216{ 
    671217    unsigned int nrOfSubunits = 0; 
    672218 
    673     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); 
     219    for ( SubunitVector::const_iterator it = m_subunits.begin(); 
    674220          it != m_subunits.end(); 
    675221          ++it ) 
    676222    { 
    677         AvDeviceSubunit* subunit = *it; 
     223        Subunit* subunit = *it; 
    678224        if ( subunitType == subunit->getSubunitType() ) { 
    679225            nrOfSubunits++; 
     
    684230} 
    685231 
    686 AvPlugConnection* 
    687 AvDevice::getPlugConnection( AvPlug& srcPlug ) const 
    688 { 
    689     for ( AvPlugConnectionVector::const_iterator it 
     232PlugConnection* 
     233Unit::getPlugConnection( Plug& srcPlug ) const 
     234{ 
     235    for ( PlugConnectionVector::const_iterator it 
    690236              = m_plugConnections.begin(); 
    691237          it != m_plugConnections.end(); 
    692238          ++it ) 
    693239    { 
    694         AvPlugConnection* plugConnection = *it; 
     240        PlugConnection* plugConnection = *it; 
    695241        if ( &( plugConnection->getSrcPlug() ) == &srcPlug ) { 
    696242            return plugConnection; 
     
    701247} 
    702248 
    703 AvPlug* 
    704 AvDevice::getPlugById( AvPlugVector& plugs, 
    705                        AvPlug::EAvPlugDirection plugDirection, 
     249Plug* 
     250Unit::getPlugById( PlugVector& plugs, 
     251                       Plug::EPlugDirection plugDirection, 
    706252                       int id ) 
    707253{ 
    708     for ( AvPlugVector::iterator it = plugs.begin(); 
     254    for ( PlugVector::iterator it = plugs.begin(); 
    709255          it != plugs.end(); 
    710256          ++it ) 
    711257    { 
    712         AvPlug* plug = *it; 
     258        Plug* plug = *it; 
    713259        if ( ( id == plug->getPlugId() ) 
    714260             && ( plugDirection == plug->getPlugDirection() ) ) 
     
    721267} 
    722268 
    723 AvPlugVector 
    724 AvDevice::getPlugsByType( AvPlugVector& plugs, 
    725                           AvPlug::EAvPlugDirection plugDirection, 
    726                           AvPlug::EAvPlugType type) 
    727 { 
    728     AvPlugVector plugVector; 
    729     for ( AvPlugVector::iterator it = plugs.begin(); 
     269PlugVector 
     270Unit::getPlugsByType( PlugVector& plugs, 
     271                          Plug::EPlugDirection plugDirection, 
     272                          Plug::EPlugType type) 
     273{ 
     274    PlugVector plugVector; 
     275    for ( PlugVector::iterator it = plugs.begin(); 
    730276          it != plugs.end(); 
    731277          ++it ) 
    732278    { 
    733         AvPlug* plug = *it; 
     279        Plug* plug = *it; 
    734280        if ( ( type == plug->getPlugType() ) 
    735281             && ( plugDirection == plug->getPlugDirection() ) ) 
     
    742288} 
    743289 
    744 AvPlug* 
    745 AvDevice::getSyncPlug( int maxPlugId, AvPlug::EAvPlugDirection ) 
     290Plug* 
     291Unit::getSyncPlug( int maxPlugId, Plug::EPlugDirection ) 
    746292{ 
    747293    return 0; 
    748294} 
    749295 
    750 bool 
    751 AvDevice::setSamplingFrequency( int s ) 
    752 
    753     ESamplingFrequency samplingFrequency=parseSampleRate( s ); 
    754     bool snoopMode=false; 
    755     if(!getOption("snoopMode", snoopMode)) { 
    756         debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
    757     } 
    758  
    759     if(snoopMode) { 
    760         int current_sr=getSamplingFrequency(); 
    761         if (current_sr != convertESamplingFrequency( samplingFrequency ) ) { 
    762             debugError("In snoop mode it is impossible to set the sample rate.\n"); 
    763             debugError("Please start the client with the correct setting.\n"); 
    764             return false; 
    765         } 
    766         return true; 
    767     } else { 
    768         AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
    769         if ( !plug ) { 
    770             debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    771             return false; 
    772         } 
    773  
    774         if ( !setSamplingFrequencyPlug( *plug, 
    775                                         AvPlug::eAPD_Input, 
    776                                         samplingFrequency ) ) 
    777         { 
    778             debugError( "setSampleRate: Setting sample rate failed\n" ); 
    779             return false; 
    780         } 
    781  
    782         plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output,  0 ); 
    783         if ( !plug ) { 
    784             debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
    785             return false; 
    786         } 
    787  
    788         if ( !setSamplingFrequencyPlug( *plug, 
    789                                         AvPlug::eAPD_Output, 
    790                                         samplingFrequency ) ) 
    791         { 
    792             debugError( "setSampleRate: Setting sample rate failed\n" ); 
    793             return false; 
    794         } 
    795  
    796         debugOutput( DEBUG_LEVEL_VERBOSE, 
    797                      "setSampleRate: Set sample rate to %d\n", 
    798                      convertESamplingFrequency( samplingFrequency ) ); 
    799         return true; 
    800     } 
    801     // not executable 
    802     return false; 
    803 
    804  
    805 int 
    806 AvDevice::getSamplingFrequency( ) { 
    807     AvPlug* inputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); 
    808     if ( !inputPlug ) { 
    809         debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    810         return false; 
    811     } 
    812     AvPlug* outputPlug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output, 0 ); 
    813     if ( !outputPlug ) { 
    814         debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
    815         return false; 
    816     } 
    817  
    818     int samplerate_playback=inputPlug->getSampleRate(); 
    819     int samplerate_capture=outputPlug->getSampleRate(); 
    820  
    821     if (samplerate_playback != samplerate_capture) { 
    822         debugWarning("Samplerates for capture and playback differ!\n"); 
    823     } 
    824     return samplerate_capture; 
    825 
    826  
    827  
    828 bool 
    829 AvDevice::setSamplingFrequencyPlug( AvPlug& plug, 
    830                                     AvPlug::EAvPlugDirection direction, 
    831                                     ESamplingFrequency samplingFrequency ) 
    832 
    833  
    834     ExtendedStreamFormatCmd extStreamFormatCmd( 
    835         *m_p1394Service, 
    836         ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList ); 
    837     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 
    838                                      plug.getPlugId() ); 
    839  
    840     extStreamFormatCmd.setPlugAddress( 
    841         PlugAddress( 
    842             AvPlug::convertPlugDirection(direction ), 
    843             PlugAddress::ePAM_Unit, 
    844             unitPlugAddress ) ); 
    845  
    846     extStreamFormatCmd.setNodeId( m_pConfigRom->getNodeId() ); 
    847     extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
    848  
     296void 
     297Unit::showDevice() 
     298
     299    m_pPlugManager->showPlugs(); 
     300
     301 
     302void 
     303Unit::showPlugs( PlugVector& plugs ) const 
     304
    849305    int i = 0; 
    850     bool cmdSuccess = false; 
    851     bool correctFormatFound = false; 
    852  
    853     do { 
    854         extStreamFormatCmd.setIndexInStreamFormat( i ); 
    855         extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 
    856         extStreamFormatCmd.setVerbose( m_verboseLevel ); 
    857  
    858         cmdSuccess = extStreamFormatCmd.fire(); 
    859  
    860         if ( cmdSuccess 
    861              && ( extStreamFormatCmd.getResponse() == 
    862                   AVCCommand::eR_Implemented ) ) 
    863         { 
    864             ESamplingFrequency foundFreq = eSF_DontCare; 
    865  
    866             FormatInformation* formatInfo = 
    867                 extStreamFormatCmd.getFormatInformation(); 
    868             FormatInformationStreamsCompound* compoundStream 
    869                 = dynamic_cast< FormatInformationStreamsCompound* > ( 
    870                     formatInfo->m_streams ); 
    871             if ( compoundStream ) { 
    872                 foundFreq = 
    873                     static_cast< ESamplingFrequency >( 
    874                         compoundStream->m_samplingFrequency ); 
    875             } 
    876  
    877             FormatInformationStreamsSync* syncStream 
    878                 = dynamic_cast< FormatInformationStreamsSync* > ( 
    879                     formatInfo->m_streams ); 
    880             if ( syncStream ) { 
    881                 foundFreq = 
    882                     static_cast< ESamplingFrequency >( 
    883                         syncStream->m_samplingFrequency ); 
    884             } 
    885  
    886             if ( foundFreq == samplingFrequency ) 
    887             { 
    888                 correctFormatFound = true; 
    889                 break; 
    890             } 
    891         } 
    892  
    893         ++i; 
    894     } while ( cmdSuccess 
    895               && ( extStreamFormatCmd.getResponse() == 
    896                    ExtendedStreamFormatCmd::eR_Implemented ) ); 
    897  
    898     if ( !cmdSuccess ) { 
    899         debugError( "setSampleRatePlug: Failed to retrieve format info\n" ); 
    900         return false; 
    901     } 
    902  
    903     if ( !correctFormatFound ) { 
    904         debugError( "setSampleRatePlug: %s plug %d does not support " 
    905                     "sample rate %d\n", 
    906                     plug.getName(), 
    907                     plug.getPlugId(), 
    908                     convertESamplingFrequency( samplingFrequency ) ); 
    909         return false; 
    910     } 
    911  
    912     extStreamFormatCmd.setSubFunction( 
    913         ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 
    914     extStreamFormatCmd.setCommandType( AVCCommand::eCT_Control ); 
    915     extStreamFormatCmd.setVerbose( m_verboseLevel ); 
    916  
    917     if ( !extStreamFormatCmd.fire() ) { 
    918         debugError( "setSampleRate: Could not set sample rate %d " 
    919                     "to %s plug %d\n", 
    920                     convertESamplingFrequency( samplingFrequency ), 
    921                     plug.getName(), 
    922                     plug.getPlugId() ); 
    923         return false; 
    924     } 
    925  
    926     return true; 
    927 
    928  
    929 void 
    930