Changeset 524
- Timestamp:
- 08/17/07 06:49:43 (16 years ago)
- Files:
-
- branches/echoaudio/src/bebob/bebob_avdevice.cpp (modified) (8 diffs)
- branches/echoaudio/src/bebob/bebob_avdevice.h (modified) (3 diffs)
- branches/echoaudio/src/bebob/bebob_avdevice_subunit.cpp (modified) (9 diffs)
- branches/echoaudio/src/bebob/bebob_avdevice_subunit.h (modified) (6 diffs)
- branches/echoaudio/src/bebob/bebob_avplug.cpp (modified) (2 diffs)
- branches/echoaudio/src/bebob/bebob_avplug.h (modified) (1 diff)
- branches/echoaudio/src/genericavc/avc_avdevice.cpp (modified) (9 diffs)
- branches/echoaudio/src/genericavc/avc_avdevice.h (modified) (4 diffs)
- branches/echoaudio/src/libavc/avc_definitions.cpp (modified) (2 diffs)
- branches/echoaudio/src/libavc/avc_definitions.h (modified) (3 diffs)
- branches/echoaudio/src/libavc/descriptors/avc_descriptor.cpp (modified) (9 diffs)
- branches/echoaudio/src/libavc/descriptors/avc_descriptor.h (modified) (4 diffs)
- branches/echoaudio/src/libavc/general/avc_connect.cpp (modified) (2 diffs)
- branches/echoaudio/src/libavc/general/avc_plug.cpp (modified) (12 diffs)
- branches/echoaudio/src/libavc/general/avc_plug.h (modified) (12 diffs)
- branches/echoaudio/src/libavc/general/avc_signal_format.cpp (added)
- branches/echoaudio/src/libavc/general/avc_signal_format.h (added)
- branches/echoaudio/src/libavc/general/avc_subunit.cpp (modified) (2 diffs)
- branches/echoaudio/src/libavc/general/avc_subunit.h (modified) (4 diffs)
- branches/echoaudio/src/libavc/general/avc_unit.cpp (modified) (7 diffs)
- branches/echoaudio/src/libavc/general/avc_unit.h (modified) (4 diffs)
- branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.cpp (modified) (8 diffs)
- branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.h (modified) (8 diffs)
- branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.cpp (modified) (3 diffs)
- branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.h (modified) (3 diffs)
- branches/echoaudio/src/libstreaming/PortManager.cpp (modified) (3 diffs)
- branches/echoaudio/src/libstreaming/PortManager.h (modified) (1 diff)
- branches/echoaudio/src/Makefile.am (modified) (2 diffs)
- branches/echoaudio/tests/Makefile.am (modified) (1 diff)
- branches/echoaudio/tests/streaming/testmidistreaming1.c (modified) (21 diffs)
- branches/echoaudio/tests/streaming/teststreaming.c (modified) (11 diffs)
- branches/echoaudio/tests/streaming/teststreaming2.c (modified) (12 diffs)
- branches/echoaudio/tests/streaming/teststreaming3.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/echoaudio/src/bebob/bebob_avdevice.cpp
r509 r524 94 94 } 95 95 96 AVC::Subunit* 97 BeBoB::AvDevice::createSubunit(AVC::Unit& unit, 98 AVC::ESubunitType type, 99 AVC::subunit_t id ) 100 { 101 switch (type) { 102 case AVC::eST_Audio: 103 return new BeBoB::SubunitAudio(unit, id ); 104 case AVC::eST_Music: 105 return new BeBoB::SubunitMusic(unit, id ); 106 default: 107 return NULL; 108 } 109 } 110 111 AVC::Plug * 112 BeBoB::AvDevice::createPlug( AVC::Unit* unit, 113 AVC::Subunit* subunit, 114 AVC::function_block_type_t functionBlockType, 115 AVC::function_block_type_t functionBlockId, 116 AVC::Plug::EPlugAddressType plugAddressType, 117 AVC::Plug::EPlugDirection plugDirection, 118 AVC::plug_id_t plugId ) 119 { 120 121 return new BeBoB::Plug( unit, 122 subunit, 123 functionBlockType, 124 functionBlockId, 125 plugAddressType, 126 plugDirection, 127 plugId ); 128 } 129 96 130 void 97 131 AvDevice::setVerboseLevel(int l) … … 166 200 // } 167 201 168 // bebob specific discovery procedure169 if ( !discoverPlugs() ) {170 debugError( "Detecting plugs failed\n" );171 return false;172 }173 174 if ( !discoverPlugConnections() ) {175 debugError( "Detecting plug connections failed\n" );176 return false;177 }178 179 if ( !discoverSubUnitsPlugConnections() ) {180 debugError( "Detecting plug connnection failed\n" );181 return false;182 }183 184 if ( !discoverSyncModes() ) {185 debugError( "Detecting sync modes failed\n" );186 return false;187 }188 189 202 // create a GenericMixer and add it as an OSC child node 190 203 // remove if already there … … 206 219 } 207 220 } 208 return true;209 }210 211 bool212 AvDevice::enumerateSubUnits()213 {214 SubUnitInfoCmd subUnitInfoCmd( get1394Service() );215 subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status );216 217 // NOTE: BeBoB has always exactly one audio and one music subunit. This218 // means is fits into the first page of the SubUnitInfo command.219 // So there is no need to do more than needed220 221 subUnitInfoCmd.m_page = 0;222 subUnitInfoCmd.setNodeId( getConfigRom().getNodeId() );223 subUnitInfoCmd.setVerbose( getDebugLevel() );224 if ( !subUnitInfoCmd.fire() ) {225 debugError( "Subunit info command failed\n" );226 // shouldn't this be an error situation?227 return false;228 }229 230 for ( int i = 0; i < subUnitInfoCmd.getNrOfValidEntries(); ++i ) {231 subunit_type_t subunit_type232 = subUnitInfoCmd.m_table[i].m_subunit_type;233 234 unsigned int subunitId = getNrOfSubunits( subunit_type );235 236 debugOutput( DEBUG_LEVEL_VERBOSE,237 "subunit_id = %2d, subunit_type = %2d (%s)\n",238 subunitId,239 subunit_type,240 subunitTypeToString( subunit_type ) );241 242 AVC::Subunit* subunit = 0;243 switch( subunit_type ) {244 case eST_Audio:245 subunit = new BeBoB::SubunitAudio( *this,246 subunitId );247 if ( !subunit ) {248 debugFatal( "Could not allocate SubunitAudio\n" );249 return false;250 }251 252 if ( !subunit->discover() ) {253 debugError( "enumerateSubUnits: Could not discover "254 "subunit_id = %2d, subunit_type = %2d (%s)\n",255 subunitId,256 subunit_type,257 subunitTypeToString( subunit_type ) );258 delete subunit;259 return false;260 } else {261 m_subunits.push_back( subunit );262 }263 264 break;265 case eST_Music:266 subunit = new BeBoB::SubunitMusic( *this,267 subunitId );268 if ( !subunit ) {269 debugFatal( "Could not allocate SubunitMusic\n" );270 return false;271 }272 if ( !subunit->discover() ) {273 debugError( "enumerateSubUnits: Could not discover "274 "subunit_id = %2d, subunit_type = %2d (%s)\n",275 subunitId,276 subunit_type,277 subunitTypeToString( subunit_type ) );278 delete subunit;279 return false;280 } else {281 m_subunits.push_back( subunit );282 }283 284 break;285 default:286 debugOutput( DEBUG_LEVEL_NORMAL,287 "Unsupported subunit found, subunit_type = %d (%s)\n",288 subunit_type,289 subunitTypeToString( subunit_type ) );290 continue;291 292 }293 }294 295 return true;296 }297 298 bool299 AvDevice::discoverPlugs()300 {301 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering plugs...\n");302 303 //////////////////////////////////////////////304 // Get number of available isochronous input305 // and output plugs of unit306 307 PlugInfoCmd plugInfoCmd( *m_p1394Service );308 plugInfoCmd.setNodeId( m_pConfigRom->getNodeId() );309 plugInfoCmd.setCommandType( AVCCommand::eCT_Status );310 plugInfoCmd.setVerbose( m_verboseLevel );311 312 if ( !plugInfoCmd.fire() ) {313 debugError( "plug info command failed\n" );314 return false;315 }316 317 debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n",318 plugInfoCmd.m_serialBusIsochronousInputPlugs );319 debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n",320 plugInfoCmd.m_serialBusIsochronousOutputPlugs );321 debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n",322 plugInfoCmd.m_externalInputPlugs );323 debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n",324 plugInfoCmd.m_externalOutputPlugs );325 326 if ( !discoverPlugsPCR( Plug::eAPD_Input,327 plugInfoCmd.m_serialBusIsochronousInputPlugs ) )328 {329 debugError( "pcr input plug discovering failed\n" );330 return false;331 }332 333 if ( !discoverPlugsPCR( Plug::eAPD_Output,334 plugInfoCmd.m_serialBusIsochronousOutputPlugs ) )335 {336 debugError( "pcr output plug discovering failed\n" );337 return false;338 }339 340 if ( !discoverPlugsExternal( Plug::eAPD_Input,341 plugInfoCmd.m_externalInputPlugs ) )342 {343 debugError( "external input plug discovering failed\n" );344 return false;345 }346 347 if ( !discoverPlugsExternal( Plug::eAPD_Output,348 plugInfoCmd.m_externalOutputPlugs ) )349 {350 debugError( "external output plug discovering failed\n" );351 return false;352 }353 354 return true;355 }356 357 bool358 AvDevice::discoverPlugsPCR( Plug::EPlugDirection plugDirection,359 plug_id_t plugMaxId )360 {361 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plugs, direction %d...\n",plugDirection);362 for ( int plugId = 0;363 plugId < plugMaxId;364 ++plugId )365 {366 AVC::Plug* plug = new Plug( this,367 NULL,368 0xff,369 0xff,370 Plug::eAPA_PCR,371 plugDirection,372 plugId );373 if ( !plug || !plug->discover() ) {374 debugError( "plug discovering failed\n" );375 delete plug;376 return false;377 }378 379 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",380 plug->getName() );381 m_pcrPlugs.push_back( plug );382 }383 384 return true;385 }386 387 bool388 AvDevice::discoverPlugsExternal( Plug::EPlugDirection plugDirection,389 plug_id_t plugMaxId )390 {391 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering Externals plugs, direction %d...\n",plugDirection);392 for ( int plugId = 0;393 plugId < plugMaxId;394 ++plugId )395 {396 AVC::Plug* plug = new Plug( this, NULL,397 0xff,398 0xff,399 Plug::eAPA_ExternalPlug,400 plugDirection,401 plugId );402 if ( !plug || !plug->discover() ) {403 debugError( "plug discovering failed\n" );404 return false;405 }406 407 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",408 plug->getName() );409 m_externalPlugs.push_back( plug );410 }411 412 return true;413 }414 415 bool416 AvDevice::discoverPlugConnections()417 {418 for ( PlugVector::iterator it = m_pcrPlugs.begin();419 it != m_pcrPlugs.end();420 ++it )421 {422 BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it);423 if(!plug) {424 debugError("BUG: not a bebob plug\n");425 return false;426 }427 if ( !plug->discoverConnections() ) {428 debugError( "Could not discover plug connections\n" );429 return false;430 }431 }432 for ( PlugVector::iterator it = m_externalPlugs.begin();433 it != m_externalPlugs.end();434 ++it )435 {436 BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it);437 if(!plug) {438 debugError("BUG: not a bebob plug\n");439 return false;440 }441 if ( !plug->discoverConnections() ) {442 debugError( "Could not discover plug connections\n" );443 return false;444 }445 }446 447 return true;448 }449 450 bool451 AvDevice::discoverSubUnitsPlugConnections()452 {453 for ( SubunitVector::iterator it = m_subunits.begin();454 it != m_subunits.end();455 ++it )456 {457 BeBoB::Subunit* subunit = dynamic_cast<BeBoB::Subunit*>(*it);458 if (subunit==NULL) {459 debugError("BUG: subunit is not a BeBoB::Subunit\n");460 return false;461 }462 463 if ( !subunit->discoverConnections() ) {464 debugError( "Subunit '%s' plug connections failed\n",465 subunit->getName() );466 return false;467 }468 }469 return true;470 }471 472 bool473 AvDevice::discoverSyncModes()474 {475 // Following possible sync plugs exists:476 // - Music subunit sync output plug = internal sync (CSP)477 // - Unit input plug 0 = SYT match478 // - Unit input plut 1 = Sync stream479 //480 // If last sync mode is reported it is mostelikely not481 // implemented *sic*482 //483 // Following sync sources are device specific:484 // - All unit external input plugs which have a485 // sync information (WS, SPDIF, ...)486 487 // First we have to find the sync input and output plug488 // in the music subunit.489 490 // Note PCR input means 1394bus-to-device where as491 // MSU input means subunit-to-device492 493 PlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs,494 Plug::eAPD_Input,495 Plug::eAPT_Sync );496 if ( !syncPCRInputPlugs.size() ) {497 debugWarning( "No PCR sync input plug found\n" );498 }499 500 PlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs,501 Plug::eAPD_Output,502 Plug::eAPT_Sync );503 if ( !syncPCROutputPlugs.size() ) {504 debugWarning( "No PCR sync output plug found\n" );505 }506 507 PlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs,508 Plug::eAPD_Input,509 Plug::eAPT_IsoStream );510 if ( !isoPCRInputPlugs.size() ) {511 debugWarning( "No PCR iso input plug found\n" );512 513 }514 515 PlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs,516 Plug::eAPD_Output,517 Plug::eAPT_IsoStream );518 if ( !isoPCROutputPlugs.size() ) {519 debugWarning( "No PCR iso output plug found\n" );520 521 }522 523 PlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs,524 Plug::eAPD_Input,525 Plug::eAPT_Digital );526 527 PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType(528 eST_Music,529 0,530 0xff,531 0xff,532 Plug::eAPA_SubunitPlug,533 Plug::eAPD_Input,534 Plug::eAPT_Sync );535 if ( !syncMSUInputPlugs.size() ) {536 debugWarning( "No sync input plug for MSU subunit found\n" );537 }538 539 PlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType(540 eST_Music,541 0,542 0xff,543 0xff,544 Plug::eAPA_SubunitPlug,545 Plug::eAPD_Output,546 Plug::eAPT_Sync );547 if ( !syncMSUOutputPlugs.size() ) {548 debugWarning( "No sync output plug for MSU subunit found\n" );549 }550 551 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" );552 showPlugs( syncPCRInputPlugs );553 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" );554 showPlugs( syncPCROutputPlugs );555 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" );556 showPlugs( isoPCRInputPlugs );557 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" );558 showPlugs( isoPCROutputPlugs );559 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" );560 showPlugs( digitalPCRInputPlugs );561 debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" );562 showPlugs( syncMSUInputPlugs );563 debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" );564 showPlugs( syncMSUOutputPlugs );565 566 // Check all possible PCR input to MSU input connections567 // -> sync stream input568 checkSyncConnectionsAndAddToList( syncPCRInputPlugs,569 syncMSUInputPlugs,570 "Sync Stream Input" );571 572 // Check all possible MSU output to PCR output connections573 // -> sync stream output574 checkSyncConnectionsAndAddToList( syncMSUOutputPlugs,575 syncPCROutputPlugs,576 "Sync Stream Output" );577 578 // Check all PCR iso input to MSU input connections579 // -> SYT match580 checkSyncConnectionsAndAddToList( isoPCRInputPlugs,581 syncMSUInputPlugs,582 "Syt Match" );583 584 // Check all MSU sync output to MSU input connections585 // -> CSP586 checkSyncConnectionsAndAddToList( syncMSUOutputPlugs,587 syncMSUInputPlugs,588 "Internal (CSP)" );589 590 // Check all external PCR digital input to MSU input connections591 // -> SPDIF/ADAT sync592 checkSyncConnectionsAndAddToList( digitalPCRInputPlugs,593 syncMSUInputPlugs,594 "Digital Input Sync" );595 596 // Currently active connection signal source cmd, command type597 // status, source unknown, destination MSU sync input plug598 599 for ( PlugVector::const_iterator it = syncMSUInputPlugs.begin();600 it != syncMSUInputPlugs.end();601 ++it )602 {603 AVC::Plug* msuPlug = *it;604 for ( PlugVector::const_iterator jt =605 msuPlug->getInputConnections().begin();606 jt != msuPlug->getInputConnections().end();607 ++jt )608 {609 AVC::Plug* plug = *jt;610 611 for ( SyncInfoVector::iterator it = m_syncInfos.begin();612 it != m_syncInfos.end();613 ++it )614 {615 SyncInfo* pSyncInfo = &*it;616 if ( ( pSyncInfo->m_source == plug )617 && ( pSyncInfo->m_destination == msuPlug ) )618 {619 m_activeSyncInfo = pSyncInfo;620 break;621 }622 }623 debugOutput( DEBUG_LEVEL_NORMAL,624 "Active Sync Connection: '%s' -> '%s'\n",625 plug->getName(),626 msuPlug->getName() );627 }628 }629 630 221 return true; 631 222 } … … 821 412 } 822 413 823 bool824 AvDevice::checkSyncConnectionsAndAddToList( PlugVector& plhs,825 PlugVector& prhs,826 std::string syncDescription )827 {828 for ( PlugVector::iterator plIt = plhs.begin();829 plIt != plhs.end();830 ++plIt )831 {832 AVC::Plug* pl = *plIt;833 for ( PlugVector::iterator prIt = prhs.begin();834 prIt != prhs.end();835 ++prIt )836 {837 AVC::Plug* pr = *prIt;838 if ( pl->inquireConnnection( *pr ) ) {839 m_syncInfos.push_back( SyncInfo( *pl, *pr, syncDescription ) );840 debugOutput( DEBUG_LEVEL_NORMAL,841 "Sync connection '%s' -> '%s'\n",842 pl->getName(),843 pr->getName() );844 }845 }846 }847 return true;848 }849 850 bool AvDevice::setActiveSync(const SyncInfo& syncInfo)851 {852 return syncInfo.m_source->setConnection( *syncInfo.m_destination );853 }854 414 855 415 bool … … 863 423 // don't lock 864 424 } else { 865 425 // return Unit::reserve(4); 866 426 } 867 427 … … 879 439 // don't unlock 880 440 } else { 881 441 // return Unit::reserve(0); 882 442 } 883 443 return true; … … 1018 578 // but bebob reports it starting from 1. Decide where 1019 579 // and how to handle this (pp: here) 580 // note that the descriptor mechanism specifies indexing from 0 1020 581 channelInfo->m_streamPosition - 1, 1021 582 channelInfo->m_location - 1, … … 1028 589 portname.str(), 1029 590 direction, 1030 // \todo: streaming backend expects indexing starting from 0 1031 // but bebob reports it starting from 1. Decide where 1032 // and how to handle this (pp: here) 1033 channelInfo->m_streamPosition - 1, 1034 channelInfo->m_location - 1, 591 channelInfo->m_streamPosition, 592 // Workaround for out-of-spec hardware 593 // should be: 594 // channelInfo->m_location-1, 595 // but now we renumber the midi channels' location as they 596 // are discovered 597 processor->getPortCount(Streaming::Port::E_Midi), 1035 598 Streaming::AmdtpPortInfo::E_Midi 1036 599 ); branches/echoaudio/src/bebob/bebob_avdevice.h
r509 r524 88 88 virtual void showDevice(); 89 89 90 bool setActiveSync( const SyncInfo& syncInfo );91 92 90 bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 93 91 static AvDevice* deserialize( Glib::ustring basePath, … … 100 98 ConfigRom& getConfigRom() const 101 99 { return FFADODevice::getConfigRom(); }; 102 100 101 virtual AVC::Subunit* createSubunit(AVC::Unit& unit, 102 AVC::ESubunitType type, 103 AVC::subunit_t id ); 104 virtual AVC::Plug *createPlug( AVC::Unit* unit, 105 AVC::Subunit* subunit, 106 AVC::function_block_type_t functionBlockType, 107 AVC::function_block_type_t functionBlockId, 108 AVC::Plug::EPlugAddressType plugAddressType, 109 AVC::Plug::EPlugDirection plugDirection, 110 AVC::plug_id_t plugId ); 103 111 protected: 104 105 bool enumerateSubUnits();106 107 bool discoverPlugs();108 bool discoverPlugsPCR( AVC::Plug::EPlugDirection plugDirection,109 AVC::plug_id_t plugMaxId );110 bool discoverPlugsExternal( AVC::Plug::EPlugDirection plugDirection,111 AVC::plug_id_t plugMaxId );112 bool discoverPlugConnections();113 bool discoverSyncModes();114 bool discoverSubUnitsPlugConnections();115 112 116 113 bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, … … 121 118 AVC::ESamplingFrequency samplingFrequency ); 122 119 123 bool checkSyncConnectionsAndAddToList( AVC::PlugVector& plhs, 124 AVC::PlugVector& prhs, 125 std::string syncDescription ); 120 126 121 127 122 protected: branches/echoaudio/src/bebob/bebob_avdevice_subunit.cpp
r509 r524 36 36 using namespace AVC; 37 37 38 IMPL_DEBUG_MODULE( BeBoB::Subunit, BeBoB::Subunit, DEBUG_LEVEL_VERBOSE );39 IMPL_DEBUG_MODULE( BeBoB::SubunitAudio, BeBoB::SubunitAudio, DEBUG_LEVEL_VERBOSE );40 IMPL_DEBUG_MODULE( BeBoB::SubunitMusic, BeBoB::SubunitMusic, DEBUG_LEVEL_VERBOSE );41 42 bool43 BeBoB::Subunit::discover()44 {45 if ( !discoverPlugs() ) {46 debugError( "plug discovering failed\n" );47 return false;48 }49 50 return true;51 }52 53 bool54 BeBoB::Subunit::discoverPlugs()55 {56 PlugInfoCmd plugInfoCmd( getUnit().get1394Service(),57 PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug );58 plugInfoCmd.setNodeId( getUnit().getConfigRom().getNodeId() );59 plugInfoCmd.setCommandType( AVCCommand::eCT_Status );60 plugInfoCmd.setSubunitType( getSubunitType() );61 plugInfoCmd.setSubunitId( getSubunitId() );62 plugInfoCmd.setVerbose( getDebugLevel() );63 64 if ( !plugInfoCmd.fire() ) {65 debugError( "plug info command failed\n" );66 return false;67 }68 69 debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n",70 plugInfoCmd.m_sourcePlugs );71 debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output "72 "plugs = %d\n", plugInfoCmd.m_destinationPlugs );73 74 if ( !discoverPlugs( Plug::eAPD_Input,75 plugInfoCmd.m_destinationPlugs ) )76 {77 debugError( "destination plug discovering failed\n" );78 return false;79 }80 81 if ( !discoverPlugs( Plug::eAPD_Output,82 plugInfoCmd.m_sourcePlugs ) )83 {84 debugError( "source plug discovering failed\n" );85 return false;86 }87 88 return true;89 }90 91 bool92 BeBoB::Subunit::discoverConnections()93 {94 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n");95 96 for ( PlugVector::iterator it = getPlugs().begin();97 it != getPlugs().end();98 ++it )99 {100 BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it);101 if(!plug) {102 debugError("BUG: not a bebob plug\n");103 return false;104 }105 if ( !plug->discoverConnections() ) {106 debugError( "plug connection discovering failed ('%s')\n",107 plug->getName() );108 return false;109 }110 }111 112 return true;113 }114 115 bool116 BeBoB::Subunit::discoverPlugs(Plug::EPlugDirection plugDirection,117 plug_id_t plugMaxId )118 {119 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering plugs...\n");120 for ( int plugIdx = 0;121 plugIdx < plugMaxId;122 ++plugIdx )123 {124 ESubunitType subunitType =125 static_cast<ESubunitType>( getSubunitType() );126 BeBoB::Plug* plug = new BeBoB::Plug( &getUnit(),127 &getSubunit(),128 0xff,129 0xff,130 Plug::eAPA_SubunitPlug,131 plugDirection,132 plugIdx );133 if ( !plug ) {134 debugError( "plug creation failed\n" );135 return false;136 }137 138 plug->setVerboseLevel(getDebugLevel());139 140 if ( !plug->discover() ) {141 debugError( "plug discover failed\n" );142 return false;143 }144 145 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",146 plug->getName() );147 getPlugs().push_back( plug );148 }149 return true;150 }151 152 153 38 ////////////////////////// 154 39 … … 156 41 subunit_t id ) 157 42 : AVC::SubunitAudio( avDevice, id ) 158 , BeBoB::Subunit()159 43 { 160 44 } … … 168 52 { 169 53 54 } 55 56 AVC::Plug * 57 BeBoB::SubunitAudio::createPlug( AVC::Unit* unit, 58 AVC::Subunit* subunit, 59 AVC::function_block_type_t functionBlockType, 60 AVC::function_block_type_t functionBlockId, 61 AVC::Plug::EPlugAddressType plugAddressType, 62 AVC::Plug::EPlugDirection plugDirection, 63 AVC::plug_id_t plugId ) 64 { 65 66 return new BeBoB::Plug( unit, 67 subunit, 68 functionBlockType, 69 functionBlockId, 70 plugAddressType, 71 plugDirection, 72 plugId ); 170 73 } 171 74 … … 179 82 return false; 180 83 } 181 182 // do BeBoB subunit specific discovery183 if ( !BeBoB::Subunit::discover() ) {184 return false;185 }186 84 187 85 // do the remaining BeBoB audio subunit discovery … … 198 96 { 199 97 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 200 if ( ! BeBoB::Subunit::discoverConnections() ) {98 if ( !Subunit::discoverConnections() ) { 201 99 return false; 202 100 } … … 488 386 subunit_t id ) 489 387 : AVC::SubunitMusic( avDevice, id ) 490 , BeBoB::Subunit()491 388 { 492 389 } … … 494 391 BeBoB::SubunitMusic::SubunitMusic() 495 392 : AVC::SubunitMusic() 496 , BeBoB::Subunit()497 393 { 498 394 } … … 500 396 BeBoB::SubunitMusic::~SubunitMusic() 501 397 { 398 } 399 400 AVC::Plug * 401 BeBoB::SubunitMusic::createPlug( AVC::Unit* unit, 402 AVC::Subunit* subunit, 403 AVC::function_block_type_t functionBlockType, 404 AVC::function_block_type_t functionBlockId, 405 AVC::Plug::EPlugAddressType plugAddressType, 406 AVC::Plug::EPlugDirection plugDirection, 407 AVC::plug_id_t plugId ) 408 { 409 410 return new BeBoB::Plug( unit, 411 subunit, 412 functionBlockType, 413 functionBlockId, 414 plugAddressType, 415 plugDirection, 416 plugId ); 502 417 } 503 418 … … 511 426 return false; 512 427 } 513 514 // do BeBoB subunit specific discovery515 if ( !BeBoB::Subunit::discover() ) {516 return false;517 }518 428 519 429 // do the remaining BeBoB music subunit discovery branches/echoaudio/src/bebob/bebob_avdevice_subunit.h
r509 r524 44 44 ///////////////////////////// 45 45 46 class Subunit {47 public:48 Subunit() {};49 virtual ~Subunit() {};50 virtual bool discover();51 virtual bool discoverConnections();52 53 // required functions54 // implemented by the derived class55 virtual const char* getName() = 0;56 virtual AVC::subunit_t getSubunitId() = 0;57 virtual AVC::ESubunitType getSubunitType() = 0;58 virtual AVC::Unit& getUnit() const = 0;59 virtual AVC::Subunit& getSubunit() = 0;60 virtual AVC::PlugVector& getPlugs() = 0;61 62 protected:63 bool discoverPlugs();64 bool discoverPlugs(Plug::EPlugDirection plugDirection,65 AVC::plug_id_t plugMaxId );66 private:67 DECLARE_DEBUG_MODULE;68 };69 70 /////////////////////////////71 72 46 class SubunitAudio : public AVC::SubunitAudio 73 , public BeBoB::Subunit74 47 { 75 48 public: … … 82 55 virtual bool discoverConnections(); 83 56 84 // required interface for BeBoB::Subunit 57 virtual AVC::Plug *createPlug( AVC::Unit* unit, 58 AVC::Subunit* subunit, 59 AVC::function_block_type_t functionBlockType, 60 AVC::function_block_type_t functionBlockId, 61 AVC::Plug::EPlugAddressType plugAddressType, 62 AVC::Plug::EPlugDirection plugDirection, 63 AVC::plug_id_t plugId ); 64 85 65 virtual const char* getName(); 86 virtual AVC::subunit_t getSubunitId()87 { return AVC::SubunitAudio::getSubunitId(); };88 virtual AVC::ESubunitType getSubunitType()89 { return AVC::SubunitAudio::getSubunitType(); };90 virtual AVC::Unit& getUnit() const91 { return AVC::SubunitAudio::getUnit(); };92 virtual AVC::Subunit& getSubunit()93 { return *this; };94 virtual AVC::PlugVector& getPlugs()95 { return AVC::SubunitAudio::getPlugs(); };96 66 97 67 protected: … … 111 81 Util::IODeserialize& deser, 112 82 AVC::Unit& unit ); 113 private: 114 DECLARE_DEBUG_MODULE; 83 115 84 }; 116 85 … … 118 87 119 88 class SubunitMusic : public AVC::SubunitMusic 120 , public BeBoB::Subunit121 89 { 122 90 public: … … 126 94 virtual ~SubunitMusic(); 127 95 128 // required interface for BeBoB::Subunit 96 virtual bool discover(); 97 98 virtual AVC::Plug *createPlug( AVC::Unit* unit, 99 AVC::Subunit* subunit, 100 AVC::function_block_type_t functionBlockType, 101 AVC::function_block_type_t functionBlockId, 102 AVC::Plug::EPlugAddressType plugAddressType, 103 AVC::Plug::EPlugDirection plugDirection, 104 AVC::plug_id_t plugId ); 105 129 106 virtual const char* getName(); 130 virtual AVC::subunit_t getSubunitId()131 { return AVC::SubunitMusic::getSubunitId(); };132 virtual AVC::ESubunitType getSubunitType()133 { return AVC::SubunitMusic::getSubunitType(); };134 virtual AVC::Unit& getUnit() const135 { return AVC::SubunitMusic::getUnit(); };136 virtual AVC::Subunit& getSubunit()137 { return *this; };138 virtual AVC::PlugVector& getPlugs()139 { return AVC::SubunitMusic::getPlugs(); };140 141 142 virtual bool discover();143 107 144 108 protected: … … 148 112 Util::IODeserialize& deser, 149 113 AVC::Unit& unit ); 150 private: 151 DECLARE_DEBUG_MODULE; 114 152 115 }; 153 116 branches/echoaudio/src/bebob/bebob_avplug.cpp
r509 r524 423 423 } 424 424 425 bool 426 Plug::discoverStreamFormat() 427 { 428 ExtendedStreamFormatCmd extStreamFormatCmd = 429 setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 430 extStreamFormatCmd.setVerbose( getDebugLevel() ); 431 432 if ( !extStreamFormatCmd.fire() ) { 433 debugError( "stream format command failed\n" ); 434 return false; 435 } 436 437 if ( ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NoStreamFormat ) 438 || ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NotUsed ) ) 439 { 440 debugOutput( DEBUG_LEVEL_VERBOSE, 441 "No stream format information available\n" ); 442 return true; 443 } 444 445 if ( !extStreamFormatCmd.getFormatInformation() ) { 446 debugWarning( "No stream format information for plug found -> skip\n" ); 447 return true; 448 } 449 450 if ( extStreamFormatCmd.getFormatInformation()->m_root 451 != FormatInformation::eFHR_AudioMusic ) 452 { 453 debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 454 return true; 455 } 456 457 FormatInformation* formatInfo = 458 extStreamFormatCmd.getFormatInformation(); 459 FormatInformationStreamsCompound* compoundStream 460 = dynamic_cast< FormatInformationStreamsCompound* > ( 461 formatInfo->m_streams ); 462 if ( compoundStream ) { 463 m_samplingFrequency = 464 compoundStream->m_samplingFrequency; 465 debugOutput( DEBUG_LEVEL_VERBOSE, 466 "%s plug %d uses " 467 "sampling frequency %d, nr of stream infos = %d\n", 468 getName(), 469 m_id, 470 m_samplingFrequency, 471 compoundStream->m_numberOfStreamFormatInfos ); 472 473 for ( int i = 1; 474 i <= compoundStream->m_numberOfStreamFormatInfos; 475 ++i ) 476 { 477 ClusterInfo* clusterInfo = 478 const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 479 480 if ( !clusterInfo ) { 481 debugError( "No matching cluster " 482 "info found for index %d\n", i ); 483 return false; 484 } 485 StreamFormatInfo* streamFormatInfo = 486 compoundStream->m_streamFormatInfos[ i - 1 ]; 487 488 debugOutput( DEBUG_LEVEL_VERBOSE, 489 "number of channels = %d, stream format = %d\n", 490 streamFormatInfo->m_numberOfChannels, 491 streamFormatInfo->m_streamFormat ); 492 493 int nrOfChannels = clusterInfo->m_nrOfChannels; 494 if ( streamFormatInfo->m_streamFormat == 495 FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 496 { 497 // 8 logical midi channels fit into 1 channel 498 nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 499 } 500 // sanity check 501 if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 502 { 503 debugWarning( "Number of channels " 504 "mismatch: '%s' plug discovering reported " 505 "%d channels for cluster '%s', while stream " 506 "format reported %d\n", 507 getName(), 508 nrOfChannels, 509 clusterInfo->m_name.c_str(), 510 streamFormatInfo->m_numberOfChannels); 511 } 512 clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 513 514 debugOutput( DEBUG_LEVEL_VERBOSE, 515 "%s plug %d cluster info %d ('%s'): " 516 "stream format %d\n", 517 getName(), 518 m_id, 519 i, 520 clusterInfo->m_name.c_str(), 521 clusterInfo->m_streamFormat ); 522 } 523 } 524 525 FormatInformationStreamsSync* syncStream 526 = dynamic_cast< FormatInformationStreamsSync* > ( 527 formatInfo->m_streams ); 528 if ( syncStream ) { 529 m_samplingFrequency = 530 syncStream->m_samplingFrequency; 531 debugOutput( DEBUG_LEVEL_VERBOSE, 532 "%s plug %d is sync stream with sampling frequency %d\n", 533 getName(), 534 m_id, 535 m_samplingFrequency ); 536 } 537 538 539 if ( !compoundStream && !syncStream ) 540 { 541 debugError( "Unsupported stream format\n" ); 542 return false; 543 } 544 545 return true; 546 } 547 548 bool 549 Plug::discoverSupportedStreamFormats() 550 { 551 ExtendedStreamFormatCmd extStreamFormatCmd = 552 setPlugAddrToStreamFormatCmd( 553 ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 554 extStreamFormatCmd.setVerbose( getDebugLevel() ); 555 556 int i = 0; 557 bool cmdSuccess = false; 558 559 do { 560 extStreamFormatCmd.setIndexInStreamFormat( i ); 561 extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 562 cmdSuccess = extStreamFormatCmd.fire(); 563 if ( cmdSuccess 564 && ( extStreamFormatCmd.getResponse() 565 == AVCCommand::eR_Implemented ) ) 566 { 567 FormatInfo formatInfo; 568 formatInfo.m_index = i; 569 bool formatInfoIsValid = true; 570 571 FormatInformationStreamsSync* syncStream 572 = dynamic_cast< FormatInformationStreamsSync* > 573 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 574 if ( syncStream ) { 575 formatInfo.m_samplingFrequency = 576 syncStream->m_samplingFrequency; 577 formatInfo.m_isSyncStream = true ; 578 } 579 580 FormatInformationStreamsCompound* compoundStream 581 = dynamic_cast< FormatInformationStreamsCompound* > 582 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 583 if ( compoundStream ) { 584 formatInfo.m_samplingFrequency = 585 compoundStream->m_samplingFrequency; 586 formatInfo.m_isSyncStream = false; 587 for ( int j = 0; 588 j < compoundStream->m_numberOfStreamFormatInfos; 589 ++j ) 590 { 591 switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 592 case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 593 formatInfo.m_audioChannels += 594 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 595 break; 596 case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 597 formatInfo.m_audioChannels += 598 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 599 break; 600 case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 601 formatInfo.m_midiChannels += 602 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 603 break; 604 default: 605 formatInfoIsValid = false; 606 debugWarning("unknown stream format (0x%02x) for channel " 607 "(%d)\n", 608 compoundStream->m_streamFormatInfos[j]->m_streamFormat, 609 j ); 610 } 611 } 612 } 613 614 if ( formatInfoIsValid ) { 615 flushDebugOutput(); 616 debugOutput( DEBUG_LEVEL_VERBOSE, 617 "[%s:%d] formatInfo[%d].m_samplingFrequency " 618 "= %d\n", 619 getName(), m_id, 620 i, formatInfo.m_samplingFrequency ); 621 debugOutput( DEBUG_LEVEL_VERBOSE, 622 "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 623 getName(), m_id, 624 i, formatInfo.m_isSyncStream ); 625 debugOutput( DEBUG_LEVEL_VERBOSE, 626 "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 627 getName(), m_id, 628 i, formatInfo.m_audioChannels ); 629 debugOutput( DEBUG_LEVEL_VERBOSE, 630 "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 631 getName(), m_id, 632 i, formatInfo.m_midiChannels ); 633 m_formatInfos.push_back( formatInfo ); 634 flushDebugOutput(); 635 } 636 } 637 638 ++i; 639 } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 640 == ExtendedStreamFormatCmd::eR_Implemented ) ); 641 642 return true; 643 } 425 // NOTE: currently in the generic AV/C unit 426 // bool 427 // Plug::discoverStreamFormat() 428 // { 429 // ExtendedStreamFormatCmd extStreamFormatCmd = 430 // setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 431 // extStreamFormatCmd.setVerbose( getDebugLevel() ); 432 // 433 // if ( !extStreamFormatCmd.fire() ) { 434 // debugError( "stream format command failed\n" ); 435 // return false; 436 // } 437 // 438 // if ( ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NoStreamFormat ) 439 // || ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NotUsed ) ) 440 // { 441 // debugOutput( DEBUG_LEVEL_VERBOSE, 442 // "No stream format information available\n" ); 443 // return true; 444 // } 445 // 446 // if ( !extStreamFormatCmd.getFormatInformation() ) { 447 // debugWarning( "No stream format information for plug found -> skip\n" ); 448 // return true; 449 // } 450 // 451 // if ( extStreamFormatCmd.getFormatInformation()->m_root 452 // != FormatInformation::eFHR_AudioMusic ) 453 // { 454 // debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 455 // return true; 456 // } 457 // 458 // FormatInformation* formatInfo = 459 // extStreamFormatCmd.getFormatInformation(); 460 // FormatInformationStreamsCompound* compoundStream 461 // = dynamic_cast< FormatInformationStreamsCompound* > ( 462 // formatInfo->m_streams ); 463 // if ( compoundStream ) { 464 // m_samplingFrequency = 465 // compoundStream->m_samplingFrequency; 466 // debugOutput( DEBUG_LEVEL_VERBOSE, 467 // "%s plug %d uses " 468 // "sampling frequency %d, nr of stream infos = %d\n", 469 // getName(), 470 // m_id, 471 // m_samplingFrequency, 472 // compoundStream->m_numberOfStreamFormatInfos ); 473 // 474 // for ( int i = 1; 475 // i <= compoundStream->m_numberOfStreamFormatInfos; 476 // ++i ) 477 // { 478 // ClusterInfo* clusterInfo = 479 // const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 480 // 481 // if ( !clusterInfo ) { 482 // debugError( "No matching cluster " 483 // "info found for index %d\n", i ); 484 // return false; 485 // } 486 // StreamFormatInfo* streamFormatInfo = 487 // compoundStream->m_streamFormatInfos[ i - 1 ]; 488 // 489 // debugOutput( DEBUG_LEVEL_VERBOSE, 490 // "number of channels = %d, stream format = %d\n", 491 // streamFormatInfo->m_numberOfChannels, 492 // streamFormatInfo->m_streamFormat ); 493 // 494 // int nrOfChannels = clusterInfo->m_nrOfChannels; 495 // if ( streamFormatInfo->m_streamFormat == 496 // FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 497 // { 498 // // 8 logical midi channels fit into 1 channel 499 // nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 500 // } 501 // // sanity check 502 // if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 503 // { 504 // debugWarning( "Number of channels " 505 // "mismatch: '%s' plug discovering reported " 506 // "%d channels for cluster '%s', while stream " 507 // "format reported %d\n", 508 // getName(), 509 // nrOfChannels, 510 // clusterInfo->m_name.c_str(), 511 // streamFormatInfo->m_numberOfChannels); 512 // } 513 // clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 514 // 515 // debugOutput( DEBUG_LEVEL_VERBOSE, 516 // "%s plug %d cluster info %d ('%s'): " 517 // "stream format %d\n", 518 // getName(), 519 // m_id, 520 // i, 521 // clusterInfo->m_name.c_str(), 522 // clusterInfo->m_streamFormat ); 523 // } 524 // } 525 // 526 // FormatInformationStreamsSync* syncStream 527 // = dynamic_cast< FormatInformationStreamsSync* > ( 528 // formatInfo->m_streams ); 529 // if ( syncStream ) { 530 // m_samplingFrequency = 531 // syncStream->m_samplingFrequency; 532 // debugOutput( DEBUG_LEVEL_VERBOSE, 533 // "%s plug %d is sync stream with sampling frequency %d\n", 534 // getName(), 535 // m_id, 536 // m_samplingFrequency ); 537 // } 538 // 539 // 540 // if ( !compoundStream && !syncStream ) 541 // { 542 // debugError( "Unsupported stream format\n" ); 543 // return false; 544 // } 545 // 546 // return true; 547 // } 548 // 549 // bool 550 // Plug::discoverSupportedStreamFormats() 551 // { 552 // ExtendedStreamFormatCmd extStreamFormatCmd = 553 // setPlugAddrToStreamFormatCmd( 554 // ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 555 // extStreamFormatCmd.setVerbose( getDebugLevel() ); 556 // 557 // int i = 0; 558 // bool cmdSuccess = false; 559 // 560 // do { 561 // extStreamFormatCmd.setIndexInStreamFormat( i ); 562 // extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 563 // cmdSuccess = extStreamFormatCmd.fire(); 564 // if ( cmdSuccess 565 // && ( extStreamFormatCmd.getResponse() 566 // == AVCCommand::eR_Implemented ) ) 567 // { 568 // FormatInfo formatInfo; 569 // formatInfo.m_index = i; 570 // bool formatInfoIsValid = true; 571 // 572 // FormatInformationStreamsSync* syncStream 573 // = dynamic_cast< FormatInformationStreamsSync* > 574 // ( extStreamFormatCmd.getFormatInformation()->m_streams ); 575 // if ( syncStream ) { 576 // formatInfo.m_samplingFrequency = 577 // syncStream->m_samplingFrequency; 578 // formatInfo.m_isSyncStream = true ; 579 // } 580 // 581 // FormatInformationStreamsCompound* compoundStream 582 // = dynamic_cast< FormatInformationStreamsCompound* > 583 // ( extStreamFormatCmd.getFormatInformation()->m_streams ); 584 // if ( compoundStream ) { 585 // formatInfo.m_samplingFrequency = 586 // compoundStream->m_samplingFrequency; 587 // formatInfo.m_isSyncStream = false; 588 // for ( int j = 0; 589 // j < compoundStream->m_numberOfStreamFormatInfos; 590 // ++j ) 591 // { 592 // switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 593 // case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 594 // formatInfo.m_audioChannels += 595 // compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 596 // break; 597 // case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 598 // formatInfo.m_audioChannels += 599 // compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 600 // break; 601 // case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 602 // formatInfo.m_midiChannels += 603 // compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 604 // break; 605 // default: 606 // formatInfoIsValid = false; 607 // debugWarning("unknown stream format (0x%02x) for channel " 608 // "(%d)\n", 609 // compoundStream->m_streamFormatInfos[j]->m_streamFormat, 610 // j ); 611 // } 612 // } 613 // } 614 // 615 // if ( formatInfoIsValid ) { 616 // flushDebugOutput(); 617 // debugOutput( DEBUG_LEVEL_VERBOSE, 618 // "[%s:%d] formatInfo[%d].m_samplingFrequency " 619 // "= %d\n", 620 // getName(), m_id, 621 // i, formatInfo.m_samplingFrequency ); 622 // debugOutput( DEBUG_LEVEL_VERBOSE, 623 // "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 624 // getName(), m_id, 625 // i, formatInfo.m_isSyncStream ); 626 // debugOutput( DEBUG_LEVEL_VERBOSE, 627 // "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 628 // getName(), m_id, 629 // i, formatInfo.m_audioChannels ); 630 // debugOutput( DEBUG_LEVEL_VERBOSE, 631 // "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 632 // getName(), m_id, 633 // i, formatInfo.m_midiChannels ); 634 // m_formatInfos.push_back( formatInfo ); 635 // flushDebugOutput(); 636 // } 637 // } 638 // 639 // ++i; 640 // } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 641 // == ExtendedStreamFormatCmd::eR_Implemented ) ); 642 // 643 // return true; 644 // } 644 645 645 646 … … 760 761 } 761 762 762 ExtendedPlugInfoCmd 763 Plug::setPlugAddrToPlugInfoCmd() 764 { 765 ExtendedPlugInfoCmd extPlugInfoCmd( m_unit->get1394Service() ); 766 767 switch( getSubunitType() ) { 768 case eST_Unit: 769 { 770 UnitPlugAddress::EPlugType ePlugType = 771 UnitPlugAddress::ePT_Unknown; 772 switch ( m_addressType ) { 773 case eAPA_PCR: 774 ePlugType = UnitPlugAddress::ePT_PCR; 775 break; 776 case eAPA_ExternalPlug: 777 ePlugType = UnitPlugAddress::ePT_ExternalPlug; 778 break; 779 case eAPA_AsynchronousPlug: 780 ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 781 break; 782 default: 783 ePlugType = UnitPlugAddress::ePT_Unknown; 784 } 785 UnitPlugAddress unitPlugAddress( ePlugType, 786 m_id ); 787 extPlugInfoCmd.setPlugAddress( 788 PlugAddress( convertPlugDirection( getPlugDirection() ), 789 PlugAddress::ePAM_Unit, 790 unitPlugAddress ) ); 791 } 792 break; 793 case eST_Music: 794 case eST_Audio: 795 { 796 switch( m_addressType ) { 797 case eAPA_SubunitPlug: 798 { 799 SubunitPlugAddress subunitPlugAddress( m_id ); 800 extPlugInfoCmd.setPlugAddress( 801 PlugAddress( 802 convertPlugDirection( getPlugDirection() ), 803 PlugAddress::ePAM_Subunit, 804 subunitPlugAddress ) ); 805 } 806 break; 807 case eAPA_FunctionBlockPlug: 808 { 809 FunctionBlockPlugAddress functionBlockPlugAddress( 810 m_functionBlockType, 811 m_functionBlockId, 812 m_id ); 813 extPlugInfoCmd.setPlugAddress( 814 PlugAddress( 815 convertPlugDirection( getPlugDirection() ), 816 PlugAddress::ePAM_FunctionBlock, 817 functionBlockPlugAddress ) ); 818 } 819 break; 820 default: 821 extPlugInfoCmd.setPlugAddress(PlugAddress()); 822 } 823 } 824 break; 825 default: 826 debugError( "Unknown subunit type\n" ); 827 } 828 829 extPlugInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 830 extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 831 extPlugInfoCmd.setSubunitId( getSubunitId() ); 832 extPlugInfoCmd.setSubunitType( getSubunitType() ); 833 834 return extPlugInfoCmd; 835 } 836 837 ExtendedStreamFormatCmd 838 Plug::setPlugAddrToStreamFormatCmd( 839 ExtendedStreamFormatCmd::ESubFunction subFunction) 840 { 841 ExtendedStreamFormatCmd extStreamFormatInfoCmd( 842 m_unit->get1394Service(), 843 subFunction ); 844 switch( getSubunitType() ) { 845 case eST_Unit: 846 { 847 UnitPlugAddress::EPlugType ePlugType = 848 UnitPlugAddress::ePT_Unknown; 849 switch ( m_addressType ) { 850 case eAPA_PCR: 851 ePlugType = UnitPlugAddress::ePT_PCR; 852 break; 853 case eAPA_ExternalPlug: 854 ePlugType = UnitPlugAddress::ePT_ExternalPlug; 855 break; 856 case eAPA_AsynchronousPlug: 857 ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 858 break; 859 default: 860 ePlugType = UnitPlugAddress::ePT_Unknown; 861 } 862 UnitPlugAddress unitPlugAddress( ePlugType, 863 m_id ); 864 extStreamFormatInfoCmd.setPlugAddress( 865 PlugAddress( convertPlugDirection( getPlugDirection() ), 866 PlugAddress::ePAM_Unit, 867 unitPlugAddress ) ); 868 } 869 break; 870 case eST_Music: 871 case eST_Audio: 872 { 873 switch( m_addressType ) { 874 case eAPA_SubunitPlug: 875 { 876 SubunitPlugAddress subunitPlugAddress( m_id ); 877 extStreamFormatInfoCmd.setPlugAddress( 878 PlugAddress( convertPlugDirection( getPlugDirection() ), 879 PlugAddress::ePAM_Subunit, 880 subunitPlugAddress ) ); 881 } 882 break; 883 case eAPA_FunctionBlockPlug: 884 { 885 FunctionBlockPlugAddress functionBlockPlugAddress( 886 m_functionBlockType, 887 m_functionBlockId, 888 m_id ); 889 extStreamFormatInfoCmd.setPlugAddress( 890 PlugAddress( convertPlugDirection( getPlugDirection() ), 891 PlugAddress::ePAM_FunctionBlock, 892 functionBlockPlugAddress ) ); 893 } 894 break; 895 default: 896 extStreamFormatInfoCmd.setPlugAddress(PlugAddress()); 897 } 898 } 899 break; 900 default: 901 debugError( "Unknown subunit type\n" ); 902 } 903 904 extStreamFormatInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 905 extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 906 extStreamFormatInfoCmd.setSubunitId( getSubunitId() ); 907 extStreamFormatInfoCmd.setSubunitType( getSubunitType() ); 908 909 return extStreamFormatInfoCmd; 910 } 911 912 } 763 } branches/echoaudio/src/bebob/bebob_avplug.h
r507 r524 74 74 bool discoverChannelName(); 75 75 bool discoverClusterInfo(); 76 bool discoverStreamFormat();77 bool discoverSupportedStreamFormats();78 76 bool discoverConnectionsInput(); 79 77 bool discoverConnectionsOutput(); 80 81 AVC::ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd();82 83 AVC::ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(84 AVC::ExtendedStreamFormatCmd::ESubFunction subFunction);85 78 86 79 private: branches/echoaudio/src/genericavc/avc_avdevice.cpp
r504 r524 1 1 /* 2 2 * Copyright (C) 2005-2007 by Pieter Palmers 3 * Copyright (C) 2005-2007 by Daniel Wagner 3 4 * 4 5 * This file is part of FFADO … … 30 31 31 32 #include "libavc/avc_definitions.h" 33 #include "libavc/general/avc_plug_info.h" 32 34 33 35 #include "debugmodule/debugmodule.h" … … 42 44 #include <libraw1394/csr.h> 43 45 46 using namespace AVC; 47 44 48 namespace GenericAVC { 49 50 IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_VERBOSE ); 45 51 46 52 // to define the supported devices … … 105 111 } 106 112 107 if (m_model != NULL) { 108 debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 109 m_model->vendor_name, m_model->model_name); 110 return true; 111 } 112 113 return false; 113 if (m_model == NULL) { 114 return false; 115 } 116 debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", 117 m_model->vendor_name, m_model->model_name); 118 119 if ( !Unit::discover() ) { 120 debugError( "Could not discover unit\n" ); 121 return false; 122 } 123 124 if((getAudioSubunit( 0 ) == NULL)) { 125 debugError( "Unit doesn't have an Audio subunit.\n"); 126 return false; 127 } 128 if((getMusicSubunit( 0 ) == NULL)) { 129 debugError( "Unit doesn't have a Music subunit.\n"); 130 return false; 131 } 132 133 return true; 114 134 } 115 135 116 136 int 117 137 AvDevice::getSamplingFrequency( ) { 118 return 0; 119 } 120 121 bool 122 AvDevice::setSamplingFrequency( int samplingFrequency ) 123 { 124 138 AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 139 if ( !inputPlug ) { 140 debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 141 return false; 142 } 143 AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 144 if ( !outputPlug ) { 145 debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 146 return false; 147 } 148 149 int samplerate_playback=inputPlug->getSampleRate(); 150 int samplerate_capture=outputPlug->getSampleRate(); 151 152 if (samplerate_playback != samplerate_capture) { 153 debugWarning("Samplerates for capture and playback differ!\n"); 154 } 155 return samplerate_capture; 156 } 157 158 bool 159 AvDevice::setSamplingFrequency( int s ) 160 { 161 ESamplingFrequency samplingFrequency=parseSampleRate( s ); 162 bool snoopMode=false; 163 if(!getOption("snoopMode", snoopMode)) { 164 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 165 } 166 167 if(snoopMode) { 168 int current_sr=getSamplingFrequency(); 169 if (current_sr != convertESamplingFrequency( samplingFrequency ) ) { 170 debugError("In snoop mode it is impossible to set the sample rate.\n"); 171 debugError("Please start the client with the correct setting.\n"); 172 return false; 173 } 174 return true; 175 } else { 176 AVC::Plug* plug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 177 if ( !plug ) { 178 debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 179 return false; 180 } 181 182 if ( !plug->setSampleRate( convertESamplingFrequency( samplingFrequency ) ) ) 183 { 184 debugError( "setSampleRate: Setting sample rate failed\n" ); 185 return false; 186 } 187 188 plug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 189 if ( !plug ) { 190 debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 191 return false; 192 } 193 194 if ( !plug->setSampleRate( convertESamplingFrequency( samplingFrequency ) ) ) 195 { 196 debugError( "setSampleRate: Setting sample rate failed\n" ); 197 return false; 198 } 199 200 debugOutput( DEBUG_LEVEL_VERBOSE, 201 "setSampleRate: Set sample rate to %d\n", 202 convertESamplingFrequency( samplingFrequency ) ); 203 return true; 204 } 205 // not executable 125 206 return false; 207 126 208 } 127 209 128 210 bool 129 211 AvDevice::lock() { 212 bool snoopMode=false; 213 if(!getOption("snoopMode", snoopMode)) { 214 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 215 } 216 217 if (snoopMode) { 218 // don't lock 219 } else { 220 // return Unit::reserve(4); 221 } 130 222 131 223 return true; 132 224 } 133 225 134 135 226 bool 136 227 AvDevice::unlock() { 137 228 bool snoopMode=false; 229 if(!getOption("snoopMode", snoopMode)) { 230 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 231 } 232 233 if (snoopMode) { 234 // don't unlock 235 } else { 236 // return Unit::reserve(0); 237 } 138 238 return true; 139 239 } … … 145 245 "%s %s at node %d\n", m_model->vendor_name, m_model->model_name, 146 246 m_nodeId); 247 248 m_pPlugManager->showPlugs(); 249 flushDebugOutput(); 147 250 } 148 251 149 252 bool 150 253 AvDevice::prepare() { 151 254 bool snoopMode=false; 255 if(!getOption("snoopMode", snoopMode)) { 256 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 257 } 258 259 /////////// 260 // get plugs 261 262 AVC::Plug* inputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Input, 0 ); 263 if ( !inputPlug ) { 264 debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 265 return false; 266 } 267 AVC::Plug* outputPlug = getPlugById( m_pcrPlugs, Plug::eAPD_Output, 0 ); 268 if ( !outputPlug ) { 269 debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 270 return false; 271 } 272 273 int samplerate=outputPlug->getSampleRate(); 274 275 debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing receive processor...\n"); 276 // create & add streamprocessors 277 Streaming::StreamProcessor *p; 278 279 p=new Streaming::AmdtpReceiveStreamProcessor( 280 get1394Service().getPort(), 281 samplerate, 282 outputPlug->getNrOfChannels()); 283 284 if(!p->init()) { 285 debugFatal("Could not initialize receive processor!\n"); 286 delete p; 287 return false; 288 } 289 290 if (!addPlugToProcessor(*outputPlug,p, 291 Streaming::Port::E_Capture)) { 292 debugFatal("Could not add plug to processor!\n"); 293 delete p; 294 return false; 295 } 296 297 m_receiveProcessors.push_back(p); 298 299 // do the transmit processor 300 debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing transmit processor%s...\n", 301 (snoopMode?" in snoop mode":"")); 302 if (snoopMode) { 303 // we are snooping, so this is receive too. 304 p=new Streaming::AmdtpReceiveStreamProcessor( 305 get1394Service().getPort(), 306 samplerate, 307 inputPlug->getNrOfChannels()); 308 } else { 309 p=new Streaming::AmdtpTransmitStreamProcessor( 310 get1394Service().getPort(), 311 samplerate, 312 inputPlug->getNrOfChannels()); 313 } 314 315 if(!p->init()) { 316 debugFatal("Could not initialize transmit processor %s!\n", 317 (snoopMode?" in snoop mode":"")); 318 delete p; 319 return false; 320 } 321 322 if (snoopMode) { 323 if (!addPlugToProcessor(*inputPlug,p, 324 Streaming::Port::E_Capture)) { 325 debugFatal("Could not add plug to processor!\n"); 326 return false; 327 } 328 } else { 329 if (!addPlugToProcessor(*inputPlug,p, 330 Streaming::Port::E_Playback)) { 331 debugFatal("Could not add plug to processor!\n"); 332 return false; 333 } 334 } 335 336 // we put this SP into the transmit SP vector, 337 // no matter if we are in snoop mode or not 338 // this allows us to find out what direction 339 // a certain stream should have. 340 m_transmitProcessors.push_back(p); 341 342 return true; 343 } 344 345 bool 346 AvDevice::addPlugToProcessor( 347 AVC::Plug& plug, 348 Streaming::StreamProcessor *processor, 349 Streaming::AmdtpAudioPort::E_Direction direction) { 350 351 debugOutput(DEBUG_LEVEL_VERBOSE, " Adding plug %s to processor\n", plug.getName()); 352 353 std::string id=std::string("dev?"); 354 if(!getOption("id", id)) { 355 debugWarning("Could not retrieve id parameter, defauling to 'dev?'\n"); 356 } 357 358 Plug::ClusterInfoVector& clusterInfos = plug.getClusterInfos(); 359 for ( Plug::ClusterInfoVector::const_iterator it = clusterInfos.begin(); 360 it != clusterInfos.end(); 361 ++it ) 362 { 363 const Plug::ClusterInfo* clusterInfo = &( *it ); 364 365 debugOutput(DEBUG_LEVEL_VERBOSE, " Adding cluster %s\n", clusterInfo->m_name.c_str()); 366 367 Plug::ChannelInfoVector channelInfos = clusterInfo->m_channelInfos; 368 for ( Plug::ChannelInfoVector::const_iterator it = channelInfos.begin(); 369 it != channelInfos.end(); 370 ++it ) 371 { 372 373 const Plug::ChannelInfo* channelInfo = &( *it ); 374 375 std::ostringstream portname; 376 377 portname << id << "_" << channelInfo->m_name; 378 379 Streaming::Port *p=NULL; 380 switch(clusterInfo->m_portType) { 381 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Speaker: 382 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Headphone: 383 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Microphone: 384 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Line: 385 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Analog: 386 debugOutput(DEBUG_LEVEL_VERBOSE, " Adding audio channel %s (pos=0x%02X, loc=0x%02X)\n", 387 channelInfo->m_name.c_str(), channelInfo->m_streamPosition, channelInfo->m_location); 388 p=new Streaming::AmdtpAudioPort( 389 portname.str(), 390 direction, 391 channelInfo->m_streamPosition, 392 channelInfo->m_location, 393 Streaming::AmdtpPortInfo::E_MBLA 394 ); 395 break; 396 397 case ExtendedPlugInfoClusterInfoSpecificData::ePT_MIDI: 398 debugOutput(DEBUG_LEVEL_VERBOSE, " Adding MIDI channel %s (pos=0x%02X, loc=0x%02X)\n", 399 channelInfo->m_name.c_str(), channelInfo->m_streamPosition, processor->getPortCount(Streaming::Port::E_Midi)); 400 p=new Streaming::AmdtpMidiPort( 401 portname.str(), 402 direction, 403 // HACK: for audiofire2 only !!! 404 (direction==Streaming::Port::E_Capture?4:6), 405 // channelInfo->m_streamPosition, 406 // Workaround for out-of-spec hardware 407 // should be: 408 // channelInfo->m_location, 409 // but now we renumber the midi channels' location as they 410 // are discovered 411 processor->getPortCount(Streaming::Port::E_Midi), 412 Streaming::AmdtpPortInfo::E_Midi 413 ); 414 415 break; 416 case ExtendedPlugInfoClusterInfoSpecificData::ePT_SPDIF: 417 case ExtendedPlugInfoClusterInfoSpecificData::ePT_ADAT: 418 case ExtendedPlugInfoClusterInfoSpecificData::ePT_TDIF: 419 case ExtendedPlugInfoClusterInfoSpecificData::ePT_MADI: 420 case ExtendedPlugInfoClusterInfoSpecificData::ePT_Digital: 421 case ExtendedPlugInfoClusterInfoSpecificData::ePT_NoType: 422 default: 423 // unsupported 424 break; 425 } 426 427 if (!p) { 428 debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",channelInfo->m_name.c_str()); 429 } else { 430 431 if (!processor->addPort(p)) { 432 debugWarning("Could not register port with stream processor\n"); 433 return false; 434 } 435 } 436 } 437 } 152 438 return true; 153 439 } … … 155 441 int 156 442 AvDevice::getStreamCount() { 157 return 0;443 return m_receiveProcessors.size() + m_transmitProcessors.size(); 158 444 } 159 445 … … 161 447 AvDevice::getStreamProcessorByIndex(int i) { 162 448 449 if (i<(int)m_receiveProcessors.size()) { 450 return m_receiveProcessors.at(i); 451 } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 452 return m_transmitProcessors.at(i-m_receiveProcessors.size()); 453 } 454 163 455 return NULL; 164 456 } … … 166 458 bool 167 459 AvDevice::startStreamByIndex(int i) { 460 int iso_channel=-1; 461 bool snoopMode=false; 462 if(!getOption("snoopMode", snoopMode)) { 463 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 464 } 465 466 if (i<(int)m_receiveProcessors.size()) { 467 int n=i; 468 Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 469 470 if(snoopMode) { // a stream from the device to another host 471 // FIXME: put this into a decent framework! 472 // we should check the oPCR[n] on the device 473 struct iec61883_oPCR opcr; 474 if (iec61883_get_oPCRX( 475 get1394Service().getHandle(), 476 m_pConfigRom->getNodeId() | 0xffc0, 477 (quadlet_t *)&opcr, 478 n)) { 479 480 debugWarning("Error getting the channel for SP %d\n",i); 481 return false; 482 } 483 484 iso_channel=opcr.channel; 485 } else { 486 iso_channel=get1394Service().allocateIsoChannelCMP( 487 m_pConfigRom->getNodeId() | 0xffc0, n, 488 get1394Service().getLocalNodeId()| 0xffc0, -1); 489 } 490 if (iso_channel<0) { 491 debugError("Could not allocate ISO channel for SP %d\n",i); 492 return false; 493 } 494 495 debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 496 497 p->setChannel(iso_channel); 498 return true; 499 500 } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 501 int n=i-m_receiveProcessors.size(); 502 Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 503 504 if(snoopMode) { // a stream from another host to the device 505 // FIXME: put this into a decent framework! 506 // we should check the iPCR[n] on the device 507 struct iec61883_iPCR ipcr; 508 if (iec61883_get_iPCRX( 509 get1394Service().getHandle(), 510 m_pConfigRom->getNodeId() | 0xffc0, 511 (quadlet_t *)&ipcr, 512 n)) { 513 514 debugWarning("Error getting the channel for SP %d\n",i); 515 return false; 516 } 517 518 iso_channel=ipcr.channel; 519 520 } else { 521 iso_channel=get1394Service().allocateIsoChannelCMP( 522 get1394Service().getLocalNodeId()| 0xffc0, -1, 523 m_pConfigRom->getNodeId() | 0xffc0, n); 524 } 525 526 if (iso_channel<0) { 527 debugError("Could not allocate ISO channel for SP %d\n",i); 528 return false; 529 } 530 531 debugOutput(DEBUG_LEVEL_VERBOSE, "Started SP %d on channel %d\n",i,iso_channel); 532 533 p->setChannel(iso_channel); 534 return true; 535 } 536 537 debugError("SP index %d out of range!\n",i); 168 538 return false; 169 539 } … … 171 541 bool 172 542 AvDevice::stopStreamByIndex(int i) { 543 bool snoopMode=false; 544 if(!getOption("snoopMode", snoopMode)) { 545 debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 546 } 547 548 if (i<(int)m_receiveProcessors.size()) { 549 int n=i; 550 Streaming::StreamProcessor *p=m_receiveProcessors.at(n); 551 552 if(snoopMode) { 553 554 } else { 555 // deallocate ISO channel 556 if(!get1394Service().freeIsoChannel(p->getChannel())) { 557 debugError("Could not deallocate iso channel for SP %d\n",i); 558 return false; 559 } 560 } 561 p->setChannel(-1); 562 563 return true; 564 565 } else if (i<(int)m_receiveProcessors.size() + (int)m_transmitProcessors.size()) { 566 int n=i-m_receiveProcessors.size(); 567 Streaming::StreamProcessor *p=m_transmitProcessors.at(n); 568 569 if(snoopMode) { 570 571 } else { 572 // deallocate ISO channel 573 if(!get1394Service().freeIsoChannel(p->getChannel())) { 574 debugError("Could not deallocate iso channel for SP %d\n",i); 575 return false; 576 } 577 } 578 p->setChannel(-1); 579 580 return true; 581 } 582 583 debugError("SP index %d out of range!\n",i); 173 584 return false; 174 585 } branches/echoaudio/src/genericavc/avc_avdevice.h
r504 r524 1 1 /* 2 2 * Copyright (C) 2005-2007 by Pieter Palmers 3 * Copyright (C) 2005-2007 by Daniel Wagner 3 4 * 4 5 * This file is part of FFADO … … 28 29 29 30 #include "debugmodule/debugmodule.h" 31 30 32 #include "libavc/avc_definitions.h" 33 #include "libavc/general/avc_unit.h" 34 #include "libavc/general/avc_subunit.h" 35 #include "libavc/general/avc_plug.h" 36 37 #include "libstreaming/AmdtpStreamProcessor.h" 38 #include "libstreaming/AmdtpPort.h" 39 #include "libstreaming/AmdtpPortInfo.h" 31 40 32 41 class ConfigRom; … … 43 52 }; 44 53 45 class AvDevice : public FFADODevice {54 class AvDevice : public FFADODevice, public AVC::Unit { 46 55 public: 47 56 AvDevice( std::auto_ptr<ConfigRom>( configRom ), … … 67 76 bool startStreamByIndex(int i); 68 77 bool stopStreamByIndex(int i); 69 78 79 // redefinition to resolve ambiguity 80 Ieee1394Service& get1394Service() 81 { return FFADODevice::get1394Service(); }; 82 ConfigRom& getConfigRom() const 83 { return FFADODevice::getConfigRom(); }; 84 70 85 protected: 86 bool addPlugToProcessor( AVC::Plug& plug, Streaming::StreamProcessor *processor, 87 Streaming::AmdtpAudioPort::E_Direction direction); 88 bool setSamplingFrequencyPlug( AVC::Plug& plug, 89 AVC::Plug::EPlugDirection direction, 90 AVC::ESamplingFrequency samplingFrequency ); 91 71 92 struct VendorModelEntry *m_model; 72 93 94 // streaming stuff 95 typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector; 96 StreamProcessorVector m_receiveProcessors; 97 StreamProcessorVector m_transmitProcessors; 98 99 DECLARE_DEBUG_MODULE; 73 100 }; 74 101 branches/echoaudio/src/libavc/avc_definitions.cpp
r505 r524 23 23 24 24 #include "avc_definitions.h" 25 25 #include <libiec61883/iec61883.h> 26 26 27 27 namespace AVC { … … 154 154 }; 155 155 156 157 } 156 enum ESubunitType byteToSubunitType(byte_t s) { 157 switch (s) { 158 case eST_Monitor: 159 return eST_Monitor; 160 case eST_Audio: 161 return eST_Audio; 162 case eST_Printer: 163 return eST_Printer; 164 case eST_Disc: 165 return eST_Disc; 166 case eST_VCR: 167 return eST_VCR; 168 case eST_Tuner: 169 return eST_Tuner; 170 case eST_CA: 171 return eST_CA; 172 case eST_Camera: 173 return eST_Camera; 174 case eST_Panel: 175 return eST_Panel; 176 case eST_BulltinBoard: 177 return eST_BulltinBoard; 178 case eST_CameraStorage: 179 return eST_CameraStorage; 180 case eST_Music: 181 return eST_Music; 182 case eST_VendorUnique: 183 return eST_VendorUnique; 184 case eST_Reserved: 185 return eST_Reserved; 186 case eST_Extended: 187 return eST_Extended; 188 default: 189 case eST_Unit: 190 return eST_Unit; 191 } 192 } 193 194 unsigned int fdfSfcToSampleRate(byte_t fdf) { 195 switch(fdf & 0x07) { 196 default: return 0; 197 case IEC61883_FDF_SFC_32KHZ: return 32000; 198 case IEC61883_FDF_SFC_44K1HZ: return 44100; 199 case IEC61883_FDF_SFC_48KHZ: return 48000; 200 case IEC61883_FDF_SFC_88K2HZ: return 88200; 201 case IEC61883_FDF_SFC_96KHZ: return 96000; 202 case IEC61883_FDF_SFC_176K4HZ: return 176400; 203 case IEC61883_FDF_SFC_192KHZ: return 192000; 204 } 205 } 206 207 byte_t sampleRateToFdfSfc(unsigned int rate) { 208 switch(rate) { 209 default: return 0x07; 210 case 32000: return IEC61883_FDF_SFC_32KHZ; 211 case 44100: return IEC61883_FDF_SFC_44K1HZ; 212 case 48000: return IEC61883_FDF_SFC_48KHZ; 213 case 88200: return IEC61883_FDF_SFC_88K2HZ; 214 case 96000: return IEC61883_FDF_SFC_96KHZ; 215 case 176400: return IEC61883_FDF_SFC_176K4HZ; 216 case 192000: return IEC61883_FDF_SFC_192KHZ; 217 } 218 } 219 220 } branches/echoaudio/src/libavc/avc_definitions.h
r504 r524 22 22 */ 23 23 24 #ifndef AV DDEFINITIONS_H25 #define AV DDEFINITIONS_H24 #ifndef AVCDEFINITIONS_H 25 #define AVCDEFINITIONS_H 26 26 27 27 #include <libavc1394/avc1394.h> … … 116 116 }; 117 117 118 enum ESubunitType byteToSubunitType(byte_t s); 119 118 120 /** 119 121 * \brief the possible sampling frequencies … … 151 153 std::ostream& operator<<( std::ostream& stream, ESamplingFrequency samplingFrequency ); 152 154 155 /** 156 * \brief Convert from a FDF SFC field value to an integer sample rate 157 * @param fdf fdf sfc field value 158 * @return sample rate 159 */ 160 unsigned int fdfSfcToSampleRate(byte_t fdf); 161 162 /** 163 * \brief Convert from an integer sample rate to a78 FDF SFC field value 164 * @param rate integer sample rate 165 * @return fdf sfc field value 166 */ 167 byte_t sampleRateToFdfSfc(unsigned int rate); 168 153 169 } 154 170 155 #endif // AV DDEFINITIONS_H171 #endif // AVCDEFINITIONS_H branches/echoaudio/src/libavc/descriptors/avc_descriptor.cpp
r503 r524 25 25 #include "avc_descriptor_cmd.h" 26 26 27 #include "../general/avc_unit.h" 28 #include "../general/avc_subunit.h" 29 27 30 #include "../util/avc_serialize.h" 28 31 #include "libieee1394/ieee1394service.h" 32 #include "libieee1394/configrom.h" 29 33 30 34 namespace AVC { … … 101 105 102 106 //---------------------- 103 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service)107 AVCDescriptor::AVCDescriptor( Unit* unit ) 104 108 : IBusData() 105 , m_p1394Service( &ieee1394service ) 106 , m_nodeId( 0 ) 107 , m_subunit_type( eST_Unit ) 108 , m_subunit_id( 0x07 ) 109 , m_unit( unit ) 110 , m_subunit ( NULL ) 109 111 , m_specifier ( AVCDescriptorSpecifier::eInvalid ) 110 112 , m_data ( NULL ) 111 113 , m_descriptor_length(0) 112 { 113 } 114 115 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service, 116 fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId)114 , m_loaded ( false ) 115 { 116 } 117 118 AVCDescriptor::AVCDescriptor( Unit* unit, Subunit* subunit ) 117 119 : IBusData() 118 , m_p1394Service( &ieee1394service ) 119 , m_nodeId( nodeId ) 120 , m_subunit_type( subunitType ) 121 , m_subunit_id( subunitId ) 120 , m_unit( unit ) 121 , m_subunit ( subunit ) 122 122 , m_specifier ( AVCDescriptorSpecifier::eInvalid ) 123 123 , m_data ( NULL ) 124 124 , m_descriptor_length(0) 125 { 126 } 127 128 AVCDescriptor::AVCDescriptor( Ieee1394Service& ieee1394service, 129 fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId,125 , m_loaded ( false ) 126 { 127 } 128 129 AVCDescriptor::AVCDescriptor( Unit* unit, Subunit* subunit, 130 130 AVCDescriptorSpecifier s ) 131 131 : IBusData() 132 , m_p1394Service( &ieee1394service ) 133 , m_nodeId( nodeId ) 134 , m_subunit_type( subunitType ) 135 , m_subunit_id( subunitId ) 132 , m_unit( unit ) 133 , m_subunit ( subunit ) 136 134 , m_specifier ( s ) 137 135 , m_data ( NULL ) 138 136 , m_descriptor_length(0) 137 , m_loaded ( false ) 139 138 { 140 139 } … … 144 143 if (m_data != NULL) free(m_data); 145 144 } 145 bool 146 AVCDescriptor::reload() 147 { 148 m_loaded=false; 149 return load(); 150 } 146 151 147 152 bool … … 149 154 { 150 155 bool result; 151 OpenDescriptorCmd openDescCmd(*m_p1394Service); 156 157 if (m_loaded) { 158 debugOutput(DEBUG_LEVEL_VERBOSE, "Descriptor already loaded, not re-loading...\n" ); 159 return true; 160 } 161 162 OpenDescriptorCmd openDescCmd(m_unit->get1394Service()); 152 163 153 164 debugOutput(DEBUG_LEVEL_VERBOSE, " Open descriptor (%s)\n",getDescriptorName()); 154 165 openDescCmd.setMode( OpenDescriptorCmd::eRead ); 155 166 openDescCmd.m_specifier=&m_specifier; 156 openDescCmd.setNodeId( m_ nodeId);167 openDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 157 168 openDescCmd.setCommandType( AVCCommand::eCT_Control ); 158 169 openDescCmd.setSubunitType( getSubunitType() ); … … 168 179 169 180 debugOutput(DEBUG_LEVEL_VERBOSE, " Read status descriptor\n"); 170 ReadDescriptorCmd readDescCmd( *m_p1394Service);181 ReadDescriptorCmd readDescCmd(m_unit->get1394Service()); 171 182 readDescCmd.m_specifier=&m_specifier; 172 readDescCmd.setNodeId( m_ nodeId);183 readDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 173 184 readDescCmd.setCommandType( AVCCommand::eCT_Control ); 174 185 readDescCmd.setSubunitType( getSubunitType() ); … … 210 221 readDescCmd.clear(); 211 222 readDescCmd.m_specifier=&m_specifier; 212 readDescCmd.setNodeId( m_ nodeId);223 readDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 213 224 readDescCmd.setCommandType( AVCCommand::eCT_Control ); 214 225 readDescCmd.setSubunitType( getSubunitType() ); … … 251 262 openDescCmd.setMode( OpenDescriptorCmd::eClose ); 252 263 openDescCmd.m_specifier=&m_specifier; 253 openDescCmd.setNodeId( m_ nodeId);264 openDescCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 254 265 openDescCmd.setCommandType( AVCCommand::eCT_Control ); 255 266 openDescCmd.setSubunitType( getSubunitType() ); … … 289 300 } 290 301 #endif 302 m_loaded=true; 291 303 return true; 292 304 } … … 309 321 return new AVCDescriptor( *this ); 310 322 } 311 bool312 AVCDescriptor::setSubunitType(ESubunitType subunitType)313 {314 m_subunit_type = subunitType;315 return true;316 }317 318 bool319 AVCDescriptor::setNodeId( fb_nodeid_t nodeId )320 {321 m_nodeId = nodeId;322 return true;323 }324 325 bool326 AVCDescriptor::setSubunitId(subunit_id_t subunitId)327 {328 m_subunit_id = subunitId & 0x7;329 return true;330 }331 323 332 324 ESubunitType 333 AVCDescriptor::getSubunitType() 334 { 335 return m_subunit_type;336 } 337 338 subunit_id_t 339 AVCDescriptor::getSubunitId() 340 { 341 return m_subunit_id;342 } 343 344 bool 345 AVCDescriptor::setVerbose ( int verboseLevel )325 AVCDescriptor::getSubunitType() const 326 { 327 return (m_subunit==NULL?eST_Unit:m_subunit->getSubunitType()); 328 } 329 330 subunit_id_t 331 AVCDescriptor::getSubunitId() const 332 { 333 return (m_subunit==NULL?0xFF:m_subunit->getSubunitId()); 334 } 335 336 bool 337 AVCDescriptor::setVerboseLevel( int verboseLevel ) 346 338 { 347 339 setDebugLevel(verboseLevel); branches/echoaudio/src/libavc/descriptors/avc_descriptor.h
r503 r524 47 47 48 48 namespace AVC { 49 50 class Unit; 51 class Subunit; 49 52 50 53 class IOSSerialize; … … 112 115 113 116 // note: in the end these have to be protected 114 AVCDescriptor( Ieee1394Service& ieee1394service ); 115 AVCDescriptor( Ieee1394Service& ieee1394service, 116 fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId ); 117 AVCDescriptor( Ieee1394Service& ieee1394service, 118 fb_nodeid_t nodeId, ESubunitType subunitType, subunit_id_t subunitId, 119 AVCDescriptorSpecifier s ); 117 AVCDescriptor( Unit* unit ); 118 AVCDescriptor( Unit* unit, Subunit* subunit ); 119 AVCDescriptor( Unit* unit, Subunit* subunit, AVCDescriptorSpecifier s ); 120 120 virtual ~AVCDescriptor(); 121 121 … … 123 123 124 124 void setSpecifier(AVCDescriptorSpecifier s) {m_specifier=s;}; 125 126 bool setNodeId( fb_nodeid_t nodeId ); 127 bool setSubunitType( ESubunitType subunitType ); 128 bool setSubunitId( subunit_id_t subunitId ); 129 130 ESubunitType getSubunitType(); 131 subunit_id_t getSubunitId(); 132 133 bool setVerbose( int verboseLevel ); 125 126 ESubunitType getSubunitType() const; 127 subunit_id_t getSubunitId() const; 128 129 bool setVerboseLevel( int verboseLevel ); 134 130 int getVerboseLevel(); 135 131 … … 138 134 139 135 bool load(); 136 bool reload(); 140 137 141 138 protected: 142 139 143 Ieee1394Service* m_p1394Service; 144 fb_nodeid_t m_nodeId; 145 ESubunitType m_subunit_type; 146 subunit_id_t m_subunit_id; 140 Unit* m_unit; 141 Subunit* m_subunit; 147 142 148 143 AVCDescriptorSpecifier m_specifier; 149 144 150 byte_t *m_data; 151 uint16_t m_descriptor_length; 152 153 private: 154 155 145 byte_t* m_data; 146 uint16_t m_descriptor_length; 147 148 bool m_loaded; 149 156 150 }; 157 151 branches/echoaudio/src/libavc/general/avc_connect.cpp
r505 r524 45 45 ConnectCmd::serialize( IOSSerialize& se ) 46 46 { 47 AVCCommand::serialize( se ); 48 return true; 47 bool result=true; 48 result &= AVCCommand::serialize( se ); 49 return result; 49 50 } 50 51 … … 52 53 ConnectCmd::deserialize( IISDeserialize& de ) 53 54 { 54 AVCCommand::deserialize( de ); 55 return true; 55 bool result=true; 56 result &= AVCCommand::deserialize( de ); 57 return result; 56 58 } 57 59 branches/echoaudio/src/libavc/general/avc_plug.cpp
r509 r524 25 25 #include "avc_plug.h" 26 26 #include "avc_unit.h" 27 #include "avc_signal_format.h" 28 27 29 #include "libieee1394/configrom.h" 28 30 … … 123 125 124 126 bool 127 Plug::discover() 128 { 129 130 if ( !initFromDescriptor() ) { 131 debugError( "discover: Could not init plug from descriptor (%d,%d,%d,%d,%d)\n", 132 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 133 // return false; 134 } 135 136 if ( !discoverPlugType() ) { 137 debugError( "discover: Could not discover plug type (%d,%d,%d,%d,%d)\n", 138 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 139 return false; 140 } 141 142 if ( !discoverName() ) { 143 debugError( "Could not discover name (%d,%d,%d,%d,%d)\n", 144 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 145 return false; 146 } 147 148 if ( !discoverNoOfChannels() ) { 149 debugError( "Could not discover number of channels " 150 "(%d,%d,%d,%d,%d)\n", 151 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 152 return false; 153 } 154 155 if ( !discoverChannelPosition() ) { 156 debugError( "Could not discover channel positions " 157 "(%d,%d,%d,%d,%d)\n", 158 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 159 return false; 160 } 161 162 if ( !discoverChannelName() ) { 163 debugError( "Could not discover channel name " 164 "(%d,%d,%d,%d,%d)\n", 165 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 166 return false; 167 } 168 169 if ( !discoverClusterInfo() ) { 170 debugError( "Could not discover channel name " 171 "(%d,%d,%d,%d,%d)\n", 172 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 173 return false; 174 } 175 176 if ( !discoverStreamFormat() ) { 177 debugError( "Could not discover stream format " 178 "(%d,%d,%d,%d,%d)\n", 179 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 180 // return false; 181 } 182 183 if ( !discoverSupportedStreamFormats() ) { 184 debugError( "Could not discover supported stream formats " 185 "(%d,%d,%d,%d,%d)\n", 186 m_unit->getConfigRom().getNodeId(), getSubunitType(), getSubunitId(), m_direction, m_id ); 187 // return false; 188 } 189 190 return m_unit->getPlugManager().addPlug( *this ); 191 } 192 193 bool 194 Plug::initFromDescriptor() 195 { 196 if(getSubunitType()==eST_Unit) { 197 debugOutput(DEBUG_LEVEL_VERBOSE, "Not loading unit plug from descriptor.\n"); 198 return true; 199 } else { 200 return m_subunit->initPlugFromDescriptor(*this); 201 } 202 } 203 204 bool 205 Plug::discoverConnections() 206 { 207 return discoverConnectionsInput() && discoverConnectionsOutput(); 208 } 209 210 bool 211 Plug::discoverPlugType() 212 { 213 214 return true; 215 } 216 217 bool 218 Plug::discoverName() 219 { 220 // name already set 221 if (m_name != "") return true; 222 223 m_name = plugAddressTypeToString(getPlugAddressType()); 224 m_name += " "; 225 m_name += plugTypeToString(getPlugType()); 226 m_name += " "; 227 m_name += plugDirectionToString(getPlugDirection()); 228 229 return true; 230 } 231 232 bool 233 Plug::discoverNoOfChannels() 234 { 235 236 return true; 237 } 238 239 bool 240 Plug::discoverChannelPosition() 241 { 242 243 return true; 244 } 245 246 bool 247 Plug::discoverChannelName() 248 { 249 250 return true; 251 } 252 253 bool 254 Plug::discoverClusterInfo() 255 { 256 257 return true; 258 } 259 260 bool 261 Plug::discoverStreamFormat() 262 { 263 ExtendedStreamFormatCmd extStreamFormatCmd = 264 setPlugAddrToStreamFormatCmd( ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 265 extStreamFormatCmd.setVerbose( getDebugLevel() ); 266 267 if ( !extStreamFormatCmd.fire() ) { 268 debugError( "stream format command failed\n" ); 269 return false; 270 } 271 272 if ( ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NoStreamFormat ) 273 || ( extStreamFormatCmd.getStatus() == ExtendedStreamFormatCmd::eS_NotUsed ) ) 274 { 275 debugOutput( DEBUG_LEVEL_VERBOSE, 276 "No stream format information available\n" ); 277 return true; 278 } 279 280 if ( !extStreamFormatCmd.getFormatInformation() ) { 281 debugWarning( "No stream format information for plug found -> skip\n" ); 282 return true; 283 } 284 285 if ( extStreamFormatCmd.getFormatInformation()->m_root 286 != FormatInformation::eFHR_AudioMusic ) 287 { 288 debugWarning( "Format hierarchy root is not Audio&Music -> skip\n" ); 289 return true; 290 } 291 292 FormatInformation* formatInfo = 293 extStreamFormatCmd.getFormatInformation(); 294 FormatInformationStreamsCompound* compoundStream 295 = dynamic_cast< FormatInformationStreamsCompound* > ( 296 formatInfo->m_streams ); 297 if ( compoundStream ) { 298 m_samplingFrequency = 299 compoundStream->m_samplingFrequency; 300 debugOutput( DEBUG_LEVEL_VERBOSE, 301 "%s plug %d uses " 302 "sampling frequency %d, nr of stream infos = %d\n", 303 getName(), 304 m_id, 305 m_samplingFrequency, 306 compoundStream->m_numberOfStreamFormatInfos ); 307 308 for ( int i = 1; 309 i <= compoundStream->m_numberOfStreamFormatInfos; 310 ++i ) 311 { 312 ClusterInfo* clusterInfo = 313 const_cast<ClusterInfo*>( getClusterInfoByIndex( i ) ); 314 315 if ( !clusterInfo ) { 316 debugError( "No matching cluster " 317 "info found for index %d\n", i ); 318 return false; 319 } 320 StreamFormatInfo* streamFormatInfo = 321 compoundStream->m_streamFormatInfos[ i - 1 ]; 322 323 debugOutput( DEBUG_LEVEL_VERBOSE, 324 "number of channels = %d, stream format = %d\n", 325 streamFormatInfo->m_numberOfChannels, 326 streamFormatInfo->m_streamFormat ); 327 328 int nrOfChannels = clusterInfo->m_nrOfChannels; 329 if ( streamFormatInfo->m_streamFormat == 330 FormatInformation::eFHL2_AM824_MIDI_CONFORMANT ) 331 { 332 // 8 logical midi channels fit into 1 channel 333 nrOfChannels = ( ( nrOfChannels + 7 ) / 8 ); 334 } 335 // sanity check 336 if ( nrOfChannels != streamFormatInfo->m_numberOfChannels ) 337 { 338 debugWarning( "Number of channels " 339 "mismatch: '%s' plug discovering reported " 340 "%d channels for cluster '%s', while stream " 341 "format reported %d\n", 342 getName(), 343 nrOfChannels, 344 clusterInfo->m_name.c_str(), 345 streamFormatInfo->m_numberOfChannels); 346 } 347 clusterInfo->m_streamFormat = streamFormatInfo->m_streamFormat; 348 349 debugOutput( DEBUG_LEVEL_VERBOSE, 350 "%s plug %d cluster info %d ('%s'): " 351 "stream format %d\n", 352 getName(), 353 m_id, 354 i, 355 clusterInfo->m_name.c_str(), 356 clusterInfo->m_streamFormat ); 357 } 358 } 359 360 FormatInformationStreamsSync* syncStream 361 = dynamic_cast< FormatInformationStreamsSync* > ( 362 formatInfo->m_streams ); 363 if ( syncStream ) { 364 m_samplingFrequency = 365 syncStream->m_samplingFrequency; 366 debugOutput( DEBUG_LEVEL_VERBOSE, 367 "%s plug %d is sync stream with sampling frequency %d\n", 368 getName(), 369 m_id, 370 m_samplingFrequency ); 371 } 372 373 374 if ( !compoundStream && !syncStream ) 375 { 376 debugError( "Unsupported stream format\n" ); 377 return false; 378 } 379 380 return true; 381 } 382 383 bool 384 Plug::discoverSupportedStreamFormats() 385 { 386 ExtendedStreamFormatCmd extStreamFormatCmd = 387 setPlugAddrToStreamFormatCmd( 388 ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList); 389 extStreamFormatCmd.setVerbose( getDebugLevel() ); 390 391 int i = 0; 392 bool cmdSuccess = false; 393 394 do { 395 extStreamFormatCmd.setIndexInStreamFormat( i ); 396 extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 397 cmdSuccess = extStreamFormatCmd.fire(); 398 if ( cmdSuccess 399 && ( extStreamFormatCmd.getResponse() 400 == AVCCommand::eR_Implemented ) ) 401 { 402 FormatInfo formatInfo; 403 formatInfo.m_index = i; 404 bool formatInfoIsValid = true; 405 406 FormatInformationStreamsSync* syncStream 407 = dynamic_cast< FormatInformationStreamsSync* > 408 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 409 if ( syncStream ) { 410 formatInfo.m_samplingFrequency = 411 syncStream->m_samplingFrequency; 412 formatInfo.m_isSyncStream = true ; 413 } 414 415 FormatInformationStreamsCompound* compoundStream 416 = dynamic_cast< FormatInformationStreamsCompound* > 417 ( extStreamFormatCmd.getFormatInformation()->m_streams ); 418 if ( compoundStream ) { 419 formatInfo.m_samplingFrequency = 420 compoundStream->m_samplingFrequency; 421 formatInfo.m_isSyncStream = false; 422 for ( int j = 0; 423 j < compoundStream->m_numberOfStreamFormatInfos; 424 ++j ) 425 { 426 switch ( compoundStream->m_streamFormatInfos[j]->m_streamFormat ) { 427 case AVC1394_STREAM_FORMAT_AM824_IEC60968_3: 428 formatInfo.m_audioChannels += 429 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 430 break; 431 case AVC1394_STREAM_FORMAT_AM824_MULTI_BIT_LINEAR_AUDIO_RAW: 432 formatInfo.m_audioChannels += 433 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 434 break; 435 case AVC1394_STREAM_FORMAT_AM824_MIDI_CONFORMANT: 436 formatInfo.m_midiChannels += 437 compoundStream->m_streamFormatInfos[j]->m_numberOfChannels; 438 break; 439 default: 440 formatInfoIsValid = false; 441 debugWarning("unknown stream format (0x%02x) for channel " 442 "(%d)\n", 443 compoundStream->m_streamFormatInfos[j]->m_streamFormat, 444 j ); 445 } 446 } 447 } 448 449 if ( formatInfoIsValid ) { 450 flushDebugOutput(); 451 debugOutput( DEBUG_LEVEL_VERBOSE, 452 "[%s:%d] formatInfo[%d].m_samplingFrequency " 453 "= %d\n", 454 getName(), m_id, 455 i, formatInfo.m_samplingFrequency ); 456 debugOutput( DEBUG_LEVEL_VERBOSE, 457 "[%s:%d] formatInfo[%d].m_isSyncStream = %d\n", 458 getName(), m_id, 459 i, formatInfo.m_isSyncStream ); 460 debugOutput( DEBUG_LEVEL_VERBOSE, 461 "[%s:%d] formatInfo[%d].m_audioChannels = %d\n", 462 getName(), m_id, 463 i, formatInfo.m_audioChannels ); 464 debugOutput( DEBUG_LEVEL_VERBOSE, 465 "[%s:%d] formatInfo[%d].m_midiChannels = %d\n", 466 getName(), m_id, 467 i, formatInfo.m_midiChannels ); 468 m_formatInfos.push_back( formatInfo ); 469 flushDebugOutput(); 470 } 471 } 472 473 ++i; 474 } while ( cmdSuccess && ( extStreamFormatCmd.getResponse() 475 == ExtendedStreamFormatCmd::eR_Implemented ) ); 476 477 return true; 478 } 479 480 bool 481 Plug::discoverConnectionsInput() 482 { 483 debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering incoming connections...\n"); 484 485 int sourcePlugGlobalId=getSignalSource(); 486 487 if(sourcePlugGlobalId >= 0) { 488 Plug *p=m_unit->getPlugManager().getPlug(sourcePlugGlobalId); 489 if (p==NULL) { 490 debugError( "Plug with global id %d not found\n",sourcePlugGlobalId ); 491 return false; 492 } 493 // connected to another plug 494 debugOutput( DEBUG_LEVEL_VERBOSE, "Plug '%s' gets signal from '%s'...\n", 495 getName(), p->getName() ); 496 497 498 499 if ( p ) { 500 debugOutput( DEBUG_LEVEL_VERBOSE, 501 "'(%d) %s' has a connection to '(%d) %s'\n", 502 getGlobalId(), 503 getName(), 504 p->getGlobalId(), 505 p->getName() ); 506 addPlugConnection( m_inputConnections, *p ); 507 } else { 508 debugError( "no corresponding plug found for '(%d) %s'\n", 509 getGlobalId(), 510 getName() ); 511 return false; 512 } 513 514 } 515 516 return true; 517 } 518 519 bool 520 Plug::discoverConnectionsOutput() 521 { 522 debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering outgoing connections...\n"); 523 524 // int i=0; 525 // int nbPlugs=m_unit->getPlugManager().getPlugCount(); 526 // debugOutput( DEBUG_LEVEL_VERBOSE, "checking %d plugs\n", nbPlugs); 527 // 528 // for (i=0;i<nbPlugs;i++) { 529 // Plug *p=m_unit->getPlugManager().getPlug(i); 530 // 531 // if(p==NULL) { 532 // debugError("could not get plug 0x%02X\n",i); 533 // continue; 534 // } 535 // 536 // if(p->getGlobalId()==getGlobalId()) continue; // skip yourself 537 // 538 // 539 // } 540 541 return true; 542 } 543 544 bool 125 545 Plug::inquireConnnection( Plug& plug ) 126 546 { … … 148 568 } 149 569 570 int 571 Plug::getSignalSource() 572 { 573 if((getPlugAddressType() == eAPA_PCR) || 574 (getPlugAddressType() == eAPA_ExternalPlug)) { 575 if (getPlugDirection() != eAPD_Output) { 576 debugWarning("Signal Source command not valid for non-output unit plugs...\n"); 577 return -1; 578 } 579 } 580 581 if(getPlugAddressType() == eAPA_SubunitPlug) { 582 if (getPlugDirection() != eAPD_Input) { 583 debugWarning("Signal Source command not valid for non-input subunit plugs...\n"); 584 return -1; 585 } 586 } 587 588 SignalSourceCmd signalSourceCmd( m_unit->get1394Service() ); 589 590 signalSourceCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 591 signalSourceCmd.setSubunitType( eST_Unit ); 592 signalSourceCmd.setSubunitId( 0xff ); 593 594 SignalSubunitAddress signalSubunitAddr; 595 signalSubunitAddr.m_subunitType = 0xFF; 596 signalSubunitAddr.m_subunitId = 0xFF; 597 signalSubunitAddr.m_plugId = 0xFE; 598 signalSourceCmd.setSignalSource( signalSubunitAddr ); 599 600 setDestPlugAddrToSignalCmd( signalSourceCmd, *this ); 601 602 signalSourceCmd.setCommandType( AVCCommand::eCT_Status ); 603 signalSourceCmd.setVerbose( getDebugLevel() ); 604 signalSourceCmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); 605 606 if ( !signalSourceCmd.fire() ) { 607 debugError( "Could not get signal source for '%s'\n", 608 getName() ); 609 return -1; 610 } 611 612 if ( signalSourceCmd.getResponse() == AVCCommand::eR_Implemented ) { 613 SignalAddress* src=signalSourceCmd.getSignalSource(); 614 Plug* p=NULL; 615 if(dynamic_cast<SignalUnitAddress *>(src)) { 616 SignalUnitAddress *usrc=dynamic_cast<SignalUnitAddress *>(src); 617 if (usrc->m_plugId & 0x80) { 618 p=m_unit->getPlugManager().getPlug( eST_Unit, 0xFF, 619 0xFF, 0xFF, eAPA_ExternalPlug, eAPD_Input, 620 usrc->m_plugId & 0x7F ); 621 } else { 622 p=m_unit->getPlugManager().getPlug( eST_Unit, 0xFF, 623 0xFF, 0xFF, eAPA_PCR, eAPD_Input, 624 usrc->m_plugId & 0x7F ); 625 } 626 } else if (dynamic_cast<SignalSubunitAddress *>(src)) { 627 SignalSubunitAddress *susrc=dynamic_cast<SignalSubunitAddress *>(src); 628 p=m_unit->getPlugManager().getPlug( byteToSubunitType(susrc->m_subunitType), 629 susrc->m_subunitId, 0xFF, 0xFF, eAPA_SubunitPlug, 630 eAPD_Output, susrc->m_plugId); 631 } else return -1; 632 633 if (p==NULL) { 634 debugError("reported signal source plug not found\n"); 635 return -1; 636 } 637 638 return p->getGlobalId(); 639 } 640 641 return -1; 642 } 643 150 644 bool 151 645 Plug::setConnection( Plug& plug ) … … 174 668 } 175 669 670 bool 671 Plug::propagateFromConnectedPlug( ) { 672 673 if (getDirection() == eAPD_Output) { 674 if (getInputConnections().size()==0) { 675 debugWarning("No input connections to propagate from, skipping.\n"); 676 return true; 677 } 678 if (getInputConnections().size()>1) { 679 debugWarning("Too many input connections to propagate from, using first one.\n"); 680 } 681 682 Plug* p = *(getInputConnections().begin()); 683 return propagateFromPlug( p ); 684 685 } else if (getDirection() == eAPD_Input) { 686 if (getOutputConnections().size()==0) { 687 debugWarning("No output connections to propagate from, skipping.\n"); 688 return true; 689 } 690 if (getOutputConnections().size()>1) { 691 debugWarning("Too many output connections to propagate from, using first one.\n"); 692 } 693 694 Plug* p = *(getOutputConnections().begin()); 695 return propagateFromPlug( p ); 696 697 } else { 698 debugWarning("plug with undefined direction\n"); 699 return false; 700 } 701 } 702 703 bool 704 Plug::propagateFromPlug( Plug *p ) { 705 debugOutput( DEBUG_LEVEL_VERBOSE, 706 "Propagating info from plug '%s' to plug '%s'\n", 707 p->getName(), getName() ); 708 709 if (m_clusterInfos.size()==0) { 710 m_clusterInfos=p->m_clusterInfos; 711 } 712 713 m_nrOfChannels=p->m_nrOfChannels; 714 715 return true; 716 } 717 176 718 int 177 719 Plug::getNrOfStreams() const … … 194 736 } 195 737 738 bool 739 Plug::setNrOfChannels(int i) 740 { 741 m_nrOfChannels=i; 742 return true; 743 } 744 196 745 int 197 746 Plug::getSampleRate() const 198 747 { 748 if(getPlugAddressType()==eAPA_PCR) { 749 if(getPlugDirection()==eAPD_Input) { 750 InputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 751 cmd.m_form=0xFF; 752 cmd.m_eoh=0xFF; 753 cmd.m_fmt=0xFF; 754 cmd.m_plug=getPlugId(); 755 756 cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 757 cmd.setSubunitType( eST_Unit ); 758 cmd.setSubunitId( 0xff ); 759 760 cmd.setCommandType( AVCCommand::eCT_Status ); 761 762 if ( !cmd.fire() ) { 763 debugError( "input plug signal format command failed\n" ); 764 return 0; 765 } 766 767 if (cmd.m_fmt != 0x10 ) { 768 debugWarning("Incorrect FMT response received: 0x%02X\n",cmd.m_fmt); 769 } 770 771 return fdfSfcToSampleRate(cmd.m_fdf[0]); 772 773 } else if (getPlugDirection()==eAPD_Output) { 774 OutputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 775 cmd.m_form=0xFF; 776 cmd.m_eoh=0xFF; 777 cmd.m_fmt=0xFF; 778 cmd.m_plug=getPlugId(); 779 780 cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 781 cmd.setSubunitType( eST_Unit ); 782 cmd.setSubunitId( 0xff ); 783 784 cmd.setCommandType( AVCCommand::eCT_Status ); 785 786 if ( !cmd.fire() ) { 787 debugError( "output plug signal format command failed\n" ); 788 return 0; 789 } 790 791 if (cmd.m_fmt != 0x10 ) { 792 debugWarning("Incorrect FMT response received: 0x%02X\n",cmd.m_fmt); 793 } 794 795 return fdfSfcToSampleRate(cmd.m_fdf[0]); 796 797 } else { 798 debugError("PCR plug with undefined direction.\n"); 799 return 0; 800 } 801 } 802 803 // fallback 199 804 return convertESamplingFrequency( static_cast<ESamplingFrequency>( m_samplingFrequency ) ); 805 } 806 807 bool 808 Plug::setSampleRate( int rate ) 809 { 810 // apple style 811 if(getPlugAddressType()==eAPA_PCR) { 812 if(getPlugDirection()==eAPD_Input) { 813 InputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 814 cmd.m_eoh=1; 815 cmd.m_form=0; 816 cmd.m_fmt=0x10; 817 cmd.m_plug=getPlugId(); 818 cmd.m_fdf[0]=sampleRateToFdfSfc(rate); 819 cmd.m_fdf[1]=0xFF; 820 cmd.m_fdf[2]=0xFF; 821 822 cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 823 cmd.setSubunitType( eST_Unit ); 824 cmd.setSubunitId( 0xff ); 825 826 cmd.setCommandType( AVCCommand::eCT_Control ); 827 828 if ( !cmd.fire() ) { 829 debugError( "input plug signal format command failed\n" ); 830 return false; 831 } 832 833 if ( cmd.getResponse() == AVCCommand::eR_Accepted ) 834 { 835 return true; 836 } 837 debugWarning( "output plug signal format command not accepted\n" ); 838 839 } else if (getPlugDirection()==eAPD_Output) { 840 OutputPlugSignalFormatCmd cmd( m_unit->get1394Service() ); 841 cmd.m_eoh=1; 842 cmd.m_form=0; 843 cmd.m_fmt=0x10; 844 cmd.m_plug=getPlugId(); 845 cmd.m_fdf[0]=sampleRateToFdfSfc(rate); 846 cmd.m_fdf[1]=0xFF; 847 cmd.m_fdf[2]=0xFF; 848 849 cmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 850 cmd.setSubunitType( eST_Unit ); 851 cmd.setSubunitId( 0xff ); 852 853 cmd.setCommandType( AVCCommand::eCT_Control ); 854 855 if ( !cmd.fire() ) { 856 debugError( "output plug signal format command failed\n" ); 857 return false; 858 } 859 860 if ( cmd.getResponse() == AVCCommand::eR_Accepted ) 861 { 862 return true; 863 } 864 debugWarning( "output plug signal format command not accepted\n" ); 865 } else { 866 debugError("PCR plug with undefined direction.\n"); 867 return false; 868 } 869 } 870 871 // fallback: BeBoB style 872 ESamplingFrequency samplingFrequency = parseSampleRate(rate); 873 874 ExtendedStreamFormatCmd extStreamFormatCmd( 875 m_unit->get1394Service(), 876 ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList ); 877 UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 878 getPlugId() ); 879 880 extStreamFormatCmd.setPlugAddress( 881 PlugAddress( 882 Plug::convertPlugDirection(getPlugDirection() ), 883 PlugAddress::ePAM_Unit, 884 unitPlugAddress ) ); 885 886 extStreamFormatCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 887 extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 888 889 int i = 0; 890 bool cmdSuccess = false; 891 bool correctFormatFound = false; 892 893 do { 894 extStreamFormatCmd.setIndexInStreamFormat( i ); 895 extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); 896 extStreamFormatCmd.setVerbose( getDebugLevel() ); 897 898 cmdSuccess = extStreamFormatCmd.fire(); 899 900 if ( cmdSuccess 901 && ( extStreamFormatCmd.getResponse() == 902 AVCCommand::eR_Implemented ) ) 903 { 904 ESamplingFrequency foundFreq = eSF_DontCare; 905 906 FormatInformation* formatInfo = 907 extStreamFormatCmd.getFormatInformation(); 908 FormatInformationStreamsCompound* compoundStream 909 = dynamic_cast< FormatInformationStreamsCompound* > ( 910 formatInfo->m_streams ); 911 if ( compoundStream ) { 912 foundFreq = 913 static_cast< ESamplingFrequency >( 914 compoundStream->m_samplingFrequency ); 915 } 916 917 FormatInformationStreamsSync* syncStream 918 = dynamic_cast< FormatInformationStreamsSync* > ( 919 formatInfo->m_streams ); 920 if ( syncStream ) { 921 foundFreq = 922 static_cast< ESamplingFrequency >( 923 syncStream->m_samplingFrequency ); 924 } 925 926 if ( foundFreq == samplingFrequency ) 927 { 928 correctFormatFound = true; 929 break; 930 } 931 } 932 933 ++i; 934 } while ( cmdSuccess 935 && ( extStreamFormatCmd.getResponse() == 936 ExtendedStreamFormatCmd::eR_Implemented ) ); 937 938 if ( !cmdSuccess ) { 939 debugError( "setSampleRatePlug: Failed to retrieve format info\n" ); 940 return false; 941 } 942 943 if ( !correctFormatFound ) { 944 debugError( "setSampleRatePlug: %s plug %d does not support " 945 "sample rate %d\n", 946 getName(), 947 getPlugId(), 948 convertESamplingFrequency( samplingFrequency ) ); 949 return false; 950 } 951 952 extStreamFormatCmd.setSubFunction( 953 ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); 954 extStreamFormatCmd.setCommandType( AVCCommand::eCT_Control ); 955 extStreamFormatCmd.setVerbose( getDebugLevel() ); 956 957 if ( !extStreamFormatCmd.fire() ) { 958 debugError( "setSampleRate: Could not set sample rate %d " 959 "to %s plug %d\n", 960 convertESamplingFrequency( samplingFrequency ), 961 getName(), 962 getPlugId() ); 963 return false; 964 } 965 966 return true; 200 967 } 201 968 … … 434 1201 } 435 1202 return dir; 1203 } 1204 1205 std::string 1206 Plug::plugAddressTypeToString(enum EPlugAddressType t) { 1207 switch (t) { 1208 case eAPA_PCR: 1209 return string("PCR"); 1210 case eAPA_ExternalPlug: 1211 return string("External"); 1212 case eAPA_AsynchronousPlug: 1213 return string("Async"); 1214 case eAPA_SubunitPlug: 1215 return string("Subunit"); 1216 case eAPA_FunctionBlockPlug: 1217 return string("Function Block"); 1218 default: 1219 case eAPA_Undefined: 1220 return string("Undefined"); 1221 } 1222 } 1223 1224 std::string 1225 Plug::plugTypeToString(enum EPlugType t) { 1226 switch (t) { 1227 case eAPT_IsoStream: 1228 return string("IsoStream"); 1229 case eAPT_AsyncStream: 1230 return string("AsyncStream"); 1231 case eAPT_Midi: 1232 return string("MIDI"); 1233 case eAPT_Sync: 1234 return string("Sync"); 1235 case eAPT_Analog: 1236 return string("Analog"); 1237 case eAPT_Digital: 1238 return string("Digital"); 1239 default: 1240 case eAPT_Unknown: 1241 return string("Unknown"); 1242 } 1243 } 1244 1245 std::string 1246 Plug::plugDirectionToString(enum EPlugDirection t) { 1247 switch (t) { 1248 case eAPD_Input: 1249 return string("Input"); 1250 case eAPD_Output: 1251 return string("Output"); 1252 default: 1253 case eAPT_Unknown: 1254 return string("Unknown"); 1255 } 436 1256 } 437 1257 … … 459 1279 debugOutput( DEBUG_LEVEL_VERBOSE, "\tNumber of Streams = %d\n", 460 1280 getNrOfStreams() ); 1281 debugOutput( DEBUG_LEVEL_VERBOSE, "\tIncoming connections from: "); 1282 1283 for ( PlugVector::const_iterator it = m_inputConnections.begin(); 1284 it != m_inputConnections.end(); 1285 ++it ) 1286 { 1287 debugOutputShort(DEBUG_LEVEL_VERBOSE, "%s, ", (*it)->getName()); 1288 } 1289 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 1290 1291 debugOutput( DEBUG_LEVEL_VERBOSE, "\tOutgoing connections to: "); 1292 for ( PlugVector::const_iterator it = m_outputConnections.begin(); 1293 it != m_outputConnections.end(); 1294 ++it ) 1295 { 1296 debugOutputShort(DEBUG_LEVEL_VERBOSE, "%s, ", (*it)->getName()); 1297 } 1298 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 1299 461 1300 flushDebugOutput(); 462 1301 } … … 1040 1879 1041 1880 // helper function 1042 static void addConnection( PlugConnection OwnerVector& connections,1881 static void addConnection( PlugConnectionVector& connections, 1043 1882 Plug& srcPlug, 1044 1883 Plug& destPlug ) 1045 1884 { 1885 for ( PlugConnectionVector::iterator it = connections.begin(); 1886 it != connections.end(); 1887 ++it ) 1888 { 1889 PlugConnection* con = *it; 1890 if ( ( &( con->getSrcPlug() ) == &srcPlug ) 1891 && ( &( con->getDestPlug() ) == &destPlug ) ) 1892 { 1893 return; 1894 } 1895 } 1896 connections.push_back( new PlugConnection( srcPlug, destPlug ) ); 1897 } 1898 1899 bool 1900 PlugManager::tidyPlugConnections(PlugConnectionVector& connections) 1901 { 1902 for ( PlugVector::const_iterator it = m_plugs.begin(); 1903 it != m_plugs.end(); 1904 ++it ) 1905 { 1906 Plug* plug = *it; 1907 for ( PlugVector::const_iterator it = 1908 plug->getInputConnections().begin(); 1909 it != plug->getInputConnections().end(); 1910 ++it ) 1911 { 1912 addConnection( connections, *( *it ), *plug ); 1913 } 1914 plug->getInputConnections().clear(); 1915 1916 for ( PlugVector::const_iterator it = 1917 plug->getOutputConnections().begin(); 1918 it != plug->getOutputConnections().end(); 1919 ++it ) 1920 { 1921 addConnection( connections, *plug, *( *it ) ); 1922 } 1923 plug->getOutputConnections().clear(); 1924 } 1925 1926 for ( PlugConnectionVector::iterator it = connections.begin(); 1927 it != connections.end(); 1928 ++it ) 1929 { 1930 PlugConnection * con = *it; 1931 con->getSrcPlug().getOutputConnections().push_back(&( con->getDestPlug() )); 1932 con->getDestPlug().getInputConnections().push_back(&( con->getSrcPlug() )); 1933 1934 } 1935 1936 return true; 1937 } 1938 1939 static void addConnectionOwner( PlugConnectionOwnerVector& connections, 1940 Plug& srcPlug, 1941 Plug& destPlug ) 1942 { 1943 1046 1944 for ( PlugConnectionOwnerVector::iterator it = connections.begin(); 1047 1945 it != connections.end(); … … 1057 1955 connections.push_back( PlugConnection( srcPlug, destPlug ) ); 1058 1956 } 1957 1059 1958 1060 1959 void … … 1104 2003 ++it ) 1105 2004 { 1106 addConnection ( connections, *( *it ), *plug );2005 addConnectionOwner( connections, *( *it ), *plug ); 1107 2006 } 1108 2007 for ( PlugVector::const_iterator it = … … 1111 2010 ++it ) 1112 2011 { 1113 addConnection ( connections, *plug, *( *it ) );2012 addConnectionOwner( connections, *plug, *( *it ) ); 1114 2013 } 1115 2014 } … … 1409 2308 } 1410 2309 1411 } 2310 ExtendedPlugInfoCmd 2311 Plug::setPlugAddrToPlugInfoCmd() 2312 { 2313 ExtendedPlugInfoCmd extPlugInfoCmd( m_unit->get1394Service() ); 2314 2315 switch( getSubunitType() ) { 2316 case eST_Unit: 2317 { 2318 UnitPlugAddress::EPlugType ePlugType = 2319 UnitPlugAddress::ePT_Unknown; 2320 switch ( m_addressType ) { 2321 case eAPA_PCR: 2322 ePlugType = UnitPlugAddress::ePT_PCR; 2323 break; 2324 case eAPA_ExternalPlug: 2325 ePlugType = UnitPlugAddress::ePT_ExternalPlug; 2326 break; 2327 case eAPA_AsynchronousPlug: 2328 ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 2329 break; 2330 default: 2331 ePlugType = UnitPlugAddress::ePT_Unknown; 2332 } 2333 UnitPlugAddress unitPlugAddress( ePlugType, 2334 m_id ); 2335 extPlugInfoCmd.setPlugAddress( 2336 PlugAddress( convertPlugDirection( getPlugDirection() ), 2337 PlugAddress::ePAM_Unit, 2338 unitPlugAddress ) ); 2339 } 2340 break; 2341 case eST_Music: 2342 case eST_Audio: 2343 { 2344 switch( m_addressType ) { 2345 case eAPA_SubunitPlug: 2346 { 2347 SubunitPlugAddress subunitPlugAddress( m_id ); 2348 extPlugInfoCmd.setPlugAddress( 2349 PlugAddress( 2350 convertPlugDirection( getPlugDirection() ), 2351 PlugAddress::ePAM_Subunit, 2352 subunitPlugAddress ) ); 2353 } 2354 break; 2355 case eAPA_FunctionBlockPlug: 2356 { 2357 FunctionBlockPlugAddress functionBlockPlugAddress( 2358 m_functionBlockType, 2359 m_functionBlockId, 2360 m_id ); 2361 extPlugInfoCmd.setPlugAddress( 2362 PlugAddress( 2363 convertPlugDirection( getPlugDirection() ), 2364 PlugAddress::ePAM_FunctionBlock, 2365 functionBlockPlugAddress ) ); 2366 } 2367 break; 2368 default: 2369 extPlugInfoCmd.setPlugAddress(PlugAddress()); 2370 } 2371 } 2372 break; 2373 default: 2374 debugError( "Unknown subunit type\n" ); 2375 } 2376 2377 extPlugInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 2378 extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 2379 extPlugInfoCmd.setSubunitId( getSubunitId() ); 2380 extPlugInfoCmd.setSubunitType( getSubunitType() ); 2381 2382 return extPlugInfoCmd; 2383 } 2384 2385 ExtendedStreamFormatCmd 2386 Plug::setPlugAddrToStreamFormatCmd( 2387 ExtendedStreamFormatCmd::ESubFunction subFunction) 2388 { 2389 ExtendedStreamFormatCmd extStreamFormatInfoCmd( 2390 m_unit->get1394Service(), 2391 subFunction ); 2392 switch( getSubunitType() ) { 2393 case eST_Unit: 2394 { 2395 UnitPlugAddress::EPlugType ePlugType = 2396 UnitPlugAddress::ePT_Unknown; 2397 switch ( m_addressType ) { 2398 case eAPA_PCR: 2399 ePlugType = UnitPlugAddress::ePT_PCR; 2400 break; 2401 case eAPA_ExternalPlug: 2402 ePlugType = UnitPlugAddress::ePT_ExternalPlug; 2403 break; 2404 case eAPA_AsynchronousPlug: 2405 ePlugType = UnitPlugAddress::ePT_AsynchronousPlug; 2406 break; 2407 default: 2408 ePlugType = UnitPlugAddress::ePT_Unknown; 2409 } 2410 UnitPlugAddress unitPlugAddress( ePlugType, 2411 m_id ); 2412 extStreamFormatInfoCmd.setPlugAddress( 2413 PlugAddress( convertPlugDirection( getPlugDirection() ), 2414 PlugAddress::ePAM_Unit, 2415 unitPlugAddress ) ); 2416 } 2417 break; 2418 case eST_Music: 2419 case eST_Audio: 2420 { 2421 switch( m_addressType ) { 2422 case eAPA_SubunitPlug: 2423 { 2424 SubunitPlugAddress subunitPlugAddress( m_id ); 2425 extStreamFormatInfoCmd.setPlugAddress( 2426 PlugAddress( convertPlugDirection( getPlugDirection() ), 2427 PlugAddress::ePAM_Subunit, 2428 subunitPlugAddress ) ); 2429 } 2430 break; 2431 case eAPA_FunctionBlockPlug: 2432 { 2433 FunctionBlockPlugAddress functionBlockPlugAddress( 2434 m_functionBlockType, 2435 m_functionBlockId, 2436 m_id ); 2437 extStreamFormatInfoCmd.setPlugAddress( 2438 PlugAddress( convertPlugDirection( getPlugDirection() ), 2439 PlugAddress::ePAM_FunctionBlock, 2440 functionBlockPlugAddress ) ); 2441 } 2442 break; 2443 default: 2444 extStreamFormatInfoCmd.setPlugAddress(PlugAddress()); 2445 } 2446 } 2447 break; 2448 default: 2449 debugError( "Unknown subunit type\n" ); 2450 } 2451 2452 extStreamFormatInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() ); 2453 extStreamFormatInfoCmd.setCommandType( AVCCommand::eCT_Status ); 2454 extStreamFormatInfoCmd.setSubunitId( getSubunitId() ); 2455 extStreamFormatInfoCmd.setSubunitType( getSubunitType() ); 2456 2457 return extStreamFormatInfoCmd; 2458 } 2459 2460 } branches/echoaudio/src/libavc/general/avc_plug.h
r509 r524 47 47 class Subunit; 48 48 class PlugManager; 49 49 50 class Plug; 50 51 51 typedef std::vector<Plug*> PlugVector; 52 53 class PlugConnection; 54 typedef std::vector<PlugConnection*> PlugConnectionVector; 55 52 56 53 57 class Plug { … … 62 66 eAPA_Undefined, 63 67 }; 68 std::string plugAddressTypeToString(enum EPlugAddressType t); 64 69 65 70 enum EPlugType { … … 72 77 eAPT_Unknown, 73 78 }; 79 std::string plugTypeToString(enum EPlugType t); 74 80 75 81 enum EPlugDirection { … … 78 84 eAPD_Unknown, 79 85 }; 86 std::string plugDirectionToString(enum EPlugDirection t); 80 87 81 88 // \todo This constructors sucks. too many parameters. fix it. … … 90 97 virtual ~Plug(); 91 98 92 virtual bool discover()93 {//FIXME:94 #warning FIXME i want to be pure!!95 return true;96 };97 98 99 bool inquireConnnection( Plug& plug ); 99 100 bool setConnection( Plug& plug ); 101 102 int getSignalSource(); 100 103 101 104 int getGlobalId() const … … 108 111 const char* getName() const 109 112 { return m_name.c_str(); } 113 bool setName(const char *n) 114 { m_name=n; return true;}; 115 bool setName(std::string n) 116 { m_name=n; return true;}; 110 117 EPlugDirection getPlugDirection() const 111 118 { return m_direction; } 119 bool setPlugDirection(EPlugDirection d) 120 { m_direction=d; return true; } 112 121 sampling_frequency_t getSamplingFrequency() const 113 122 { return m_samplingFrequency; } 114 123 int getSampleRate() const; // 22050, 24000, 32000, ... 124 bool setSampleRate( int rate ); 125 115 126 int getNrOfChannels() const; 127 bool setNrOfChannels(int i); 116 128 int getNrOfStreams() const; 117 129 130 // FIXME: this is the same as getPlugDirection 118 131 EPlugDirection getDirection() const 119 132 { return m_direction; } … … 122 135 EPlugType getPlugType() const 123 136 { return m_infoPlugType; } 137 bool setPlugType(EPlugType t) 138 { m_infoPlugType=t; return true; } 124 139 125 140 function_block_type_t getFunctionBlockType() const … … 128 143 { return m_functionBlockId; } 129 144 130 const PlugVector& getInputConnections() const 145 // const PlugVector& getInputConnections() const 146 // { return m_inputConnections; } 147 // const PlugVector& getOutputConnections() const 148 // { return m_outputConnections; } 149 PlugVector& getInputConnections() 131 150 { return m_inputConnections; } 132 const PlugVector& getOutputConnections() const151 PlugVector& getOutputConnections() 133 152 { return m_outputConnections; } 134 153 … … 171 190 virtual void setVerboseLevel( int i ) 172 191 {setDebugLevel(i);}; 192 193 // the discovery interface 194 // everything can be overloaded, or 195 // can be left as is 196 public: 197 virtual bool discover(); 198 virtual bool discoverConnections(); 199 virtual bool propagateFromConnectedPlug( ); 200 201 protected: 202 virtual bool discoverPlugType(); 203 virtual bool discoverName(); 204 virtual bool discoverNoOfChannels(); 205 virtual bool discoverChannelPosition(); 206 virtual bool discoverChannelName(); 207 virtual bool discoverClusterInfo(); 208 virtual bool discoverStreamFormat(); 209 virtual bool discoverSupportedStreamFormats(); 210 virtual bool discoverConnectionsInput(); 211 virtual bool discoverConnectionsOutput(); 212 virtual bool initFromDescriptor(); 213 214 bool propagateFromPlug( Plug *p ); 215 216 ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd(); 217 218 ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd( 219 ExtendedStreamFormatCmd::ESubFunction subFunction); 220 173 221 protected: 174 222 Plug(); … … 280 328 void showPlugs() const; 281 329 330 int getPlugCount() 331 { return m_plugs.size(); }; 332 282 333 Plug* getPlug( ESubunitType subunitType, 283 334 subunit_id_t subunitId, … … 302 353 void setVerboseLevel( int i ) 303 354 {setDebugLevel(i);}; 355 PlugVector& getPlugs() {return m_plugs;}; 356 bool tidyPlugConnections(PlugConnectionVector&); 357 304 358 private: 305 359 … … 330 384 }; 331 385 332 typedef std::vector<PlugConnection*> PlugConnectionVector;333 386 typedef std::vector<PlugConnection> PlugConnectionOwnerVector; 334 387 branches/echoaudio/src/libavc/general/avc_subunit.cpp
r509 r524 66 66 } 67 67 68 Plug * 69 Subunit::createPlug( AVC::Unit* unit, 70 AVC::Subunit* subunit, 71 AVC::function_block_type_t functionBlockType, 72 AVC::function_block_type_t functionBlockId, 73 AVC::Plug::EPlugAddressType plugAddressType, 74 AVC::Plug::EPlugDirection plugDirection, 75 AVC::plug_id_t plugId ) 76 { 77 78 return new Plug( unit, 79 subunit, 80 functionBlockType, 81 functionBlockId, 82 plugAddressType, 83 plugDirection, 84 plugId ); 85 } 86 68 87 bool 69 88 Subunit::discover() 70 89 { 71 // There is nothing we can discover for a generic subunit 72 // Maybe the plugs, but there are multiple ways of doing that. 73 // subclasses should implement this 90 if ( !discoverPlugs() ) { 91 debugError( "plug discovery failed\n" ); 92 return false; 93 } 94 95 return true; 96 } 97 98 bool 99 Subunit::discoverPlugs() 100 { 101 PlugInfoCmd plugInfoCmd( getUnit().get1394Service(), 102 PlugInfoCmd::eSF_SerialBusIsochronousAndExternalPlug ); 103 plugInfoCmd.setNodeId( getUnit().getConfigRom().getNodeId() ); 104 plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 105 plugInfoCmd.setSubunitType( getSubunitType() ); 106 plugInfoCmd.setSubunitId( getSubunitId() ); 107 plugInfoCmd.setVerbose( getDebugLevel() ); 108 109 if ( !plugInfoCmd.fire() ) { 110 debugError( "plug info command failed\n" ); 111 return false; 112 } 113 114 debugOutput( DEBUG_LEVEL_NORMAL, "number of source plugs = %d\n", 115 plugInfoCmd.m_sourcePlugs ); 116 debugOutput( DEBUG_LEVEL_NORMAL, "number of destination output " 117 "plugs = %d\n", plugInfoCmd.m_destinationPlugs ); 118 119 if ( !discoverPlugs( Plug::eAPD_Input, 120 plugInfoCmd.m_destinationPlugs ) ) 121 { 122 debugError( "destination plug discovering failed\n" ); 123 return false; 124 } 125 126 if ( !discoverPlugs( Plug::eAPD_Output, 127 plugInfoCmd.m_sourcePlugs ) ) 128 { 129 debugError( "source plug discovering failed\n" ); 130 return false; 131 } 132 133 return true; 134 } 135 136 bool 137 Subunit::discoverConnections() 138 { 139 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n"); 140 141 for ( PlugVector::iterator it = getPlugs().begin(); 142 it != getPlugs().end(); 143 ++it ) 144 { 145 Plug* plug = *it; 146 if ( !plug->discoverConnections() ) { 147 debugError( "plug connection discovering failed ('%s')\n", 148 plug->getName() ); 149 return false; 150 } 151 } 152 153 return true; 154 } 155 156 bool 157 Subunit::discoverPlugs(Plug::EPlugDirection plugDirection, 158 plug_id_t plugMaxId ) 159 { 160 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 161 for ( int plugIdx = 0; 162 plugIdx < plugMaxId; 163 ++plugIdx ) 164 { 165 Plug* plug = createPlug( &getUnit(), 166 &getSubunit(), 167 0xff, 168 0xff, 169 Plug::eAPA_SubunitPlug, 170 plugDirection, 171 plugIdx ); 172 if ( !plug ) { 173 debugError( "plug creation failed\n" ); 174 return false; 175 } 176 177 plug->setVerboseLevel(getDebugLevel()); 178 179 if ( !plug->discover() ) { 180 debugError( "plug discover failed\n" ); 181 return false; 182 } 183 184 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 185 plug->getName() ); 186 getPlugs().push_back( plug ); 187 } 74 188 return true; 75 189 } … … 98 212 } 99 213 return 0; 214 } 215 216 bool 217 Subunit::initPlugFromDescriptor( Plug& plug ) 218 { 219 debugError("plug loading from descriptor not implemented\n"); 220 return false; 100 221 } 101 222 branches/echoaudio/src/libavc/general/avc_subunit.h
r509 r524 51 51 52 52 virtual bool discover(); 53 virtual bool discoverConnections(); 53 54 virtual const char* getName() = 0; 54 55 … … 60 61 Unit& getUnit() const 61 62 { return *m_unit; } 63 Subunit& getSubunit() 64 { return *this; } 62 65 66 virtual Plug *createPlug( AVC::Unit* unit, 67 AVC::Subunit* subunit, 68 AVC::function_block_type_t functionBlockType, 69 AVC::function_block_type_t functionBlockId, 70 AVC::Plug::EPlugAddressType plugAddressType, 71 AVC::Plug::EPlugDirection plugDirection, 72 AVC::plug_id_t plugId ); 63 73 64 74 bool addPlug( Plug& plug ); 75 virtual bool initPlugFromDescriptor( Plug& plug ); 65 76 66 77 PlugVector& getPlugs() … … 68 79 Plug* getPlug(Plug::EPlugDirection direction, plug_id_t plugId); 69 80 81 virtual void setVerboseLevel(int l) 82 { setDebugLevel(l);}; 70 83 71 84 bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; 72 85 static Subunit* deserialize( Glib::ustring basePath, 73 Util::IODeserialize& deser, 74 Unit& avDevice ); 86 Util::IODeserialize& deser, Unit& avDevice ); 75 87 protected: 76 88 Subunit(); … … 81 93 Util::IODeserialize& deser, 82 94 Unit& avDevice ) = 0; 95 bool discoverPlugs(); 96 bool discoverPlugs(Plug::EPlugDirection plugDirection, 97 AVC::plug_id_t plugMaxId ); 83 98 84 99 protected: branches/echoaudio/src/libavc/general/avc_unit.cpp
r510 r524 50 50 , m_activeSyncInfo( 0 ) 51 51 { 52 debugOutput( DEBUG_LEVEL_VERBOSE, "Created AVC::Unit\n" ); 52 debugOutput( DEBUG_LEVEL_VERBOSE, "Created Unit\n" ); 53 m_pPlugManager->setVerboseLevel( getDebugLevel() ); 53 54 } 54 55 … … 81 82 } 82 83 84 Plug * 85 Unit::createPlug( Unit* unit, 86 Subunit* subunit, 87 function_block_type_t functionBlockType, 88 function_block_type_t functionBlockId, 89 Plug::EPlugAddressType plugAddressType, 90 Plug::EPlugDirection plugDirection, 91 plug_id_t plugId ) 92 { 93 94 return new Plug( unit, 95 subunit, 96 functionBlockType, 97 functionBlockId, 98 plugAddressType, 99 plugDirection, 100 plugId ); 101 } 102 103 Subunit* 104 Unit::createSubunit(Unit& unit, 105 ESubunitType type, 106 subunit_t id ) 107 { 108 switch (type) { 109 case eST_Audio: 110 return new SubunitAudio(unit, id ); 111 case eST_Music: 112 return new SubunitMusic(unit, id ); 113 default: 114 return NULL; 115 } 116 } 117 83 118 void 84 119 Unit::setVerboseLevel(int l) … … 93 128 if ( !enumerateSubUnits() ) { 94 129 debugError( "Could not enumarate sub units\n" ); 130 return false; 131 } 132 133 if ( !discoverPlugs() ) { 134 debugError( "Detecting plugs failed\n" ); 135 return false; 136 } 137 138 if ( !discoverPlugConnections() ) { 139 debugError( "Detecting plug connections failed\n" ); 140 return false; 141 } 142 143 if ( !discoverSubUnitsPlugConnections() ) { 144 debugError( "Detecting subunit plug connnections failed\n" ); 145 return false; 146 } 147 148 if ( !m_pPlugManager->tidyPlugConnections(m_plugConnections) ) { 149 debugError( "Tidying of plug connnections failed\n" ); 150 return false; 151 } 152 153 if ( !discoverSyncModes() ) { 154 debugError( "Detecting sync modes failed\n" ); 155 return false; 156 } 157 158 if ( !propagateClusterInfos() ) { 159 debugError( "Failed to propagate cluster info's\n" ); 95 160 return false; 96 161 } … … 135 200 switch( subunit_type ) { 136 201 case eST_Audio: 137 subunit = new SubunitAudio( *this, 138 subunitId ); 202 subunit = createSubunit( *this, eST_Audio, subunitId ); 139 203 if ( !subunit ) { 140 204 debugFatal( "Could not allocate SubunitAudio\n" ); 141 205 return false; 142 206 } 207 208 subunit->setVerboseLevel(getDebugLevel()); 143 209 144 210 if ( !subunit->discover() ) { … … 156 222 break; 157 223 case eST_Music: 158 subunit = new SubunitMusic( *this, 159 subunitId ); 224 subunit = createSubunit( *this, eST_Music, subunitId ); 160 225 if ( !subunit ) { 161 226 debugFatal( "Could not allocate SubunitMusic\n" ); 162 227 return false; 163 228 } 229 230 subunit->setVerboseLevel(getDebugLevel()); 231 164 232 if ( !subunit->discover() ) { 165 233 debugError( "enumerateSubUnits: Could not discover " … … 225 293 } 226 294 295 bool 296 Unit::discoverPlugs() 297 { 298 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering plugs...\n"); 299 300 ////////////////////////////////////////////// 301 // Get number of available isochronous input 302 // and output plugs of unit 303 304 PlugInfoCmd plugInfoCmd( get1394Service() ); 305 plugInfoCmd.setNodeId( getConfigRom().getNodeId() ); 306 plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); 307 plugInfoCmd.setVerbose( getDebugLevel() ); 308 309 if ( !plugInfoCmd.fire() ) { 310 debugError( "plug info command failed\n" ); 311 return false; 312 } 313 314 debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n", 315 plugInfoCmd.m_serialBusIsochronousInputPlugs ); 316 debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n", 317 plugInfoCmd.m_serialBusIsochronousOutputPlugs ); 318 debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n", 319 plugInfoCmd.m_externalInputPlugs ); 320 debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n", 321 plugInfoCmd.m_externalOutputPlugs ); 322 323 if ( !discoverPlugsPCR( Plug::eAPD_Input, 324 plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) 325 { 326 debugError( "pcr input plug discovering failed\n" ); 327 return false; 328 } 329 330 if ( !discoverPlugsPCR( Plug::eAPD_Output, 331 plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) 332 { 333 debugError( "pcr output plug discovering failed\n" ); 334 return false; 335 } 336 337 if ( !discoverPlugsExternal( Plug::eAPD_Input, 338 plugInfoCmd.m_externalInputPlugs ) ) 339 { 340 debugError( "external input plug discovering failed\n" ); 341 return false; 342 } 343 344 if ( !discoverPlugsExternal( Plug::eAPD_Output, 345 plugInfoCmd.m_externalOutputPlugs ) ) 346 { 347 debugError( "external output plug discovering failed\n" ); 348 return false; 349 } 350 351 return true; 352 } 353 354 bool 355 Unit::discoverPlugsPCR( Plug::EPlugDirection plugDirection, 356 plug_id_t plugMaxId ) 357 { 358 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plugs, direction %d...\n",plugDirection); 359 for ( int plugId = 0; 360 plugId < plugMaxId; 361 ++plugId ) 362 { 363 Plug* plug = createPlug( this, 364 NULL, 365 0xff, 366 0xff, 367 Plug::eAPA_PCR, 368 plugDirection, 369 plugId ); 370 if ( !plug || !plug->discover() ) { 371 debugError( "plug discovering failed\n" ); 372 delete plug; 373 return false; 374 } 375 376 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 377 plug->getName() ); 378 m_pcrPlugs.push_back( plug ); 379 } 380 381 return true; 382 } 383 384 bool 385 Unit::discoverPlugsExternal( Plug::EPlugDirection plugDirection, 386 plug_id_t plugMaxId ) 387 { 388 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering External plugs, direction %d...\n",plugDirection); 389 for ( int plugId = 0; 390 plugId < plugMaxId; 391 ++plugId ) 392 { 393 Plug* plug = createPlug( this, NULL, 394 0xff, 395 0xff, 396 Plug::eAPA_ExternalPlug, 397 plugDirection, 398 plugId ); 399 if ( !plug || !plug->discover() ) { 400 debugError( "plug discovering failed\n" ); 401 return false; 402 } 403 404 debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", 405 plug->getName() ); 406 m_externalPlugs.push_back( plug ); 407 } 408 409 return true; 410 } 411 412 bool 413 Unit::discoverPlugConnections() 414 { 415 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering PCR plug connections...\n"); 416 for ( PlugVector::iterator it = m_pcrPlugs.begin(); 417 it != m_pcrPlugs.end(); 418 ++it ) 419 { 420 Plug* plug = *it; 421 if ( !plug->discoverConnections() ) { 422 debugError( "Could not discover PCR plug connections\n" ); 423 return false; 424 } 425 } 426 debugOutput( DEBUG_LEVEL_NORMAL, "Discovering External plug connections...\n"); 427 for ( PlugVector::iterator it = m_externalPlugs.begin(); 428 it != m_externalPlugs.end(); 429 ++it ) 430 { 431 Plug* plug = *it; 432 if ( !plug->discoverConnections() ) { 433 debugError( "Could not discover External plug connections\n" ); 434 return false; 435 } 436 } 437 438 return true; 439 } 440 441 bool 442 Unit::discoverSubUnitsPlugConnections() 443 { 444 for ( SubunitVector::iterator it = m_subunits.begin(); 445 it != m_subunits.end(); 446 ++it ) 447 { 448 Subunit* subunit = *it; 449 450 if ( !subunit->discoverConnections() ) { 451 debugError( "Subunit '%s' plug connections failed\n", 452 subunit->getName() ); 453 return false; 454 } 455 } 456 return true; 457 } 458 459 bool 460 Unit::propagateClusterInfos() 461 { 462 debugOutput( DEBUG_LEVEL_NORMAL, "Propagating info to PCR plugs...\n"); 463 for ( PlugVector::iterator it = m_pcrPlugs.begin(); 464 it != m_pcrPlugs.end(); 465 ++it ) 466 { 467 Plug* plug = *it; 468 debugOutput( DEBUG_LEVEL_NORMAL, "plug: %s\n", plug->getName()); 469 if (!plug->propagateFromConnectedPlug()) { 470 debugWarning( "Could not propagate info for plug '%s'\n", plug->getName()); 471 } 472 } 473 debugOutput( DEBUG_LEVEL_NORMAL, "Propagating info to External plugs...\n"); 474 for ( PlugVector::iterator it = m_externalPlugs.begin(); 475 it != m_externalPlugs.end(); 476 ++it ) 477 { 478 Plug* plug = *it; 479 debugOutput( DEBUG_LEVEL_NORMAL, "plug: %s\n", plug->getName()); 480 if (!plug->propagateFromConnectedPlug()) { 481 debugWarning( "Could not propagate info for plug '%s'\n", plug->getName()); 482 } 483 } 484 485 return true; 486 487 } 488 489 227 490 PlugConnection* 228 491 Unit::getPlugConnection( Plug& srcPlug ) const … … 288 551 return 0; 289 552 } 553 554 bool 555 Unit::discoverSyncModes() 556 { 557 // Following possible sync plugs exists: 558 // - Music subunit sync output plug = internal sync (CSP) 559 // - Unit input plug 0 = SYT match 560 // - Unit input plut 1 = Sync stream 561 // 562 // If last sync mode is reported it is mostelikely not 563 // implemented *sic* 564 // 565 // Following sync sources are device specific: 566 // - All unit external input plugs which have a 567 // sync information (WS, SPDIF, ...) 568 569 // First we have to find the sync input and output plug 570 // in the music subunit. 571 572 // Note PCR input means 1394bus-to-device where as 573 // MSU input means subunit-to-device 574 575 PlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, 576 Plug::eAPD_Input, 577 Plug::eAPT_Sync ); 578 if ( !syncPCRInputPlugs.size() ) { 579 debugWarning( "No PCR sync input plug found\n" ); 580 } 581 582 PlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, 583 Plug::eAPD_Output, 584 Plug::eAPT_Sync ); 585 if ( !syncPCROutputPlugs.size() ) { 586 debugWarning( "No PCR sync output plug found\n" ); 587 } 588 589 PlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, 590 Plug::eAPD_Input, 591 Plug::eAPT_IsoStream ); 592 if ( !isoPCRInputPlugs.size() ) { 593 debugWarning( "No PCR iso input plug found\n" ); 594 595 } 596 597 PlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, 598 Plug::eAPD_Output, 599 Plug::eAPT_IsoStream ); 600 if ( !isoPCROutputPlugs.size() ) { 601 debugWarning( "No PCR iso output plug found\n" ); 602 603 } 604 605 PlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, 606 Plug::eAPD_Input, 607 Plug::eAPT_Digital ); 608 609 PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 610 eST_Music, 611 0, 612 0xff, 613 0xff, 614 Plug::eAPA_SubunitPlug, 615 Plug::eAPD_Input, 616 Plug::eAPT_Sync ); 617 if ( !syncMSUInputPlugs.size() ) { 618 debugWarning( "No sync input plug for MSU subunit found\n" ); 619 } 620 621 PlugVector syncMSUOutputPlugs = m_pPlugManager->getPlugsByType( 622 eST_Music, 623 0, 624 0xff, 625 0xff, 626 Plug::eAPA_SubunitPlug, 627 Plug::eAPD_Output, 628 Plug::eAPT_Sync ); 629 if ( !syncMSUOutputPlugs.size() ) { 630 debugWarning( "No sync output plug for MSU subunit found\n" ); 631 } 632 633 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); 634 showPlugs( syncPCRInputPlugs ); 635 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); 636 showPlugs( syncPCROutputPlugs ); 637 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); 638 showPlugs( isoPCRInputPlugs ); 639 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); 640 showPlugs( isoPCROutputPlugs ); 641 debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); 642 showPlugs( digitalPCRInputPlugs ); 643 debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); 644 showPlugs( syncMSUInputPlugs ); 645 debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); 646 showPlugs( syncMSUOutputPlugs ); 647 648 // Check all possible PCR input to MSU input connections 649 // -> sync stream input 650 checkSyncConnectionsAndAddToList( syncPCRInputPlugs, 651 syncMSUInputPlugs, 652 "Sync Stream Input" ); 653 654 // Check all possible MSU output to PCR output connections 655 // -> sync stream output 656 checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 657 syncPCROutputPlugs, 658 "Sync Stream Output" ); 659 660 // Check all PCR iso input to MSU input connections 661 // -> SYT match 662 checkSyncConnectionsAndAddToList( isoPCRInputPlugs, 663 syncMSUInputPlugs, 664 "Syt Match" ); 665 666 // Check all MSU sync output to MSU input connections 667 // -> CSP 668 checkSyncConnectionsAndAddToList( syncMSUOutputPlugs, 669 syncMSUInputPlugs, 670 "Internal (CSP)" ); 671 672 // Check all external PCR digital input to MSU input connections 673 // -> SPDIF/ADAT sync 674 checkSyncConnectionsAndAddToList( digitalPCRInputPlugs, 675 syncMSUInputPlugs, 676 "Digital Input Sync" ); 677 678 // Currently active connection signal source cmd, command type 679 // status, source unknown, destination MSU sync input plug 680 681 for ( PlugVector::const_iterator it = syncMSUInputPlugs.begin(); 682 it != syncMSUInputPlugs.end(); 683 ++it ) 684 { 685 AVC::Plug* msuPlug = *it; 686 for ( PlugVector::const_iterator jt = 687 msuPlug->getInputConnections().begin(); 688 jt != msuPlug->getInputConnections().end(); 689 ++jt ) 690 { 691 AVC::Plug* plug = *jt; 692 693 for ( SyncInfoVector::iterator it = m_syncInfos.begin(); 694 it != m_syncInfos.end(); 695 ++it ) 696 { 697 SyncInfo* pSyncInfo = &*it; 698 if ( ( pSyncInfo->m_source == plug ) 699 && ( pSyncInfo->m_destination == msuPlug ) ) 700 { 701 m_activeSyncInfo = pSyncInfo; 702 break; 703 } 704 } 705 debugOutput( DEBUG_LEVEL_NORMAL, 706 "Active Sync Connection: '%s' -> '%s'\n", 707 plug->getName(), 708 msuPlug->getName() ); 709 } 710 } 711 712 return true; 713 } 714 715 bool 716 Unit::checkSyncConnectionsAndAddToList( PlugVector& plhs, 717 PlugVector& prhs, 718 std::string syncDescription ) 719 { 720 for ( PlugVector::iterator plIt = plhs.begin(); 721 plIt != plhs.end(); 722 ++plIt ) 723 { 724 AVC::Plug* pl = *plIt; 725 for ( PlugVector::iterator prIt = prhs.begin(); 726 prIt != prhs.end(); 727 ++prIt ) 728 { 729 AVC::Plug* pr = *prIt; 730 if ( pl->inquireConnnection( *pr ) ) { 731 m_syncInfos.push_back( SyncInfo( *pl, *pr, syncDescription ) ); 732 debugOutput( DEBUG_LEVEL_NORMAL, 733 "Sync connection '%s' -> '%s'\n", 734 pl->getName(), 735 pr->getName() ); 736 } 737 } 738 } 739 return true; 740 } 741 742 bool Unit::setActiveSync(const SyncInfo& syncInfo) 743 { 744 return syncInfo.m_source->setConnection( *syncInfo.m_destination ); 745 } 746 290 747 291 748 void branches/echoaudio/src/libavc/general/avc_unit.h
r509 r524 62 62 63 63 /// Discovers the unit's internals 64 bool discover();64 virtual bool discover(); 65 65 66 66 PlugManager& getPlugManager() … … 86 86 87 87 typedef std::vector<SyncInfo> SyncInfoVector; 88 const SyncInfoVector& getSyncInfos() const88 virtual const SyncInfoVector& getSyncInfos() const 89 89 { return m_syncInfos; } 90 const SyncInfo* getActiveSyncInfo() const90 virtual const SyncInfo* getActiveSyncInfo() const 91 91 { return m_activeSyncInfo; } 92 virtual bool setActiveSync( const SyncInfo& syncInfo ) = 0; 92 93 virtual bool setActiveSync( const SyncInfo& syncInfo ); 93 94 94 95 bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const; … … 104 105 Subunit* getSubunit( subunit_type_t subunitType, 105 106 subunit_id_t subunitId ) const; 107 108 virtual AVC::Subunit* createSubunit(Unit& unit, 109 ESubunitType type, 110 subunit_t id ); 111 virtual AVC::Plug* createPlug( AVC::Unit* unit, 112 AVC::Subunit* subunit, 113 AVC::function_block_type_t functionBlockType, 114 AVC::function_block_type_t functionBlockId, 115 AVC::Plug::EPlugAddressType plugAddressType, 116 AVC::Plug::EPlugDirection plugDirection, 117 AVC::plug_id_t plugId ); 118 106 119 protected: 107 120 108 121 virtual bool enumerateSubUnits(); 109 122 virtual bool discoverPlugConnections(); 123 virtual bool discoverSubUnitsPlugConnections(); 124 virtual bool discoverPlugs(); 125 virtual bool discoverPlugsPCR( AVC::Plug::EPlugDirection plugDirection, 126 AVC::plug_id_t plugMaxId ); 127 virtual bool discoverPlugsExternal( AVC::Plug::EPlugDirection plugDirection, 128 AVC::plug_id_t plugMaxId ); 129 virtual bool propagateClusterInfos(); 130 virtual bool discoverSyncModes(); 131 virtual bool checkSyncConnectionsAndAddToList( AVC::PlugVector& plhs, 132 AVC::PlugVector& prhs, 133 std::string syncDescription ); 134 virtual Plug* getSyncPlug( int maxPlugId, Plug::EPlugDirection ); 135 110 136 unsigned int getNrOfSubunits( subunit_type_t subunitType ) const; 111 137 PlugConnection* getPlugConnection( Plug& srcPlug ) const; 112 113 Plug* getSyncPlug( int maxPlugId, Plug::EPlugDirection );114 138 115 139 Plug* getPlugById( PlugVector& plugs, … … 126 150 void showPlugs( PlugVector& plugs ) const; 127 151 128 // bool checkSyncConnectionsAndAddToList( PlugVector& plhs,129 // PlugVector& prhs,130 // std::string syncDescription );131 152 132 153 static bool serializeSyncInfoVector( Glib::ustring basePath, branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.cpp
r503 r524 30 30 #include "libieee1394/ieee1394service.h" 31 31 32 #include "../general/avc_subunit.h" 33 #include "../general/avc_unit.h" 34 32 35 #include <netinet/in.h> 33 36 … … 199 202 } 200 203 } 201 202 return result; 203 } 204 205 return result; 206 } 207 208 std::string 209 AVCMusicClusterInfoBlock::getName() { 210 if(m_RawTextInfoBlock.m_compound_length>0) { 211 return m_RawTextInfoBlock.m_text; 212 } else if (m_NameInfoBlock.m_compound_length>0) { 213 return m_NameInfoBlock.m_text; 214 } else { 215 return std::string("Unknown"); 216 } 217 } 218 204 219 205 220 // --------- … … 322 337 return result; 323 338 } 339 340 std::string 341 AVCMusicSubunitPlugInfoBlock::getName() { 342 if(m_RawTextInfoBlock.m_compound_length>0) { 343 return m_RawTextInfoBlock.m_text; 344 } else if (m_NameInfoBlock.m_compound_length>0) { 345 return m_NameInfoBlock.m_text; 346 } else { 347 return std::string("Unknown"); 348 } 349 } 350 324 351 325 352 // --------- … … 431 458 } 432 459 460 std::string 461 AVCMusicPlugInfoBlock::getName() { 462 if(m_RawTextInfoBlock.m_compound_length>0) { 463 return m_RawTextInfoBlock.m_text; 464 } else if (m_NameInfoBlock.m_compound_length>0) { 465 return m_NameInfoBlock.m_text; 466 } else { 467 return std::string("Unknown"); 468 } 469 } 470 471 433 472 // --------- 434 473 AVCMusicRoutingStatusInfoBlock::AVCMusicRoutingStatusInfoBlock( ) … … 568 607 } 569 608 609 AVCMusicSubunitPlugInfoBlock * 610 AVCMusicRoutingStatusInfoBlock::getSubunitPlugInfoBlock(Plug::EPlugDirection direction, plug_id_t id) { 611 if (direction == Plug::eAPD_Input) { 612 for ( AVCMusicSubunitPlugInfoBlockVectorIterator it = mDestPlugInfoBlocks.begin(); 613 it != mDestPlugInfoBlocks.end(); 614 ++it ) 615 { 616 AVCMusicSubunitPlugInfoBlock *b=(*it); 617 if (b->m_subunit_plug_id == id) return b; 618 } 619 debugOutput(DEBUG_LEVEL_VERBOSE, "no plug info found.\n"); 620 return NULL; 621 } else if (direction == Plug::eAPD_Output) { 622 for ( AVCMusicSubunitPlugInfoBlockVectorIterator it = mSourcePlugInfoBlocks.begin(); 623 it != mSourcePlugInfoBlocks.end(); 624 ++it ) 625 { 626 AVCMusicSubunitPlugInfoBlock *b=(*it); 627 if (b->m_subunit_plug_id == id) return b; 628 } 629 debugOutput(DEBUG_LEVEL_VERBOSE, "no plug info found.\n"); 630 return NULL; 631 } else { 632 debugOutput(DEBUG_LEVEL_VERBOSE, "Invalid direction.\n"); 633 return NULL; 634 } 635 } 636 637 AVCMusicPlugInfoBlock * 638 AVCMusicRoutingStatusInfoBlock::getMusicPlugInfoBlock(plug_id_t id) { 639 for ( AVCMusicPlugInfoBlockVectorIterator it = mMusicPlugInfoBlocks.begin(); 640 it != mMusicPlugInfoBlocks.end(); 641 ++it ) 642 { 643 AVCMusicPlugInfoBlock *b=(*it); 644 if (b->m_music_plug_id == id) return b; 645 } 646 debugOutput(DEBUG_LEVEL_VERBOSE, "no music plug info found.\n"); 647 return NULL; 648 } 570 649 571 650 // ---------------------- 572 AVCMusicStatusDescriptor::AVCMusicStatusDescriptor( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId)573 : AVCDescriptor( ieee1394service, nodeId, eST_Music, 0x00, AVCDescriptorSpecifier::eSubunit0x80)651 AVCMusicStatusDescriptor::AVCMusicStatusDescriptor( Unit* unit, Subunit* subunit ) 652 : AVCDescriptor(unit, subunit, AVCDescriptorSpecifier::eSubunit0x80) 574 653 {} 575 654 … … 614 693 615 694 switch (block_type) { 616 case 0x8100: 695 case 0x8100: 617 696 m_general_status_infoblock.setVerbose(getVerboseLevel()); 618 697 result &= m_general_status_infoblock.deserialize(de); 619 698 break; 620 case 0x8101: 699 case 0x8101: 621 700 m_output_plug_status_infoblock.setVerbose(getVerboseLevel()); 622 701 result &= m_output_plug_status_infoblock.deserialize(de); 623 702 break; 624 case 0x8108:703 case 0x8108: 625 704 m_routing_status_infoblock.setVerbose(getVerboseLevel()); 626 705 result &= m_routing_status_infoblock.deserialize(de); … … 631 710 break; 632 711 } 633 712 634 713 if(blocks_done++>max_blocks) { 635 714 debugError("Too much info blocks in descriptor, probably a runaway parser\n"); … … 641 720 } 642 721 643 } 722 AVCMusicSubunitPlugInfoBlock * 723 AVCMusicStatusDescriptor::getSubunitPlugInfoBlock(Plug::EPlugDirection direction, plug_id_t id) { 724 return m_routing_status_infoblock.getSubunitPlugInfoBlock(direction, id); 725 } 726 727 AVCMusicPlugInfoBlock * 728 AVCMusicStatusDescriptor::getMusicPlugInfoBlock(plug_id_t id) { 729 return m_routing_status_infoblock.getMusicPlugInfoBlock(id); 730 } 731 732 } branches/echoaudio/src/libavc/musicsubunit/avc_descriptor_music.h
r503 r524 34 34 35 35 #include "../general/avc_generic.h" 36 #include "../general/avc_plug.h" 37 36 38 #include "debugmodule/debugmodule.h" 37 39 38 40 #include <libavc1394/avc1394.h> 41 39 42 #include <vector> 43 #include <string> 40 44 41 45 class Ieee1394Service; … … 99 103 byte_t stream_location; 100 104 }; 101 102 virtual bool serialize( IOSSerialize& se ); 103 virtual bool deserialize( IISDeserialize& de ); 104 105 virtual bool clear(); 106 105 typedef std::vector<struct sSignalInfo> SignalInfoVector; 106 typedef std::vector<struct sSignalInfo>::iterator SignalInfoVectorIterator; 107 108 virtual bool serialize( IOSSerialize& se ); 109 virtual bool deserialize( IISDeserialize& de ); 110 111 virtual bool clear(); 112 113 std::string getName(); 114 107 115 AVCMusicClusterInfoBlock( ); 108 116 virtual ~AVCMusicClusterInfoBlock(); … … 113 121 byte_t m_port_type; 114 122 byte_t m_nb_signals; 115 std::vector<struct sSignalInfo>m_SignalInfos;123 SignalInfoVector m_SignalInfos; 116 124 117 125 AVCRawTextInfoBlock m_RawTextInfoBlock; … … 128 136 { 129 137 public: 138 enum AVCMusicSubunitPlugInfoBlockPlugType { 139 ePT_IsoStream = 0x0, 140 ePT_AsyncStream = 0x1, 141 ePT_Midi = 0x2, 142 ePT_Sync = 0x3, 143 ePT_Analog = 0x4, 144 ePT_Digital = 0x5, 145 146 ePT_Unknown = 0xff, 147 }; 130 148 131 149 virtual bool serialize( IOSSerialize& se ); … … 138 156 139 157 virtual bool clear(); 158 159 std::string getName(); 140 160 141 161 byte_t m_subunit_plug_id; … … 169 189 virtual const char* getInfoBlockName() const 170 190 {return "AVCMusicPlugInfoBlock";}; 191 192 std::string getName(); 171 193 172 194 byte_t m_music_plug_type; … … 207 229 {return "AVCMusicRoutingStatusInfoBlock";}; 208 230 231 AVCMusicSubunitPlugInfoBlock *getSubunitPlugInfoBlock(Plug::EPlugDirection, plug_id_t); 232 AVCMusicPlugInfoBlock *getMusicPlugInfoBlock(plug_id_t); 233 209 234 virtual bool clear(); 210 235 … … 233 258 virtual bool deserialize( IISDeserialize& de ); 234 259 235 AVCMusicStatusDescriptor( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId);260 AVCMusicStatusDescriptor( Unit* unit, Subunit* subunit ); 236 261 virtual ~AVCMusicStatusDescriptor() {} 237 262 238 263 virtual const char* getDescriptorName() const 239 264 {return "AVCMusicStatusDescriptor";}; 265 266 AVCMusicSubunitPlugInfoBlock *getSubunitPlugInfoBlock(Plug::EPlugDirection, plug_id_t); 267 AVCMusicPlugInfoBlock *getMusicPlugInfoBlock(plug_id_t); 268 240 269 private: 241 270 // the child info blocks branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.cpp
r508 r524 34 34 #include "../util/avc_serialize.h" 35 35 36 #include "avc_musicsubunit.h" 37 #include "avc_descriptor_music.h" 38 36 39 #include <sstream> 37 40 … … 42 45 SubunitMusic::SubunitMusic( Unit& unit, subunit_t id ) 43 46 : Subunit( unit, eST_Music, id ) 44 { 47 , m_status_descriptor ( new AVCMusicStatusDescriptor( &unit, this ) ) 48 { 49 45 50 } 46 51 47 52 SubunitMusic::SubunitMusic() 48 53 : Subunit() 54 , m_status_descriptor ( NULL ) 49 55 { 50 56 } … … 52 58 SubunitMusic::~SubunitMusic() 53 59 { 60 if (m_status_descriptor) delete m_status_descriptor; 61 } 62 63 bool 64 SubunitMusic::discover() 65 { 66 debugOutput(DEBUG_LEVEL_NORMAL, "Discovering %s...\n", getName()); 67 68 // discover the AV/C generic part 69 if ( !Subunit::discover() ) { 70 return false; 71 } 72 73 // now we have the subunit plugs 74 75 return true; 76 } 77 78 bool 79 SubunitMusic::initPlugFromDescriptor( Plug& plug ) 80 { 81 debugOutput(DEBUG_LEVEL_VERBOSE, "Loading info from descriptor for plug: \n"); 82 bool result=true; 83 84 // load the descriptor (if not already loaded) 85 if (m_status_descriptor != NULL) { 86 result &= m_status_descriptor->load(); 87 } 88 89 AVCMusicSubunitPlugInfoBlock *info; 90 info = m_status_descriptor->getSubunitPlugInfoBlock(plug.getDirection(), plug.getPlugId()); 91 92 if (info == NULL) { 93 debugError("Could not find plug info block\n"); 94 return false; 95 } 96 97 debugOutput(DEBUG_LEVEL_VERBOSE, "Found plug: %s\n",info->getName().c_str()); 98 99 // plug name 100 result &= plug.setName(info->getName()); 101 102 // plug type 103 switch (info->m_plug_type) { 104 case AVCMusicSubunitPlugInfoBlock::ePT_IsoStream: 105 result &= plug.setPlugType(Plug::eAPT_IsoStream); 106 break; 107 case AVCMusicSubunitPlugInfoBlock::ePT_AsyncStream: 108 result &= plug.setPlugType(Plug::eAPT_AsyncStream); 109 break; 110 case AVCMusicSubunitPlugInfoBlock::ePT_Midi: 111 result &= plug.setPlugType(Plug::eAPT_Midi); 112 break; 113 case AVCMusicSubunitPlugInfoBlock::ePT_Sync: 114 result &= plug.setPlugType(Plug::eAPT_Sync); 115 break; 116 case AVCMusicSubunitPlugInfoBlock::ePT_Analog: 117 result &= plug.setPlugType(Plug::eAPT_Analog); 118 break; 119 case AVCMusicSubunitPlugInfoBlock::ePT_Digital: 120 result &= plug.setPlugType(Plug::eAPT_Digital); 121 break; 122 } 123 124 // number of channels 125 result &= plug.setNrOfChannels(info->m_nb_channels); 126 127 128 129 int idx=1; 130 for ( AVCMusicClusterInfoBlockVectorIterator it = info->m_Clusters.begin(); 131 it != info->m_Clusters.end(); 132 ++it ) 133 { 134 struct Plug::ClusterInfo cinfo; 135 136 AVCMusicClusterInfoBlock *c=(*it); 137 138 cinfo.m_index=idx; //FIXME: is this correct? 139 cinfo.m_portType=c->m_port_type; 140 cinfo.m_nrOfChannels=c->m_nb_signals; 141 cinfo.m_streamFormat=c->m_stream_format; 142 cinfo.m_name=c->getName(); 143 144 debugOutput(DEBUG_LEVEL_VERBOSE, "Adding cluster idx=%2d type=%02X nbch=%2d fmt=%02X name=%s\n", 145 cinfo.m_index, cinfo.m_portType, cinfo.m_nrOfChannels, cinfo.m_streamFormat, cinfo.m_name.c_str()); 146 147 for ( AVCMusicClusterInfoBlock::SignalInfoVectorIterator sig_it 148 = c->m_SignalInfos.begin(); 149 sig_it != c->m_SignalInfos.end(); 150 ++sig_it ) 151 { 152 struct AVCMusicClusterInfoBlock::sSignalInfo s=(*sig_it); 153 struct Plug::ChannelInfo sinfo; 154 155 sinfo.m_streamPosition=s.stream_position; 156 sinfo.m_location=s.stream_location; 157 158 AVCMusicPlugInfoBlock *mplug=m_status_descriptor->getMusicPlugInfoBlock(s.music_plug_id); 159 160 if (mplug==NULL) { 161 debugWarning("No music plug found for this signal\n"); 162 sinfo.m_name="unknown"; 163 } else { 164 sinfo.m_name=mplug->getName(); 165 } 166 167 debugOutput(DEBUG_LEVEL_VERBOSE, "Adding signal pos=%2d loc=%2d name=%s\n", 168 sinfo.m_streamPosition, sinfo.m_location, mplug->getName().c_str()); 169 170 cinfo.m_channelInfos.push_back(sinfo); 171 } 172 173 idx++; 174 plug.getClusterInfos().push_back(cinfo); 175 } 176 177 178 return result; 179 180 } 181 182 bool 183 SubunitMusic::loadDescriptors() 184 { 185 bool result=true; 186 if (m_status_descriptor != NULL) { 187 result &= m_status_descriptor->load(); 188 } else { 189 debugError("BUG: m_status_descriptor == NULL\n"); 190 return false; 191 } 192 return result; 193 } 194 195 void SubunitMusic::setVerboseLevel(int l) 196 { 197 Subunit::setVerboseLevel(l); 198 if (m_status_descriptor != NULL) { 199 m_status_descriptor->setVerboseLevel(l); 200 } 54 201 } 55 202 branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.h
r508 r524 32 32 33 33 class Unit; 34 class Plug; 35 class AVCMusicStatusDescriptor; 34 36 35 37 // ///////////////////////////// … … 41 43 SubunitMusic(); 42 44 virtual ~SubunitMusic(); 45 46 virtual bool discover(); 47 virtual bool initPlugFromDescriptor( Plug& plug ); 43 48 49 virtual bool loadDescriptors(); 50 51 virtual void setVerboseLevel(int l); 44 52 virtual const char* getName(); 45 46 53 protected: 47 54 virtual bool serializeChild( Glib::ustring basePath, … … 50 57 Util::IODeserialize& deser, 51 58 Unit& avDevice ); 59 60 class AVCMusicStatusDescriptor* m_status_descriptor; 52 61 }; 53 62 branches/echoaudio/src/libstreaming/PortManager.cpp
r445 r524 25 25 #include "Port.h" 26 26 #include <assert.h> 27 28 #include <iostream> 29 #include <sstream> 27 30 28 31 … … 57 60 // } 58 61 62 bool PortManager::makeNameUnique(Port *port) 63 { 64 bool done=false; 65 int idx=0; 66 std::string portname_orig=port->getName(); 67 68 while(!done && idx<10000) { 69 bool is_unique=true; 70 71 for ( PortVectorIterator it = m_Ports.begin(); 72 it != m_Ports.end(); 73 ++it ) 74 { 75 is_unique &= !((*it)->getName() == port->getName()); 76 } 77 78 if (is_unique) { 79 done=true; 80 } else { 81 std::ostringstream portname; 82 portname << portname_orig << idx++; 83 84 port->setName(portname.str()); 85 } 86 } 87 88 if(idx<10000) return true; 89 else return false; 90 } 91 59 92 /** 60 93 * … … 66 99 assert(port); 67 100 68 debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s\n",port->getName().c_str()); 69 m_Ports.push_back(port); 70 71 return true; 101 debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s, type: %d, dir: %d, dtype: %d\n", 102 port->getName().c_str(), port->getPortType(), port->getDirection(), port->getDataType()); 103 104 if (makeNameUnique(port)) { 105 m_Ports.push_back(port); 106 return true; 107 } else { 108 return false; 109 } 72 110 } 73 111 branches/echoaudio/src/libstreaming/PortManager.h
r445 r524 48 48 virtual ~PortManager(); 49 49 50 virtual bool makeNameUnique(Port *port); 50 51 virtual bool addPort(Port *port); 51 52 virtual bool deletePort(Port *port); branches/echoaudio/src/Makefile.am
r508 r524 71 71 libavc/general/avc_generic.h \ 72 72 libavc/general/avc_connect.h \ 73 libavc/general/avc_signal_format.h \ 73 74 libavc/general/avc_extended_plug_info.h \ 74 75 libavc/general/avc_unit.h \ … … 112 113 libavc/general/avc_subunit_info.cpp \ 113 114 libavc/general/avc_connect.cpp \ 115 libavc/general/avc_signal_format.cpp \ 114 116 libavc/general/avc_extended_cmd_generic.cpp \ 115 117 libavc/general/avc_extended_plug_info.cpp \ branches/echoaudio/tests/Makefile.am
r499 r524 24 24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 25 26 #SUBDIRS=streaming26 SUBDIRS=streaming 27 27 28 28 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src $(LIBXML_CFLAGS) \ branches/echoaudio/tests/streaming/testmidistreaming1.c
r445 r524 45 45 #include <alsa/asoundlib.h> 46 46 47 #include "libf reebob/freebob_streaming.h"47 #include "libffado/ffado.h" 48 48 49 49 #include "debugtools.h" … … 68 68 snd_midi_event_t *parser; 69 69 snd_seq_t *seq_handle; 70 } f reebob_midi_port_t;70 } ffado_midi_port_t; 71 71 72 72 typedef struct { 73 73 snd_seq_t *seq_handle; 74 74 int nb_seq_ports; 75 f reebob_midi_port_t *ports[MAX_MIDI_PORTS];76 } f reebob_midi_ports_t;75 ffado_midi_port_t *ports[MAX_MIDI_PORTS]; 76 } ffado_midi_ports_t; 77 77 78 78 int open_seq(snd_seq_t **seq_handle, int in_ports[], int out_ports[], int num_in, int num_out); … … 113 113 } 114 114 115 void decode_midi_byte (f reebob_midi_port_t *port, int byte) {115 void decode_midi_byte (ffado_midi_port_t *port, int byte) { 116 116 snd_seq_event_t ev; 117 117 if ((snd_midi_event_encode_byte(port->parser,byte, &ev)) > 0) { … … 127 127 } 128 128 129 int encode_midi_bytes(f reebob_midi_port_t *port, unsigned char *byte_buff, int len) {129 int encode_midi_bytes(ffado_midi_port_t *port, unsigned char *byte_buff, int len) { 130 130 return 0; 131 131 } … … 140 140 int retval=0; 141 141 int i=0; 142 int start_flag = 0; 142 143 143 144 int nb_periods=0; 144 145 145 f reebob_sample_t **audiobuffers_in;146 f reebob_sample_t **audiobuffers_out;147 f reebob_sample_t *nullbuffer;146 ffado_sample_t **audiobuffers_in; 147 ffado_sample_t **audiobuffers_out; 148 ffado_sample_t *nullbuffer; 148 149 149 150 run=1; 150 151 151 printf("F reebobMIDI streaming test application (1)\n");152 printf("Ffado MIDI streaming test application (1)\n"); 152 153 153 154 signal (SIGINT, sighandler); 154 155 signal (SIGPIPE, sighandler); 155 156 156 f reebob_device_info_t device_info;157 158 f reebob_options_t dev_options;157 ffado_device_info_t device_info; 158 159 ffado_options_t dev_options; 159 160 160 161 dev_options.sample_rate=-1; // -1 = detect from discovery … … 169 170 dev_options.packetizer_priority=60; 170 171 171 freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 172 dev_options.verbose=5; 173 174 dev_options.slave_mode=0; 175 dev_options.snoop_mode=0; 176 177 ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 172 178 if (!dev) { 173 fprintf(stderr,"Could not init F reebobStreaming layer\n");179 fprintf(stderr,"Could not init Ffado Streaming layer\n"); 174 180 exit(-1); 175 181 } 176 182 177 nb_in_channels=f reebob_streaming_get_nb_capture_streams(dev);178 nb_out_channels=f reebob_streaming_get_nb_playback_streams(dev);183 nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 184 nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 179 185 180 186 int midi_in_nbchannels=0; … … 182 188 183 189 /* allocate intermediate buffers */ 184 audiobuffers_in=calloc(nb_in_channels,sizeof(f reebob_sample_t *));185 audiobuffers_out=calloc(nb_in_channels,sizeof(f reebob_sample_t));190 audiobuffers_in=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 191 audiobuffers_out=calloc(nb_in_channels,sizeof(ffado_sample_t)); 186 192 for (i=0;i<nb_in_channels;i++) { 187 audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));188 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));193 audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 194 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 189 195 190 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {191 case f reebob_stream_type_audio:196 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 197 case ffado_stream_type_audio: 192 198 /* assign the audiobuffer to the stream */ 193 f reebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));194 f reebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_float);199 ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 200 ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_float); 195 201 break; 196 202 197 203 // this is done with read/write routines because the nb of bytes can differ. 198 case f reebob_stream_type_midi:204 case ffado_stream_type_midi: 199 205 midi_in_nbchannels++; 200 206 default: … … 203 209 } 204 210 205 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));211 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 206 212 207 213 for (i=0;i<nb_out_channels;i++) { 208 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {209 case f reebob_stream_type_audio:214 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 215 case ffado_stream_type_audio: 210 216 if (i<nb_in_channels) { 211 217 /* assign the audiobuffer to the stream */ 212 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));213 f reebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_float);218 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 219 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float); 214 220 } else { 215 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer);216 f reebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24);221 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 222 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24); 217 223 } 218 224 break; 219 225 // this is done with read/write routines because the nb of bytes can differ. 220 case f reebob_stream_type_midi:226 case ffado_stream_type_midi: 221 227 midi_out_nbchannels++; 222 228 default: … … 235 241 fid_out[i]=fopen(name,"w"); 236 242 237 f reebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name));243 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 238 244 fprintf(fid_out[i],"Channel name: %s\n",name); 239 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {240 case f reebob_stream_type_audio:245 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 246 case ffado_stream_type_audio: 241 247 fprintf(fid_out[i],"Channel type: audio\n"); 242 248 break; 243 case f reebob_stream_type_midi:249 case ffado_stream_type_midi: 244 250 fprintf(fid_out[i],"Channel type: midi\n"); 245 251 break; 246 case f reebob_stream_type_unknown:252 case ffado_stream_type_unknown: 247 253 fprintf(fid_out[i],"Channel type: unknown\n"); 248 254 break; 249 255 default: 250 case f reebob_stream_type_invalid:256 case ffado_stream_type_invalid: 251 257 fprintf(fid_out[i],"Channel type: invalid\n"); 252 258 break; … … 258 264 fid_in[i]=fopen(name,"w"); 259 265 260 f reebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name));261 fprintf(fid_in[i], "Channel name: %s\n" );262 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {263 case f reebob_stream_type_audio:266 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 267 fprintf(fid_in[i], "Channel name: %s\n", name); 268 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 269 case ffado_stream_type_audio: 264 270 fprintf(fid_in[i], "Channel type: audio\n"); 265 271 break; 266 case f reebob_stream_type_midi:272 case ffado_stream_type_midi: 267 273 fprintf(fid_in[i], "Channel type: midi\n"); 268 274 break; 269 case f reebob_stream_type_unknown:275 case ffado_stream_type_unknown: 270 276 fprintf(fid_in[i],"Channel type: unknown\n"); 271 277 break; 272 278 default: 273 case f reebob_stream_type_invalid:279 case ffado_stream_type_invalid: 274 280 fprintf(fid_in[i],"Channel type: invalid\n"); 275 281 break; … … 288 294 } 289 295 290 f reebob_midi_port_t* midi_out_portmap[nb_out_channels];291 f reebob_midi_port_t* midi_in_portmap[nb_in_channels];296 ffado_midi_port_t* midi_out_portmap[nb_out_channels]; 297 ffado_midi_port_t* midi_in_portmap[nb_in_channels]; 292 298 293 299 int cnt=0; 294 300 295 301 for (i=0;i<nb_out_channels;i++) { 296 f reebob_midi_port_t *midi_out_port;297 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {298 case f reebob_stream_type_audio:302 ffado_midi_port_t *midi_out_port; 303 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 304 case ffado_stream_type_audio: 299 305 midi_out_portmap[i]=NULL; 300 306 break; 301 case f reebob_stream_type_midi:302 midi_out_port=malloc(sizeof(f reebob_midi_port_t));307 case ffado_stream_type_midi: 308 midi_out_port=malloc(sizeof(ffado_midi_port_t)); 303 309 if(!midi_out_port) { 304 310 fprintf(stderr, "Could not allocate memory for MIDI OUT port %d\n",i); … … 314 320 } 315 321 break; 322 default: break; 316 323 } 317 324 } … … 319 326 cnt=0; 320 327 for (i=0;i<nb_in_channels;i++) { 321 f reebob_midi_port_t *midi_in_port;322 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {323 case f reebob_stream_type_audio:328 ffado_midi_port_t *midi_in_port; 329 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 330 case ffado_stream_type_audio: 324 331 midi_in_portmap[i]=NULL; 325 332 break; 326 case f reebob_stream_type_midi:333 case ffado_stream_type_midi: 327 334 328 midi_in_port=malloc(sizeof(f reebob_midi_port_t));335 midi_in_port=malloc(sizeof(ffado_midi_port_t)); 329 336 if(!midi_in_port) { 330 337 fprintf(stderr, "Could not allocate memory for MIDI IN port %d\n",i); … … 340 347 midi_in_portmap[i]=midi_in_port; 341 348 } 342 break; 349 break; 350 default: break; 343 351 } 344 352 } 345 353 346 354 // start the streaming layer 347 freebob_streaming_start(dev);355 start_flag = ffado_streaming_start(dev); 348 356 349 357 fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 350 while(run ) {351 retval = f reebob_streaming_wait(dev);358 while(run && start_flag==0) { 359 retval = ffado_streaming_wait(dev); 352 360 if (retval < 0) { 353 361 fprintf(stderr,"Xrun\n"); 354 f reebob_streaming_reset(dev);362 ffado_streaming_reset(dev); 355 363 continue; 356 364 } 357 365 358 // f reebob_streaming_transfer_buffers(dev);359 f reebob_streaming_transfer_capture_buffers(dev);360 f reebob_streaming_transfer_playback_buffers(dev);366 // ffado_streaming_transfer_buffers(dev); 367 ffado_streaming_transfer_capture_buffers(dev); 368 ffado_streaming_transfer_playback_buffers(dev); 361 369 362 370 nb_periods++; … … 369 377 int s; 370 378 371 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {372 case f reebob_stream_type_audio:379 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 380 case ffado_stream_type_audio: 373 381 // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 374 // //samplesread=f reebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);382 // //samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 375 383 samplesread=PERIOD_SIZE; 376 384 break; 377 case f reebob_stream_type_midi:378 samplesread=f reebob_streaming_read(dev, i, audiobuffers_in[i], PERIOD_SIZE);385 case ffado_stream_type_midi: 386 samplesread=ffado_streaming_read(dev, i, audiobuffers_in[i], PERIOD_SIZE); 379 387 quadlet_t *buff=(quadlet_t *)audiobuffers_in[i]; 380 388 for (s=0;s<samplesread;s++) { … … 385 393 if(samplesread>0) { 386 394 fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 387 hexDumpToFile(fid_in[i],(unsigned char*)audiobuffers_in[i],samplesread*sizeof(freebob_sample_t)); 388 } 389 break; 395 hexDumpToFile(fid_in[i],(unsigned char*)audiobuffers_in[i],samplesread*sizeof(ffado_sample_t)); 396 } 397 break; 398 default: break; 390 399 } 391 400 // fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 392 // hexDumpToFile(fid_in[i],(unsigned char*)buff,samplesread*sizeof(f reebob_sample_t));401 // hexDumpToFile(fid_in[i],(unsigned char*)buff,samplesread*sizeof(ffado_sample_t)); 393 402 394 403 } 395 404 396 405 for(i=0;i<nb_out_channels;i++) { 397 f reebob_sample_t *buff;406 ffado_sample_t *buff; 398 407 int b=0; 399 408 unsigned char* byte_buff; … … 405 414 } 406 415 407 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {408 case f reebob_stream_type_audio:409 // sampleswritten=f reebob_streaming_write(dev, i, buff, PERIOD_SIZE);416 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 417 case ffado_stream_type_audio: 418 // sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 410 419 // sampleswritten=PERIOD_SIZE; 411 420 break; 412 case f reebob_stream_type_midi:421 case ffado_stream_type_midi: 413 422 414 423 #define max_midi_bytes_to_write PERIOD_SIZE/8 … … 418 427 419 428 for(b=0;b<sampleswritten;b++) { 420 f reebob_sample_t tmp_event=*(byte_buff+b);421 f reebob_streaming_write(dev, i, &tmp_event, 1);429 ffado_sample_t tmp_event=*(byte_buff+b); 430 ffado_streaming_write(dev, i, &tmp_event, 1); 422 431 } 423 432 424 433 425 434 fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 426 hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(freebob_sample_t)); 427 break; 435 hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 436 break; 437 default: break; 428 438 } 429 439 } … … 435 445 fprintf(stderr,"Exiting receive loop\n"); 436 446 437 f reebob_streaming_stop(dev);438 439 f reebob_streaming_finish(dev);447 ffado_streaming_stop(dev); 448 449 ffado_streaming_finish(dev); 440 450 441 451 for (i=0;i<nb_out_channels;i++) { … … 457 467 // free the MIDI to seq parsers and port structures 458 468 for(i=0;i<midi_in_nbchannels;i++) { 459 f reebob_midi_port_t *midi_in_port=midi_in_portmap[i];469 ffado_midi_port_t *midi_in_port=midi_in_portmap[i]; 460 470 461 471 if(midi_in_port) { … … 466 476 // free the MIDI to seq parsers and port structures 467 477 for(i=0;i<midi_out_nbchannels;i++) { 468 f reebob_midi_port_t *midi_out_port=midi_out_portmap[i];478 ffado_midi_port_t *midi_out_port=midi_out_portmap[i]; 469 479 470 480 if(midi_out_port) { branches/echoaudio/tests/streaming/teststreaming.c
r445 r524 36 36 #include <signal.h> 37 37 38 #include "libf reebob/freebob_streaming.h"38 #include "libffado/ffado.h" 39 39 40 40 #include "debugtools.h" … … 56 56 int retval=0; 57 57 int i=0; 58 int start_flag = 0; 58 59 59 60 int nb_periods=0; 60 61 61 f reebob_sample_t **audiobuffer;62 f reebob_sample_t *nullbuffer;62 ffado_sample_t **audiobuffer; 63 ffado_sample_t *nullbuffer; 63 64 64 65 run=1; 65 66 66 printf("F reebobstreaming test application\n");67 printf("Ffado streaming test application\n"); 67 68 68 69 signal (SIGINT, sighandler); 69 70 signal (SIGPIPE, sighandler); 70 71 71 f reebob_device_info_t device_info;72 73 f reebob_options_t dev_options;72 ffado_device_info_t device_info; 73 74 ffado_options_t dev_options; 74 75 75 76 dev_options.sample_rate=44100; … … 83 84 dev_options.realtime=0; 84 85 dev_options.packetizer_priority=60; 85 86 freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 86 87 dev_options.verbose=5; 88 89 dev_options.slave_mode=0; 90 dev_options.snoop_mode=0; 91 92 ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 87 93 if (!dev) { 88 fprintf(stderr,"Could not init F reebobStreaming layer\n");94 fprintf(stderr,"Could not init FFADO Streaming layer\n"); 89 95 exit(-1); 90 96 } 91 97 92 nb_in_channels=f reebob_streaming_get_nb_capture_streams(dev);93 nb_out_channels=f reebob_streaming_get_nb_playback_streams(dev);98 nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 99 nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 94 100 95 101 /* allocate intermediate buffers */ 96 audiobuffer=calloc(nb_in_channels,sizeof(f reebob_sample_t *));97 for (i=0;i<nb_in_channels;i++) { 98 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));99 } 100 101 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));102 audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 103 for (i=0;i<nb_in_channels;i++) { 104 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 105 } 106 107 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 102 108 103 109 /* open the files to write to*/ … … 111 117 fid_out[i]=fopen(name,"w"); 112 118 113 f reebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name));119 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 114 120 fprintf(fid_out[i],"Channel name: %s\n",name); 115 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {116 case f reebob_stream_type_audio:121 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 122 case ffado_stream_type_audio: 117 123 fprintf(fid_out[i],"Channel type: audio\n"); 118 124 break; 119 case f reebob_stream_type_midi:125 case ffado_stream_type_midi: 120 126 fprintf(fid_out[i],"Channel type: midi\n"); 121 127 break; 122 case f reebob_stream_type_unknown:128 case ffado_stream_type_unknown: 123 129 fprintf(fid_out[i],"Channel type: unknown\n"); 124 130 break; 125 131 default: 126 case f reebob_stream_type_invalid:132 case ffado_stream_type_invalid: 127 133 fprintf(fid_out[i],"Channel type: invalid\n"); 128 134 break; … … 134 140 fid_in[i]=fopen(name,"w"); 135 141 136 f reebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name));142 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 137 143 fprintf(fid_in[i], "Channel name: %s\n",name); 138 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {139 case f reebob_stream_type_audio:144 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 145 case ffado_stream_type_audio: 140 146 fprintf(fid_in[i], "Channel type: audio\n"); 141 147 break; 142 case f reebob_stream_type_midi:148 case ffado_stream_type_midi: 143 149 fprintf(fid_in[i], "Channel type: midi\n"); 144 150 break; 145 case f reebob_stream_type_unknown:151 case ffado_stream_type_unknown: 146 152 fprintf(fid_in[i],"Channel type: unknown\n"); 147 153 break; 148 154 default: 149 case f reebob_stream_type_invalid:155 case ffado_stream_type_invalid: 150 156 fprintf(fid_in[i],"Channel type: invalid\n"); 151 157 break; … … 153 159 } 154 160 155 f reebob_streaming_prepare(dev);156 freebob_streaming_start(dev);161 ffado_streaming_prepare(dev); 162 start_flag = ffado_streaming_start(dev); 157 163 158 164 fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 159 while(run ) {160 retval = f reebob_streaming_wait(dev);165 while(run && start_flag==0) { 166 retval = ffado_streaming_wait(dev); 161 167 if (retval < 0) { 162 168 fprintf(stderr,"Xrun\n"); 163 f reebob_streaming_reset(dev);169 ffado_streaming_reset(dev); 164 170 continue; 165 171 } 166 172 167 // f reebob_streaming_transfer_buffers(dev);168 f reebob_streaming_transfer_capture_buffers(dev);169 f reebob_streaming_transfer_playback_buffers(dev);173 // ffado_streaming_transfer_buffers(dev); 174 ffado_streaming_transfer_capture_buffers(dev); 175 ffado_streaming_transfer_playback_buffers(dev); 170 176 171 177 nb_periods++; … … 176 182 177 183 for(i=0;i<nb_in_channels;i++) { 178 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {179 case f reebob_stream_type_audio:180 samplesread=f reebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);181 break; 182 case f reebob_stream_type_midi:183 samplesread=f reebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);184 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 185 case ffado_stream_type_audio: 186 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 187 break; 188 case ffado_stream_type_midi: 189 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 184 190 break; 185 191 default: … … 187 193 } 188 194 // fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 189 // hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(f reebob_sample_t));195 // hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t)); 190 196 } 191 197 192 198 for(i=0;i<nb_out_channels;i++) { 193 f reebob_sample_t *buff;199 ffado_sample_t *buff; 194 200 if (i<nb_in_channels) { 195 201 buff=audiobuffer[i]; … … 198 204 } 199 205 200 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {201 case f reebob_stream_type_audio:202 sampleswritten=f reebob_streaming_write(dev, i, buff, PERIOD_SIZE);203 break; 204 case f reebob_stream_type_midi:205 sampleswritten=f reebob_streaming_write(dev, i, buff, PERIOD_SIZE);206 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 207 case ffado_stream_type_audio: 208 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 209 break; 210 case ffado_stream_type_midi: 211 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 206 212 break; 207 213 default: … … 209 215 } 210 216 // fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 211 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(f reebob_sample_t));217 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 212 218 } 213 219 … … 218 224 fprintf(stderr,"Exiting receive loop\n"); 219 225 220 f reebob_streaming_stop(dev);221 222 f reebob_streaming_finish(dev);226 ffado_streaming_stop(dev); 227 228 ffado_streaming_finish(dev); 223 229 224 230 for (i=0;i<nb_out_channels;i++) { branches/echoaudio/tests/streaming/teststreaming2.c
r445 r524 38 38 #include <signal.h> 39 39 40 #include "libf reebob/freebob_streaming.h"40 #include "libffado/ffado.h" 41 41 42 42 #include "debugtools.h" … … 58 58 int retval=0; 59 59 int i=0; 60 int start_flag=0; 60 61 61 62 int nb_periods=0; 62 63 63 f reebob_sample_t **audiobuffer;64 f reebob_sample_t *nullbuffer;64 ffado_sample_t **audiobuffer; 65 ffado_sample_t *nullbuffer; 65 66 66 67 run=1; 67 68 68 printf("F reebobstreaming test application (2)\n");69 printf("Ffado streaming test application (2)\n"); 69 70 70 71 signal (SIGINT, sighandler); 71 72 signal (SIGPIPE, sighandler); 72 73 73 f reebob_device_info_t device_info;74 75 f reebob_options_t dev_options;74 ffado_device_info_t device_info; 75 76 ffado_options_t dev_options; 76 77 77 78 dev_options.sample_rate=44100; … … 85 86 dev_options.realtime=1; 86 87 dev_options.packetizer_priority=60; 87 88 freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 88 89 dev_options.verbose=5; 90 91 dev_options.slave_mode=0; 92 dev_options.snoop_mode=0; 93 94 ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 89 95 if (!dev) { 90 fprintf(stderr,"Could not init F reebobStreaming layer\n");96 fprintf(stderr,"Could not init Ffado Streaming layer\n"); 91 97 exit(-1); 92 98 } 93 99 94 nb_in_channels=f reebob_streaming_get_nb_capture_streams(dev);95 nb_out_channels=f reebob_streaming_get_nb_playback_streams(dev);100 nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 101 nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 96 102 97 103 /* allocate intermediate buffers */ 98 audiobuffer=calloc(nb_in_channels,sizeof(f reebob_sample_t *));99 for (i=0;i<nb_in_channels;i++) { 100 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));101 102 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {103 case f reebob_stream_type_audio:104 audiobuffer=calloc(nb_in_channels,sizeof(ffado_sample_t *)); 105 for (i=0;i<nb_in_channels;i++) { 106 audiobuffer[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 107 108 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 109 case ffado_stream_type_audio: 104 110 /* assign the audiobuffer to the stream */ 105 f reebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i]));106 f reebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_int24);111 ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffer[i])); 112 ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_int24); 107 113 break; 108 114 // this is done with read/write routines because the nb of bytes can differ. 109 case f reebob_stream_type_midi:115 case ffado_stream_type_midi: 110 116 default: 111 117 break; … … 113 119 } 114 120 115 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));121 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 116 122 117 123 #if 1 118 124 for (i=0;i<nb_out_channels;i++) { 119 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {120 case f reebob_stream_type_audio:125 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 126 case ffado_stream_type_audio: 121 127 if (i<nb_in_channels) { 122 128 /* assign the audiobuffer to the stream */ 123 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffer[i]);129 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)audiobuffer[i]); 124 130 } else { 125 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer);131 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 126 132 } 127 f reebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24);133 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24); 128 134 break; 129 135 // this is done with read/write routines because the nb of bytes can differ. 130 case f reebob_stream_type_midi:136 case ffado_stream_type_midi: 131 137 default: 132 138 break; … … 145 151 fid_out[i]=fopen(name,"w"); 146 152 147 f reebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name));153 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 148 154 fprintf(fid_out[i],"Channel name: %s\n",name); 149 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {150 case f reebob_stream_type_audio:155 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 156 case ffado_stream_type_audio: 151 157 fprintf(fid_out[i],"Channel type: audio\n"); 152 158 break; 153 case f reebob_stream_type_midi:159 case ffado_stream_type_midi: 154 160 fprintf(fid_out[i],"Channel type: midi\n"); 155 161 break; 156 case f reebob_stream_type_unknown:162 case ffado_stream_type_unknown: 157 163 fprintf(fid_out[i],"Channel type: unknown\n"); 158 164 break; 159 165 default: 160 case f reebob_stream_type_invalid:166 case ffado_stream_type_invalid: 161 167 fprintf(fid_out[i],"Channel type: invalid\n"); 162 168 break; … … 168 174 fid_in[i]=fopen(name,"w"); 169 175 170 f reebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name));176 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 171 177 fprintf(fid_in[i], "Channel name: %s\n",name); 172 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {173 case f reebob_stream_type_audio:178 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 179 case ffado_stream_type_audio: 174 180 fprintf(fid_in[i], "Channel type: audio\n"); 175 181 break; 176 case f reebob_stream_type_midi:182 case ffado_stream_type_midi: 177 183 fprintf(fid_in[i], "Channel type: midi\n"); 178 184 break; 179 case f reebob_stream_type_unknown:185 case ffado_stream_type_unknown: 180 186 fprintf(fid_in[i],"Channel type: unknown\n"); 181 187 break; 182 188 default: 183 case f reebob_stream_type_invalid:189 case ffado_stream_type_invalid: 184 190 fprintf(fid_in[i],"Channel type: invalid\n"); 185 191 break; … … 190 196 191 197 // prepare and start the streaming layer 192 f reebob_streaming_prepare(dev);193 freebob_streaming_start(dev);198 ffado_streaming_prepare(dev); 199 start_flag = ffado_streaming_start(dev); 194 200 195 201 fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 196 while(run ) {197 retval = f reebob_streaming_wait(dev);202 while(run && start_flag==0) { 203 retval = ffado_streaming_wait(dev); 198 204 if (retval < 0) { 199 205 fprintf(stderr,"Xrun\n"); 200 f reebob_streaming_reset(dev);206 ffado_streaming_reset(dev); 201 207 continue; 202 208 } 203 209 204 210 for (i=0;i<nb_in_channels;i++) { 205 memset(audiobuffer[i],0xCC,(PERIOD_SIZE+1)*sizeof(f reebob_sample_t));206 } 207 208 // f reebob_streaming_transfer_buffers(dev);209 f reebob_streaming_transfer_capture_buffers(dev);210 f reebob_streaming_transfer_playback_buffers(dev);211 memset(audiobuffer[i],0xCC,(PERIOD_SIZE+1)*sizeof(ffado_sample_t)); 212 } 213 214 // ffado_streaming_transfer_buffers(dev); 215 ffado_streaming_transfer_capture_buffers(dev); 216 ffado_streaming_transfer_playback_buffers(dev); 211 217 212 218 nb_periods++; … … 219 225 220 226 221 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {222 case f reebob_stream_type_audio:227 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 228 case ffado_stream_type_audio: 223 229 // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 224 // //samplesread=f reebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);230 // //samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 225 231 samplesread=PERIOD_SIZE; 226 232 break; 227 case f reebob_stream_type_midi:228 samplesread=f reebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE);233 case ffado_stream_type_midi: 234 samplesread=ffado_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 229 235 break; 230 236 default: … … 233 239 234 240 // fprintf(fid_in[i], "---- Period read (%d samples) ----\n",samplesread); 235 // hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(f reebob_sample_t)+1);241 // hexDumpToFile(fid_in[i],(unsigned char*)audiobuffer[i],samplesread*sizeof(ffado_sample_t)+1); 236 242 // FIXME: Dump analog1 as raw data to a separate binary file for testing 237 243 //if (i==2) { 238 // fwrite(audiobuffer[i],sizeof(f reebob_sample_t),samplesread,of);244 // fwrite(audiobuffer[i],sizeof(ffado_sample_t),samplesread,of); 239 245 //} 240 246 } 241 247 242 248 for(i=0;i<nb_out_channels;i++) { 243 f reebob_sample_t *buff;249 ffado_sample_t *buff; 244 250 if (i<nb_in_channels) { 245 251 buff=audiobuffer[i]; … … 248 254 } 249 255 250 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {251 case f reebob_stream_type_audio:252 //// Calling f reebob_streaming_write() causes problems since the buffer is external here.256 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 257 case ffado_stream_type_audio: 258 //// Calling ffado_streaming_write() causes problems since the buffer is external here. 253 259 //// Just mirror the read case since it seems to work. 254 //// sampleswritten=f reebob_streaming_write(dev, i, buff, PERIOD_SIZE);260 //// sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 255 261 sampleswritten=PERIOD_SIZE; 256 262 break; 257 case f reebob_stream_type_midi:258 sampleswritten=f reebob_streaming_write(dev, i, buff, PERIOD_SIZE);263 case ffado_stream_type_midi: 264 sampleswritten=ffado_streaming_write(dev, i, buff, PERIOD_SIZE); 259 265 break; 260 266 default: … … 262 268 } 263 269 // fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 264 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(f reebob_sample_t));270 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 265 271 } 266 272 … … 271 277 fprintf(stderr,"Exiting receive loop\n"); 272 278 273 f reebob_streaming_stop(dev);274 275 f reebob_streaming_finish(dev);279 ffado_streaming_stop(dev); 280 281 ffado_streaming_finish(dev); 276 282 fclose(of); 277 283 branches/echoaudio/tests/streaming/teststreaming3.c
r445 r524 38 38 #include <signal.h> 39 39 40 #include "libf reebob/freebob_streaming.h"40 #include "libffado/ffado.h" 41 41 42 42 #include "debugtools.h" … … 59 59 int retval=0; 60 60 int i=0; 61 int start_flag = 0; 61 62 62 63 int nb_periods=0; 63 64 64 65 float **audiobuffers_in; 65 f reebob_sample_t **audiobuffers_out;66 f reebob_sample_t *nullbuffer;66 ffado_sample_t **audiobuffers_out; 67 ffado_sample_t *nullbuffer; 67 68 68 69 run=1; 69 70 70 printf("F reebobstreaming test application (3)\n");71 printf("Ffado streaming test application (3)\n"); 71 72 72 73 signal (SIGINT, sighandler); 73 74 signal (SIGPIPE, sighandler); 74 75 75 f reebob_device_info_t device_info;76 77 f reebob_options_t dev_options;76 ffado_device_info_t device_info; 77 78 ffado_options_t dev_options; 78 79 79 80 dev_options.sample_rate=44100; … … 88 89 dev_options.packetizer_priority=70; 89 90 90 freebob_device_t *dev=freebob_streaming_init(&device_info, dev_options); 91 dev_options.verbose=5; 92 93 dev_options.slave_mode=0; 94 dev_options.snoop_mode=0; 95 96 ffado_device_t *dev=ffado_streaming_init(&device_info, dev_options); 91 97 if (!dev) { 92 fprintf(stderr,"Could not init F reebobStreaming layer\n");98 fprintf(stderr,"Could not init Ffado Streaming layer\n"); 93 99 exit(-1); 94 100 } 95 101 96 nb_in_channels=f reebob_streaming_get_nb_capture_streams(dev);97 nb_out_channels=f reebob_streaming_get_nb_playback_streams(dev);102 nb_in_channels=ffado_streaming_get_nb_capture_streams(dev); 103 nb_out_channels=ffado_streaming_get_nb_playback_streams(dev); 98 104 99 105 /* allocate intermediate buffers */ 100 106 audiobuffers_in=calloc(nb_in_channels,sizeof(float *)); 101 audiobuffers_out=calloc(nb_in_channels,sizeof(f reebob_sample_t));107 audiobuffers_out=calloc(nb_in_channels,sizeof(ffado_sample_t)); 102 108 for (i=0;i<nb_in_channels;i++) { 103 109 audiobuffers_in[i]=calloc(PERIOD_SIZE+1,sizeof(float)); 104 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));105 106 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {107 case f reebob_stream_type_audio:110 audiobuffers_out[i]=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 111 112 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 113 case ffado_stream_type_audio: 108 114 /* assign the audiobuffer to the stream */ 109 f reebob_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));110 f reebob_streaming_set_capture_buffer_type(dev, i, freebob_buffer_type_float);115 ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 116 ffado_streaming_set_capture_buffer_type(dev, i, ffado_buffer_type_float); 111 117 break; 112 118 // this is done with read/write routines because the nb of bytes can differ. 113 case f reebob_stream_type_midi:119 case ffado_stream_type_midi: 114 120 default: 115 121 break; … … 117 123 } 118 124 119 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(f reebob_sample_t));125 nullbuffer=calloc(PERIOD_SIZE+1,sizeof(ffado_sample_t)); 120 126 121 127 for (i=0;i<nb_out_channels;i++) { 122 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {123 case f reebob_stream_type_audio:128 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 129 case ffado_stream_type_audio: 124 130 if (i<nb_in_channels) { 125 131 /* assign the audiobuffer to the stream */ 126 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i]));127 f reebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_float);132 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); 133 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_float); 128 134 } else { 129 f reebob_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer);130 f reebob_streaming_set_playback_buffer_type(dev, i, freebob_buffer_type_int24);135 ffado_streaming_set_playback_stream_buffer(dev, i, (char *)nullbuffer); 136 ffado_streaming_set_playback_buffer_type(dev, i, ffado_buffer_type_int24); 131 137 } 132 138 break; 133 139 // this is done with read/write routines because the nb of bytes can differ. 134 case f reebob_stream_type_midi:140 case ffado_stream_type_midi: 135 141 default: 136 142 break; … … 148 154 fid_out[i]=fopen(name,"w"); 149 155 150 f reebob_streaming_get_playback_stream_name(dev,i,name,sizeof(name));156 ffado_streaming_get_playback_stream_name(dev,i,name,sizeof(name)); 151 157 fprintf(fid_out[i],"Channel name: %s\n",name); 152 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {153 case f reebob_stream_type_audio:158 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 159 case ffado_stream_type_audio: 154 160 fprintf(fid_out[i],"Channel type: audio\n"); 155 161 break; 156 case f reebob_stream_type_midi:162 case ffado_stream_type_midi: 157 163 fprintf(fid_out[i],"Channel type: midi\n"); 158 164 break; 159 case f reebob_stream_type_unknown:165 case ffado_stream_type_unknown: 160 166 fprintf(fid_out[i],"Channel type: unknown\n"); 161 167 break; 162 168 default: 163 case f reebob_stream_type_invalid:169 case ffado_stream_type_invalid: 164 170 fprintf(fid_out[i],"Channel type: invalid\n"); 165 171 break; … … 171 177 fid_in[i]=fopen(name,"w"); 172 178 173 f reebob_streaming_get_capture_stream_name(dev,i,name,sizeof(name));174 fprintf(fid_in[i], "Channel name: %s\n" );175 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {176 case f reebob_stream_type_audio:179 ffado_streaming_get_capture_stream_name(dev,i,name,sizeof(name)); 180 fprintf(fid_in[i], "Channel name: %s\n",name); 181 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 182 case ffado_stream_type_audio: 177 183 fprintf(fid_in[i], "Channel type: audio\n"); 178 184 break; 179 case f reebob_stream_type_midi:185 case ffado_stream_type_midi: 180 186 fprintf(fid_in[i], "Channel type: midi\n"); 181 187 break; 182 case f reebob_stream_type_unknown:188 case ffado_stream_type_unknown: 183 189 fprintf(fid_in[i],"Channel type: unknown\n"); 184 190 break; 185 191 default: 186 case f reebob_stream_type_invalid:192 case ffado_stream_type_invalid: 187 193 fprintf(fid_in[i],"Channel type: invalid\n"); 188 194 break; … … 191 197 192 198 // start the streaming layer 193 freebob_streaming_start(dev); 199 ffado_streaming_prepare(dev); 200 start_flag = ffado_streaming_start(dev); 194 201 195 202 fprintf(stderr,"Entering receive loop (%d,%d)\n",nb_in_channels,nb_out_channels); 196 while(run ) {197 retval = f reebob_streaming_wait(dev);203 while(run && start_flag==0) { 204 retval = ffado_streaming_wait(dev); 198 205 if (retval < 0) { 199 206 fprintf(stderr,"Xrun\n"); 200 f reebob_streaming_reset(dev);207 ffado_streaming_reset(dev); 201 208 continue; 202 209 } 203 210 204 // f reebob_streaming_transfer_buffers(dev);205 f reebob_streaming_transfer_capture_buffers(dev);206 f reebob_streaming_transfer_playback_buffers(dev);211 // ffado_streaming_transfer_buffers(dev); 212 ffado_streaming_transfer_capture_buffers(dev); 213 ffado_streaming_transfer_playback_buffers(dev); 207 214 208 215 nb_periods++; … … 215 222 216 223 217 switch (f reebob_streaming_get_capture_stream_type(dev,i)) {218 case f reebob_stream_type_audio:224 switch (ffado_streaming_get_capture_stream_type(dev,i)) { 225 case ffado_stream_type_audio: 219 226 // no need to get the buffers manually, we have set the API internal buffers to the audiobuffer[i]'s 220 227 // //samplesread=freebob_streaming_read(dev, i, audiobuffer[i], PERIOD_SIZE); 221 228 samplesread=PERIOD_SIZE; 222 229 break; 223 case freebob_stream_type_midi: 224 samplesread=freebob_streaming_read(dev, i, audiobuffers_out[i], PERIOD_SIZE); 225 break; 230 case ffado_stream_type_midi: 231 samplesread=ffado_streaming_read(dev, i, audiobuffers_out[i], PERIOD_SIZE); 232 break; 233 default: break; 226 234 } 227 235 … … 231 239 232 240 for(i=0;i<nb_out_channels;i++) { 233 f reebob_sample_t *buff;241 ffado_sample_t *buff; 234 242 int sampleswritten=0; 235 243 if (i<nb_in_channels) { … … 239 247 } 240 248 241 switch (f reebob_streaming_get_playback_stream_type(dev,i)) {242 case f reebob_stream_type_audio:249 switch (ffado_streaming_get_playback_stream_type(dev,i)) { 250 case ffado_stream_type_audio: 243 251 // sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 244 252 sampleswritten=PERIOD_SIZE; 245 253 break; 246 case f reebob_stream_type_midi:254 case ffado_stream_type_midi: 247 255 // sampleswritten=freebob_streaming_write(dev, i, buff, PERIOD_SIZE); 248 256 break; 257 default: break; 249 258 } 250 259 // fprintf(fid_out[i], "---- Period write (%d samples) ----\n",sampleswritten); 251 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(f reebob_sample_t));260 // hexDumpToFile(fid_out[i],(unsigned char*)buff,sampleswritten*sizeof(ffado_sample_t)); 252 261 } 253 262 … … 258 267 fprintf(stderr,"Exiting receive loop\n"); 259 268 260 f reebob_streaming_stop(dev);261 262 f reebob_streaming_finish(dev);269 ffado_streaming_stop(dev); 270 271 ffado_streaming_finish(dev); 263 272 264 273 for (i=0;i<nb_out_channels;i++) {