Changeset 435 for branches/streaming-rework
- Timestamp:
- 03/11/07 06:20:31 (16 years ago)
- Files:
-
- branches/streaming-rework/config.h.in (deleted)
- branches/streaming-rework/configure.ac (modified) (4 diffs)
- branches/streaming-rework/libfreebob/freebob.h (modified) (4 diffs)
- branches/streaming-rework/libfreebob/freebob_bounce.h (deleted)
- branches/streaming-rework/libfreebob/freebob_streaming.h (modified) (1 diff)
- branches/streaming-rework/libfreebob/Makefile.am (modified) (1 diff)
- branches/streaming-rework/libfreebob/xmlparser.h (deleted)
- branches/streaming-rework/src/bebob/bebob_avdevice.cpp (modified) (2 diffs)
- branches/streaming-rework/src/bebob/bebob_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/bebob/bebob_avdevice_xml.cpp (deleted)
- branches/streaming-rework/src/bebob/bebob_avplug.h (modified) (2 diffs)
- branches/streaming-rework/src/bebob/bebob_avplug_xml.cpp (deleted)
- branches/streaming-rework/src/bounce/bounce_avdevice.cpp (modified) (5 diffs)
- branches/streaming-rework/src/bounce/bounce_avdevice.h (modified) (3 diffs)
- branches/streaming-rework/src/bounce/bounce_slave_avdevice.cpp (modified) (2 diffs)
- branches/streaming-rework/src/bounce/bounce_slave_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/devicemanager.cpp (modified) (6 diffs)
- branches/streaming-rework/src/devicemanager.h (modified) (4 diffs)
- branches/streaming-rework/src/freebob.cpp (modified) (4 diffs)
- branches/streaming-rework/src/freebob_streaming.cpp (modified) (7 diffs)
- branches/streaming-rework/src/iavdevice.cpp (modified) (2 diffs)
- branches/streaming-rework/src/iavdevice.h (modified) (3 diffs)
- branches/streaming-rework/src/libieee1394/configrom.cpp (modified) (3 diffs)
- branches/streaming-rework/src/libieee1394/configrom.h (modified) (2 diffs)
- branches/streaming-rework/src/libstreaming/AmdtpSlaveStreamProcessor.cpp (added)
- branches/streaming-rework/src/libstreaming/AmdtpSlaveStreamProcessor.h (added)
- branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (modified) (11 diffs)
- branches/streaming-rework/src/libstreaming/cip.h (modified) (1 diff)
- branches/streaming-rework/src/libstreaming/StreamProcessorManager.cpp (modified) (5 diffs)
- branches/streaming-rework/src/libutil/unittests.cpp (modified) (4 diffs)
- branches/streaming-rework/src/Makefile.am (modified) (9 diffs)
- branches/streaming-rework/src/maudio/maudio_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/metrichalo/mh_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/motu/motu_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/rme/rme_avdevice.h (modified) (1 diff)
- branches/streaming-rework/src/xmlparser.c (deleted)
- branches/streaming-rework/tests/freebob-server.c (deleted)
- branches/streaming-rework/tests/Makefile.am (modified) (3 diffs)
- branches/streaming-rework/tests/test-freebob.c (deleted)
- branches/streaming-rework/tests/test-freebob.cpp (moved) (moved from branches/streaming-rework/tests/test-freebob-cpp.cpp) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/streaming-rework/configure.ac
r414 r435 1 1 # configure.ac - Configure script for FreeBoB. 2 2 # Copyright (C) 2005,06 by Daniel Wagner. 3 # Copyright (C) 2006 3 # Copyright (C) 2006,07 by Pieter Palmers. 4 4 # 5 5 # This file is part of FreeBoB. … … 25 25 m4_define(freebob_major_version, 1) 26 26 m4_define(freebob_minor_version, 999) 27 m4_define(freebob_micro_version, 3)27 m4_define(freebob_micro_version, 4) 28 28 29 29 m4_define(freebob_version, freebob_major_version.freebob_minor_version.freebob_micro_version) … … 117 117 PKG_CHECK_MODULES(LIBAVC1394, libavc1394 >= 0.5.3) 118 118 PKG_CHECK_MODULES(ALSA, alsa >= 1.0.0) 119 PKG_CHECK_MODULES(LIBXML, libxml-2.0 >= 2.6.0)120 119 PKG_CHECK_MODULES(LIBXMLCPP, libxml++-2.6 >= 2.14.0) 120 PKG_CHECK_MODULES(LIBLO, liblo >= 0.22) 121 121 122 122 # Setup CFLAGS and CXXFLAGS … … 391 391 AC_SUBST([LIBAVC1394_CFLAGS]) 392 392 AC_SUBST([LIBAVC1394_LIBS]) 393 AC_SUBST([LIB XML_LIBS])394 AC_SUBST([LIB XML_CFLAGS])393 AC_SUBST([LIBLO_LIBS]) 394 AC_SUBST([LIBLO_CFLAGS]) 395 395 396 396 AC_SUBST([BIN_PROGRAMS]) branches/streaming-rework/libfreebob/freebob.h
r386 r435 1 1 /* freebob.h 2 * Copyright (C) 2005 Pieter Palmers2 * Copyright (C) 2005,07 Pieter Palmers 3 3 * Copyright (C) 2006 Daniel Wagner 4 4 * … … 41 41 typedef struct freebob_handle* freebob_handle_t; 42 42 43 /*44 * Buffer specification45 */46 typedef struct _freebob_stream_spec freebob_stream_spec_t;47 typedef struct _freebob_stream_info freebob_stream_info_t;48 typedef struct _freebob_connection_spec freebob_connection_spec_t;49 typedef struct _freebob_connection_info freebob_connection_info_t;50 typedef struct _freebob_supported_stream_format_spec freebob_supported_stream_format_spec_t;51 typedef struct _freebob_supported_stream_format_info freebob_supported_stream_format_info_t;52 53 /*54 * Stream specification55 */56 struct _freebob_stream_spec {57 int location;58 int position;59 int format;60 int type;61 int destination_port;62 char name[FREEBOB_MAX_NAME_LEN];63 };64 65 struct _freebob_stream_info {66 int nb_streams;67 freebob_stream_spec_t** streams;68 };69 70 /*71 * Connection specification72 */73 struct _freebob_connection_spec {74 int id;75 int port;76 int node;77 int plug;78 int dimension; /* due to the midi stuff, the dimension isn't equal */79 /* to the number of streams */80 int samplerate; /* this should be equal for all connections when */81 /* using jack. maybe not when using other api's */82 int iso_channel;83 enum freebob_direction direction;84 int is_master;85 freebob_stream_info_t* stream_info;86 };87 88 /*89 * topology info90 */91 struct _freebob_connection_info {92 int direction;93 int nb_connections;94 freebob_connection_spec_t** connections;95 };96 97 /*98 * Supported stream formats99 */100 struct _freebob_supported_stream_format_spec {101 int samplerate;102 int nb_audio_channels;103 int nb_midi_channels;104 };105 106 struct _freebob_supported_stream_format_info {107 int direction;108 int nb_formats;109 freebob_supported_stream_format_spec_t** formats;110 };111 112 113 43 #ifdef __cplusplus 114 44 extern "C" { … … 124 54 freebob_discover_devices( freebob_handle_t freebob_handle, int verbose_level ); 125 55 126 127 freebob_connection_info_t*128 freebob_get_connection_info( freebob_handle_t freebob_handle,129 int node_id,130 enum freebob_direction direction );131 132 freebob_supported_stream_format_info_t*133 freebob_get_supported_stream_format_info( freebob_handle_t freebob_handle,134 int node_id,135 enum freebob_direction direction );136 137 void138 freebob_free_connection_info( freebob_connection_info_t* connection_info );139 void140 freebob_free_connection_spec( freebob_connection_spec_t* connection_spec );141 void142 freebob_free_stream_info( freebob_stream_info_t* stream_info );143 void144 freebob_free_stream_spec( freebob_stream_spec_t* stream_spec );145 void146 freebob_free_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info );147 void148 freebob_free_supported_stream_format_spec( freebob_supported_stream_format_spec_t* stream_spec );149 150 151 152 void153 freebob_print_connection_info( freebob_connection_info_t* connection_info );154 void155 freebob_print_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info );156 157 56 int freebob_node_is_valid_freebob_device(freebob_handle_t fb_handle, int node_id); 158 57 int freebob_get_nb_devices_on_bus(freebob_handle_t fb_handle); … … 161 60 int freebob_set_samplerate(freebob_handle_t freebob_handle, int node_id, int samplerate); 162 61 163 /* debug function */ 164 void 165 freebob_print_xml_description( freebob_handle_t freebob_handle, 166 int node_id, 167 enum freebob_direction direction ); 168 62 /* ABI stuff */ 169 63 const char* 170 64 freebob_get_version(); branches/streaming-rework/libfreebob/freebob_streaming.h
r424 r435 451 451 int freebob_streaming_transfer_capture_buffers(freebob_device_t *dev); 452 452 453 /**454 * Returns the packetizer thread to allow RT enabling by the host.455 *456 * @param dev the freebob device457 *458 * @return the thread.459 */460 pthread_t freebob_streaming_get_packetizer_thread(freebob_device_t *dev);461 462 463 453 #ifdef __cplusplus 464 454 } branches/streaming-rework/libfreebob/Makefile.am
r336 r435 19 19 libfreebobincludedir = $(includedir)/libfreebob 20 20 21 libfreebobinclude_HEADERS = freebob.h freebob_streaming.h xmlparser.h freebob_bounce.h21 libfreebobinclude_HEADERS = freebob.h freebob_streaming.h branches/streaming-rework/src/bebob/bebob_avdevice.cpp
r426 r435 1102 1102 // and how to handle this (pp: here) 1103 1103 channelInfo->m_streamPosition - 1, 1104 channelInfo->m_location ,1104 channelInfo->m_location - 1, 1105 1105 Streaming::AmdtpPortInfo::E_MBLA 1106 1106 ); … … 1115 1115 // and how to handle this (pp: here) 1116 1116 channelInfo->m_streamPosition - 1, 1117 channelInfo->m_location ,1117 channelInfo->m_location - 1, 1118 1118 Streaming::AmdtpPortInfo::E_Midi 1119 1119 ); branches/streaming-rework/src/bebob/bebob_avdevice.h
r426 r435 26 26 #include "libavc/avc_definitions.h" 27 27 #include "libavc/avc_extended_cmd_generic.h" 28 #include "libfreebob/xmlparser.h"29 28 30 29 #include "bebob/bebob_avplug.h" branches/streaming-rework/src/bebob/bebob_avplug.h
r420 r435 28 28 #include "libavc/avc_definitions.h" 29 29 #include "libavc/avc_generic.h" 30 #include "libfreebob/xmlparser.h"31 30 32 31 #include "libutil/serialize.h" … … 130 129 const AvPlugVector& getOutputConnections() const 131 130 { return m_outputConnections; } 132 133 bool addXmlDescription( xmlNodePtr conectionSet );134 bool addXmlDescriptionStreamFormats( xmlNodePtr streamFormats );135 131 136 132 static PlugAddress::EPlugDirection convertPlugDirection( branches/streaming-rework/src/bounce/bounce_avdevice.cpp
r426 r435 162 162 } 163 163 164 #define BOUNCE_NR_OF_CHANNELS 2165 166 164 bool 167 165 BounceDevice::addPortsToProcessor( … … 177 175 178 176 int i=0; 179 for (i=0;i<BOUNCE_N R_OF_CHANNELS;i++) {177 for (i=0;i<BOUNCE_NB_AUDIO_CHANNELS;i++) { 180 178 char *buff; 181 asprintf(&buff,"%s%s_Port%d",id.c_str(),direction==Streaming:: AmdtpAudioPort::E_Playback?"p":"c",i);179 asprintf(&buff,"%s%s_Port%d",id.c_str(),direction==Streaming::Port::E_Playback?"p":"c",i); 182 180 183 181 Streaming::Port *p=NULL; … … 205 203 } 206 204 } 207 208 205 free(buff); 209 206 } 207 208 for (i=0;i<BOUNCE_NB_MIDI_CHANNELS;i++) { 209 char *buff; 210 asprintf(&buff,"%s_Midi%s%d",id.c_str(),direction==Streaming::Port::E_Playback?"Out":"In",i); 211 212 Streaming::Port *p=NULL; 213 p=new Streaming::AmdtpMidiPort( 214 buff, 215 direction, 216 // \todo: streaming backend expects indexing starting from 0 217 // but bebob reports it starting from 1. Decide where 218 // and how to handle this (pp: here) 219 BOUNCE_NB_AUDIO_CHANNELS, 220 i, 221 Streaming::AmdtpPortInfo::E_Midi 222 ); 223 224 if (!p) { 225 debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff); 226 } else { 227 228 if (!processor->addPort(p)) { 229 debugWarning("Could not register port with stream processor\n"); 230 free(buff); 231 return false; 232 } else { 233 debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff); 234 } 235 } 236 free(buff); 210 237 } 211 238 … … 228 255 m_p1394Service->getPort(), 229 256 m_samplerate, 230 BOUNCE_N R_OF_CHANNELS);257 BOUNCE_NB_AUDIO_CHANNELS+(BOUNCE_NB_MIDI_CHANNELS?1:0)); 231 258 232 259 if(!p->init()) { … … 249 276 // we are snooping, so this is receive too. 250 277 p=new Streaming::AmdtpReceiveStreamProcessor( 251 252 253 BOUNCE_NR_OF_CHANNELS);278 m_p1394Service->getPort(), 279 m_samplerate, 280 BOUNCE_NB_AUDIO_CHANNELS+(BOUNCE_NB_MIDI_CHANNELS?1:0)); 254 281 } else { 255 282 p=new Streaming::AmdtpTransmitStreamProcessor( 256 283 m_p1394Service->getPort(), 257 284 m_samplerate, 258 BOUNCE_N R_OF_CHANNELS);285 BOUNCE_NB_AUDIO_CHANNELS+(BOUNCE_NB_MIDI_CHANNELS?1:0)); 259 286 } 260 287 branches/streaming-rework/src/bounce/bounce_avdevice.h
r426 r435 25 25 #include "libavc/avc_definitions.h" 26 26 #include "libavc/avc_extended_cmd_generic.h" 27 #include "libfreebob/xmlparser.h"28 27 29 28 #include "libstreaming/AmdtpStreamProcessor.h" … … 34 33 35 34 #include "iavdevice.h" 36 #include "libfreebob/freebob_bounce.h"37 35 38 36 #include <vector> … … 43 41 #define BOUNCE_REGISTER_RX_ISOCHANNEL 0x14 44 42 #define BOUNCE_INVALID_OFFSET 0xFFFFF00000000000ULL 43 44 #define BOUNCE_NB_AUDIO_CHANNELS 4 45 46 // don't define more than 8 midi channels! 47 #define BOUNCE_NB_MIDI_CHANNELS 2 45 48 46 49 class ConfigRom; branches/streaming-rework/src/bounce/bounce_slave_avdevice.cpp
r426 r435 26 26 * 27 27 */ 28 29 #include "libstreaming/AmdtpSlaveStreamProcessor.h" 30 28 31 #include "libieee1394/configrom.h" 29 32 #include "libieee1394/ieee1394service.h" 30 33 31 34 #include "bounce_slave_avdevice.h" 32 #include "libfreebob/freebob_bounce.h"33 35 34 36 #include <libraw1394/raw1394.h> … … 174 176 bool 175 177 BounceSlaveDevice::prepare() { 176 // snooping does not make sense for a slave device 177 setOption("snoopMode", false); 178 179 // prepare the base class 180 // FIXME: when doing proper discovery this won't work anymore 181 // as it relies on a completely symmetric transmit/receive 182 if(!BounceDevice::prepare()) { 183 debugError("Base class preparation failed\n"); 184 return false; 185 } 186 187 // do any customisations here 188 178 debugOutput(DEBUG_LEVEL_NORMAL, "Preparing BounceSlaveDevice...\n" ); 179 180 // create & add streamprocessors 181 Streaming::StreamProcessor *p; 182 183 p=new Streaming::AmdtpSlaveReceiveStreamProcessor( 184 m_p1394Service->getPort(), 185 m_samplerate, 186 BOUNCE_NB_AUDIO_CHANNELS); 187 188 if(!p->init()) { 189 debugFatal("Could not initialize receive processor!\n"); 190 delete p; 191 return false; 192 } 193 194 if (!addPortsToProcessor(p, 195 Streaming::Port::E_Capture)) { 196 debugFatal("Could not add plug to processor!\n"); 197 delete p; 198 return false; 199 } 200 201 m_receiveProcessors.push_back(p); 202 203 // do the transmit processor 204 p=new Streaming::AmdtpSlaveTransmitStreamProcessor( 205 m_p1394Service->getPort(), 206 m_samplerate, 207 BOUNCE_NB_AUDIO_CHANNELS); 208 209 if(!p->init()) { 210 debugFatal("Could not initialize transmit processor!\n"); 211 delete p; 212 return false; 213 } 214 215 if (!addPortsToProcessor(p, 216 Streaming::Port::E_Playback)) { 217 debugFatal("Could not add plug to processor!\n"); 218 delete p; 219 return false; 220 } 221 m_transmitProcessors.push_back(p); 222 189 223 return true; 190 224 } branches/streaming-rework/src/bounce/bounce_slave_avdevice.h
r426 r435 31 31 #include "debugmodule/debugmodule.h" 32 32 #include "bounce_avdevice.h" 33 34 #define FREEBOB_MAX_NAME_LEN 256 35 36 #define FREEBOB_BOUNCE_SERVER_VENDORNAME "FreeBoB Server" 37 #define FREEBOB_BOUNCE_SERVER_MODELNAME "freebob-server" 38 39 // NOTE: this is currently free, but it is not really allowed to use 40 #define FREEBOB_BOUNCE_SERVER_VENDORID 0x000B0001 41 #define FREEBOB_BOUNCE_SERVER_MODELID 0x000B0001 42 #define FREEBOB_BOUNCE_SERVER_SPECID 0x000B0001 33 43 34 44 namespace Bounce { branches/streaming-rework/src/devicemanager.cpp
r426 r435 67 67 68 68 DeviceManager::DeviceManager() 69 : m_1394Service( 0 ) 69 : OscNode("devicemanager") 70 , m_1394Service( 0 ) 71 , m_oscServer( NULL ) 70 72 { 71 73 addOption(Util::OptionContainer::Option("slaveMode",false)); … … 75 77 DeviceManager::~DeviceManager() 76 78 { 79 if (m_oscServer) { 80 m_oscServer->stop(); 81 delete m_oscServer; 82 } 83 77 84 for ( IAvDeviceVectorIterator it = m_avDevices.begin(); 78 85 it != m_avDevices.end(); … … 100 107 return false; 101 108 } 109 110 m_oscServer = new OSC::OscServer("17820"); 111 112 if (!m_oscServer) { 113 debugFatal("failed to create osc server\n"); 114 delete m_1394Service; 115 m_1394Service = 0; 116 return false; 117 } 118 119 if (!m_oscServer->init()) { 120 debugFatal("failed to init osc server\n"); 121 delete m_oscServer; 122 m_oscServer = NULL; 123 delete m_1394Service; 124 m_1394Service = 0; 125 return false; 126 } 127 128 if (!m_oscServer->registerAtRootNode(this)) { 129 debugFatal("failed to register devicemanager at server\n"); 130 delete m_oscServer; 131 m_oscServer = NULL; 132 delete m_1394Service; 133 m_1394Service = 0; 134 return false; 135 } 136 137 if (!m_oscServer->start()) { 138 debugFatal("failed to start osc server\n"); 139 delete m_oscServer; 140 m_oscServer = NULL; 141 delete m_1394Service; 142 m_1394Service = 0; 143 return false; 144 } 102 145 103 146 return true; … … 123 166 ++it ) 124 167 { 168 if (!removeChildOscNode(*it)) { 169 debugWarning("failed to unregister AvDevice from OSC server\n"); 170 } 125 171 delete *it; 126 172 } … … 190 236 191 237 m_avDevices.push_back( avDevice ); 238 239 if (!addChildOscNode(avDevice)) { 240 debugWarning("failed to register AvDevice at OSC server\n"); 241 } 242 192 243 } 193 244 } … … 405 456 } 406 457 407 }408 409 xmlDocPtr410 DeviceManager::getXmlDescription()411 {412 xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" );413 if ( !doc ) {414 debugError( "Couldn't create new xml doc\n" );415 return 0;416 }417 418 xmlNodePtr rootNode = xmlNewNode( 0, BAD_CAST "FreeBoBConnectionInfo" );419 if ( !rootNode ) {420 debugError( "Couldn't create root node\n" );421 xmlFreeDoc( doc );422 xmlCleanupParser();423 return 0;424 }425 xmlDocSetRootElement( doc, rootNode );426 427 for ( IAvDeviceVectorIterator it = m_avDevices.begin();428 it != m_avDevices.end();429 ++it )430 {431 IAvDevice* avDevice = *it;432 433 xmlNodePtr deviceNode = xmlNewChild( rootNode, 0,434 BAD_CAST "Device", 0 );435 if ( !deviceNode ) {436 debugError( "Couldn't create device node\n" );437 xmlFreeDoc( doc );438 xmlCleanupParser();439 return 0;440 }441 442 char* result;443 asprintf( &result, "%d", avDevice->getConfigRom().getNodeId() );444 if ( !xmlNewChild( deviceNode, 0,445 BAD_CAST "NodeId", BAD_CAST result ) )446 {447 debugError( "Couldn't create 'NodeId' node" );448 free(result);449 return 0;450 }451 free( result );452 453 std::string res = "Connection Information for "454 + avDevice->getConfigRom().getVendorName()455 +", "456 + avDevice->getConfigRom().getModelName()457 + " configuration";458 if ( !xmlNewChild( deviceNode,459 0,460 BAD_CAST "Comment",461 BAD_CAST res.c_str() ) ) {462 debugError( "Couldn't create comment node\n" );463 xmlFreeDoc( doc );464 xmlCleanupParser();465 free(result);466 return 0;467 }468 469 res = avDevice->getConfigRom().getVendorName();470 471 if ( !xmlNewChild( deviceNode,472 0,473 BAD_CAST "Vendor",474 BAD_CAST res.c_str() ) ) {475 debugError( "Couldn't create vendor node\n" );476 xmlFreeDoc( doc );477 xmlCleanupParser();478 free(result);479 return 0;480 }481 482 res = avDevice->getConfigRom().getModelName();483 484 if ( !xmlNewChild( deviceNode,485 0,486 BAD_CAST "Model",487 BAD_CAST res.c_str() ) ) {488 debugError( "Couldn't create model node\n" );489 xmlFreeDoc( doc );490 xmlCleanupParser();491 free(result);492 return 0;493 }494 495 asprintf( &result, "%08x%08x",496 ( quadlet_t )( avDevice->getConfigRom().getGuid() >> 32 ),497 ( quadlet_t )( avDevice->getConfigRom().getGuid() & 0xfffffff ) );498 if ( !xmlNewChild( deviceNode, 0,499 BAD_CAST "GUID", BAD_CAST result ) ) {500 debugError( "Couldn't create 'GUID' node\n" );501 xmlFreeDoc( doc );502 xmlCleanupParser();503 504 free(result);505 return 0;506 }507 free( result );508 509 510 if ( !avDevice->addXmlDescription( deviceNode ) ) {511 debugError( "Adding XML description failed\n" );512 xmlFreeDoc( doc );513 xmlCleanupParser();514 free(result);515 return 0;516 }517 518 }519 520 return doc;521 458 } 522 459 branches/streaming-rework/src/devicemanager.h
r426 r435 24 24 #include "debugmodule/debugmodule.h" 25 25 26 #include "libfreebob/xmlparser.h" 26 #include "libieee1394/configrom.h" 27 #include "libieee1394/ieee1394service.h" 28 27 29 #include "libutil/OptionContainer.h" 30 #include "libosc/OscServer.h" 31 #include "libosc/OscNode.h" 28 32 29 33 #include <glibmm/ustring.h> … … 40 44 typedef std::vector< IAvDevice* >::iterator IAvDeviceVectorIterator; 41 45 42 class ConfigRom;43 44 45 class DeviceManager : public Util::OptionContainer{46 46 class DeviceManager 47 : public Util::OptionContainer, 48 public OSC::OscNode 49 { 50 public: 47 51 DeviceManager(); 48 52 ~DeviceManager(); … … 61 65 unsigned int getAvDeviceCount(); 62 66 63 xmlDocPtr getXmlDescription();64 65 67 bool saveCache( Glib::ustring fileName ); 66 68 bool loadCache( Glib::ustring fileName ); … … 76 78 Ieee1394Service* m_1394Service; 77 79 IAvDeviceVector m_avDevices; 80 81 OSC::OscServer* m_oscServer; 78 82 79 83 DECLARE_DEBUG_MODULE; branches/streaming-rework/src/freebob.cpp
r420 r435 23 23 24 24 #include "libfreebob/freebob.h" 25 #include "libfreebob/xmlparser.h"26 25 27 26 #include "debugmodule/debugmodule.h" … … 35 34 #include <stdlib.h> 36 35 #include <string.h> 37 #include <libxml/xmlmemory.h>38 #include <libxml/parser.h>39 36 40 37 DECLARE_GLOBAL_DEBUG_MODULE; … … 109 106 } 110 107 111 freebob_connection_info_t*112 freebob_get_connection_info( freebob_handle_t freebob_handle,113 int node_id,114 enum freebob_direction direction )115 {116 xmlDocPtr doc;117 doc = freebob_handle->m_deviceManager->getXmlDescription();118 if ( !doc ) {119 debugFatal( "Could not get XML description\n" );120 return 0;121 }122 123 return freebob_xmlparse_get_connection_info( doc, node_id, direction );124 }125 126 freebob_supported_stream_format_info_t*127 freebob_get_supported_stream_format_info( freebob_handle_t freebob_handle,128 int node_id,129 enum freebob_direction direction )130 {131 xmlDocPtr doc;132 doc = freebob_handle->m_deviceManager->getXmlDescription();133 if ( !doc ) {134 debugFatal( "Could not get XML description\n" );135 return 0;136 }137 138 return freebob_xmlparse_get_stream_formats( doc, node_id, direction );139 }140 141 108 int 142 109 freebob_node_is_valid_freebob_device( freebob_handle_t freebob_handle, int node_id ) … … 169 136 } 170 137 171 void172 freebob_free_connection_info( freebob_connection_info_t* connection_info )173 {174 if ( !connection_info ) {175 return;176 }177 178 for ( int i = 0; i < connection_info->nb_connections; ++i ) {179 freebob_free_connection_spec( connection_info->connections[i] );180 }181 182 free( connection_info->connections );183 free( connection_info );184 }185 186 void187 freebob_free_connection_spec( freebob_connection_spec_t* connection_spec )188 {189 if ( !connection_spec ) {190 return;191 }192 193 freebob_free_stream_info( connection_spec->stream_info );194 free( connection_spec );195 }196 197 void freebob_free_stream_info( freebob_stream_info_t* stream_info )198 {199 if ( !stream_info ) {200 return;201 }202 203 for ( int i = 0; i < stream_info->nb_streams; ++i ) {204 freebob_free_stream_spec( stream_info->streams[i] );205 }206 207 free(stream_info->streams);208 free(stream_info);209 }210 211 void freebob_free_stream_spec( freebob_stream_spec_t* stream_spec )212 {213 if ( !stream_spec ) {214 return;215 }216 217 free( stream_spec );218 }219 220 void221 freebob_free_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info )222 {223 if ( !stream_info ) {224 return;225 }226 227 for ( int i = 0; i < stream_info->nb_formats; ++i ) {228 freebob_free_supported_stream_format_spec( stream_info->formats[i] );229 }230 231 free(stream_info->formats);232 free(stream_info);233 }234 235 void236 freebob_free_supported_stream_format_spec( freebob_supported_stream_format_spec_t* stream_spec )237 {238 if ( !stream_spec ) {239 return;240 }241 242 free( stream_spec );243 }244 245 void246 freebob_print_connection_info( freebob_connection_info_t* connection_info )247 {248 if ( !connection_info ) {249 fprintf( stderr, "connection_info==NULL\n" );250 return;251 }252 253 printf( "Direction: %d (%s)\n\n", connection_info->direction,254 connection_info->direction? "playback" : "capture" );255 256 puts( "Connection Info" );257 puts( "===============\n" );258 259 printf("Number of connections: %d\n\n",260 connection_info->nb_connections );261 262 for ( int i = 0; i < connection_info->nb_connections; ++i) {263 freebob_connection_spec_t* connection_spec264 = connection_info->connections[i];265 266 267 if ( connection_spec ) {268 printf( " Connection %2d\n", i );269 printf( " -------------\n" );270 printf( " [%2d] Id: %d\n", i, connection_spec->id );271 printf( " [%2d] Port: %d\n", i, connection_spec->port );272 printf( " [%2d] Node: %d\n", i, connection_spec->node );273 printf( " [%2d] Plug: %d\n", i, connection_spec->plug );274 printf( " [%2d] Dimension: %d\n", i, connection_spec->dimension );275 printf( " [%2d] Samplerate: %d\n", i, connection_spec->samplerate );276 printf( " [%2d] IsoChannel: %d\n", i, connection_spec->iso_channel );277 printf( " [%2d] IsMaster: %d\n", i, connection_spec->is_master );278 279 if ( connection_info->connections[i]->stream_info ) {280 printf(" [%2d] Number of stream infos: %d\n\n",281 i, connection_spec->stream_info->nb_streams );282 283 printf(" StreamId Position Location Format Type DPort Name\n");284 printf(" --------------------------------------------------\n");285 286 for ( int j = 0;287 j < connection_spec->stream_info->nb_streams;288 ++j )289 {290 freebob_stream_spec_t* stream_spec291 = connection_spec->stream_info->streams[j];292 293 printf(" [%2d]:[%2d] "294 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x %s\n",295 i, j,296 stream_spec->position,297 stream_spec->location,298 stream_spec->format,299 stream_spec->type,300 stream_spec->destination_port,301 stream_spec->name );302 }303 }304 }305 printf( "\n" );306 }307 308 return;309 }310 311 void312 freebob_print_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info )313 {314 if ( !stream_info ) {315 fprintf( stderr, "stream_info==NULL\n" );316 return;317 }318 319 printf( "Direction: %d (%s)\n\n", stream_info->direction,320 stream_info->direction? "playback" : "capture" );321 322 printf( "Samplerate AudioChannels MidiChannels\n" );323 printf( "-------------------------------------\n" );324 for ( int i = 0; i < stream_info->nb_formats; ++i) {325 freebob_supported_stream_format_spec_t* format_spec326 = stream_info->formats[i];327 328 if ( format_spec ) {329 printf( "%05d %02d %02d\n",330 format_spec->samplerate,331 format_spec->nb_audio_channels,332 format_spec->nb_midi_channels );333 }334 }335 336 return;337 }338 339 /* debug function */340 void341 freebob_print_xml_description( freebob_handle_t freebob_handle,342 int node_id,343 enum freebob_direction direction )344 {345 xmlDocPtr doc;346 doc = freebob_handle->m_deviceManager->getXmlDescription();347 if ( !doc ) {348 debugFatal( "Could not get XML description\n" );349 return;350 }351 352 xmlChar* xmlbuff;353 int buffersize;354 xmlDocDumpFormatMemory( doc, &xmlbuff, &buffersize, 1 );355 356 printf("%s\n",(char *)xmlbuff);357 358 xmlFree(xmlbuff);359 xmlFree(doc);360 return;361 }362 363 138 void freebob_sleep_after_avc_command( int time ) 364 139 { branches/streaming-rework/src/freebob_streaming.cpp
r424 r435 33 33 */ 34 34 35 #include "libfreebob/freebob.h" 35 36 #include "libfreebob/freebob_streaming.h" 36 37 #include "devicemanager.h" … … 53 54 54 55 struct _freebob_device 55 { 56 57 58 59 60 56 { 57 DeviceManager * m_deviceManager; 58 StreamProcessorManager *processorManager; 59 60 freebob_options_t options; 61 freebob_device_info_t device_info; 61 62 }; 62 63 63 64 freebob_device_t *freebob_streaming_init (freebob_device_info_t *device_info, freebob_options_t options) { 64 unsigned int i=0; 65 66 struct _freebob_device *dev = new struct _freebob_device; 67 68 debugFatal("%s built %s %s\n", freebob_get_version(), __DATE__, __TIME__); 69 70 if(!dev) { 71 debugFatal( "Could not allocate streaming device\n" ); 72 return 0; 73 } 74 75 memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); 76 memcpy((void *)&dev->device_info, (void *)device_info, sizeof(dev->device_info)); 77 78 dev->m_deviceManager = new DeviceManager(); 79 if ( !dev->m_deviceManager ) { 80 debugFatal( "Could not allocate device manager\n" ); 81 delete dev; 82 return 0; 83 } 84 if ( !dev->m_deviceManager->initialize( dev->options.port ) ) { 85 debugFatal( "Could not initialize device manager\n" ); 86 delete dev->m_deviceManager; 87 delete dev; 88 return 0; 89 } 90 91 // create a processor manager to manage the actual stream 92 // processors 93 dev->processorManager = new StreamProcessorManager(dev->options.period_size,dev->options.nb_buffers); 94 if(!dev->processorManager) { 95 debugFatal("Could not create StreamProcessorManager\n"); 96 delete dev->m_deviceManager; 97 delete dev; 98 return 0; 99 } 100 101 dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 102 103 dev->processorManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 104 if(!dev->processorManager->init()) { 105 debugFatal("Could not init StreamProcessorManager\n"); 65 unsigned int i=0; 66 67 struct _freebob_device *dev = new struct _freebob_device; 68 69 debugFatal("%s built %s %s\n", freebob_get_version(), __DATE__, __TIME__); 70 71 if(!dev) { 72 debugFatal( "Could not allocate streaming device\n" ); 73 return 0; 74 } 75 76 memcpy((void *)&dev->options, (void *)&options, sizeof(dev->options)); 77 memcpy((void *)&dev->device_info, (void *)device_info, sizeof(dev->device_info)); 78 79 dev->m_deviceManager = new DeviceManager(); 80 if ( !dev->m_deviceManager ) { 81 debugFatal( "Could not allocate device manager\n" ); 82 delete dev; 83 return 0; 84 } 85 if ( !dev->m_deviceManager->initialize( dev->options.port ) ) { 86 debugFatal( "Could not initialize device manager\n" ); 87 delete dev->m_deviceManager; 88 delete dev; 89 return 0; 90 } 91 92 // create a processor manager to manage the actual stream 93 // processors 94 dev->processorManager = new StreamProcessorManager(dev->options.period_size,dev->options.nb_buffers); 95 if(!dev->processorManager) { 96 debugFatal("Could not create StreamProcessorManager\n"); 97 delete dev->m_deviceManager; 98 delete dev; 99 return 0; 100 } 101 102 dev->processorManager->setThreadParameters(dev->options.realtime, dev->options.packetizer_priority); 103 104 dev->processorManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 105 if(!dev->processorManager->init()) { 106 debugFatal("Could not init StreamProcessorManager\n"); 107 delete dev->processorManager; 108 delete dev->m_deviceManager; 109 delete dev; 110 return 0; 111 } 112 113 // set slave mode option 114 bool slaveMode=(dev->options.slave_mode != 0); 115 debugOutput(DEBUG_LEVEL_VERBOSE, "setting slave mode to %d\n", slaveMode); 116 if(!dev->m_deviceManager->setOption("slaveMode", slaveMode)) { 117 debugWarning("Failed to set slave mode option\n"); 118 } 119 // set snoop mode option 120 bool snoopMode=(dev->options.snoop_mode != 0); 121 debugOutput(DEBUG_LEVEL_VERBOSE, "setting snoop mode to %d\n", snoopMode); 122 if(!dev->m_deviceManager->setOption("snoopMode", snoopMode)) { 123 debugWarning("Failed to set snoop mode option\n"); 124 } 125 126 // discover the devices on the bus 127 if(!dev->m_deviceManager->discover(DEBUG_LEVEL_NORMAL)) { 128 debugFatal("Could not discover devices\n"); 129 delete dev->processorManager; 130 delete dev->m_deviceManager; 131 delete dev; 132 return 0; 133 } 134 135 // are there devices on the bus? 136 if(dev->m_deviceManager->getAvDeviceCount()==0) { 137 debugFatal("There are no devices on the bus\n"); 138 delete dev->processorManager; 139 delete dev->m_deviceManager; 140 delete dev; 141 return 0; 142 } 143 144 // iterate over the found devices 145 // add the stream processors of the devices to the managers 146 for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 147 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 148 assert(device); 149 150 debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); 151 152 if (!device->lock()) { 153 debugWarning("Could not lock device, skipping device (%p)!\n", device); 154 continue; 155 } 156 157 debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", 158 dev->options.sample_rate, device); 159 160 // Set the device's sampling rate to that requested 161 // FIXME: does this really belong here? If so we need to handle errors. 162 if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 163 debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", 164 dev->options.sample_rate, device); 165 166 // try again: 167 if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 106 168 delete dev->processorManager; 107 169 delete dev->m_deviceManager; 108 170 delete dev; 171 debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); 109 172 return 0; 110 }111 112 // set slave mode option113 bool slaveMode=(dev->options.slave_mode != 0);114 debugOutput(DEBUG_LEVEL_VERBOSE, "setting slave mode to %d\n", slaveMode);115 if(!dev->m_deviceManager->setOption("slaveMode", slaveMode)) {116 debugWarning("Failed to set slave mode option\n");117 }118 // set snoop mode option119 bool snoopMode=(dev->options.snoop_mode != 0);120 debugOutput(DEBUG_LEVEL_VERBOSE, "setting snoop mode to %d\n", snoopMode);121 if(!dev->m_deviceManager->setOption("snoopMode", snoopMode)) {122 debugWarning("Failed to set snoop mode option\n");123 }124 125 // discover the devices on the bus126 if(!dev->m_deviceManager->discover(DEBUG_LEVEL_NORMAL)) {127 debugFatal("Could not discover devices\n");128 delete dev->processorManager;129 delete dev->m_deviceManager;130 delete dev;131 return 0;132 }133 134 // are there devices on the bus?135 if(dev->m_deviceManager->getAvDeviceCount()==0) {136 debugFatal("There are no devices on the bus\n");137 delete dev->processorManager;138 delete dev->m_deviceManager;139 delete dev;140 return 0;141 }142 143 // iterate over the found devices144 // add the stream processors of the devices to the managers145 for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) {146 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i);147 assert(device);148 149 debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device);150 151 if (!device->lock()) {152 debugWarning("Could not lock device, skipping device (%p)!\n", device);153 continue;154 173 } 155 156 debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", 157 dev->options.sample_rate, device); 158 159 // Set the device's sampling rate to that requested 160 // FIXME: does this really belong here? If so we need to handle errors. 161 if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 162 debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", 163 dev->options.sample_rate, device); 164 165 // try again: 166 if (!device->setSamplingFrequency(parseSampleRate(dev->options.sample_rate))) { 167 delete dev->processorManager; 168 delete dev->m_deviceManager; 169 delete dev; 170 debugFatal("Could not set sampling frequency to %d\n",dev->options.sample_rate); 171 return 0; 172 } 174 } 175 176 // prepare the device 177 device->prepare(); 178 179 int j=0; 180 for(j=0; j<device->getStreamCount();j++) { 181 StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); 182 debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); 183 if (!dev->processorManager->registerProcessor(streamproc)) { 184 debugWarning("Could not register stream processor (%p) with the Processor manager\n",streamproc); 173 185 } 174 175 // prepare the device 176 device->prepare(); 177 178 int j=0; 179 for(j=0; j<device->getStreamCount();j++) { 180 StreamProcessor *streamproc=device->getStreamProcessorByIndex(j); 181 debugOutput(DEBUG_LEVEL_VERBOSE, "Registering stream processor %d of device %d with processormanager\n",j,i); 182 if (!dev->processorManager->registerProcessor(streamproc)) { 183 debugWarning("Could not register stream processor (%p) with the Processor manager\n",streamproc); 184 } 185 } 186 } 187 188 // set the sync source 189 if (!dev->processorManager->setSyncSource(dev->m_deviceManager->getSyncSource())) { 190 debugWarning("Could not set processorManager sync source (%p)\n", 191 dev->m_deviceManager->getSyncSource()); 192 } 193 194 // we are ready! 195 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); 196 return dev; 186 } 187 } 188 189 // set the sync source 190 if (!dev->processorManager->setSyncSource(dev->m_deviceManager->getSyncSource())) { 191 debugWarning("Could not set processorManager sync source (%p)\n", 192 dev->m_deviceManager->getSyncSource()); 193 } 194 195 // we are ready! 196 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n\n"); 197 return dev; 197 198 198 199 } … … 264 265 265 266 int freebob_streaming_stop(freebob_device_t *dev) { 266 unsigned int i; 267 debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); 268 269 dev->processorManager->stop(); 270 271 // create the connections for all devices 272 // iterate over the found devices 273 // add the stream processors of the devices to the managers 274 for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 275 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 276 assert(device); 277 278 int j=0; 279 for(j=0; j<device->getStreamCount();j++) { 280 debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); 281 // stop the stream 282 // start the stream 283 if (!device->stopStreamByIndex(j)) { 284 debugWarning("Could not stop stream %d of device %d\n",j,i); 285 continue; 286 } 267 unsigned int i; 268 debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Stop -------------\n"); 269 270 dev->processorManager->stop(); 271 272 // create the connections for all devices 273 // iterate over the found devices 274 // add the stream processors of the devices to the managers 275 for(i=0;i<dev->m_deviceManager->getAvDeviceCount();i++) { 276 IAvDevice *device=dev->m_deviceManager->getAvDeviceByIndex(i); 277 assert(device); 278 279 int j=0; 280 for(j=0; j<device->getStreamCount();j++) { 281 debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %d\n",j,i); 282 // stop the stream 283 // start the stream 284 if (!device->stopStreamByIndex(j)) { 285 debugWarning("Could not stop stream %d of device %d\n",j,i); 286 continue; 287 287 } 288 288 } 289 290 return 0; 289 } 290 291 return 0; 291 292 } 292 293 293 294 int freebob_streaming_reset(freebob_device_t *dev) { 294 295 296 //dev->processorManager->reset();297 298 295 debugOutput(DEBUG_LEVEL_VERBOSE,"------------- Reset -------------\n"); 296 297 // dev->processorManager->reset(); 298 299 return 0; 299 300 } 300 301 301 302 int freebob_streaming_wait(freebob_device_t *dev) { 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 303 static int periods=0; 304 static int periods_print=0; 305 static int xruns=0; 306 307 periods++; 308 if(periods>periods_print) { 309 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\nfreebob_streaming_wait\n"); 310 debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); 311 debugOutputShort(DEBUG_LEVEL_VERBOSE, "Xruns: %d\n",xruns); 312 debugOutputShort(DEBUG_LEVEL_VERBOSE, "============================================\n"); 313 dev->processorManager->dumpInfo(); 314 debugOutputShort(DEBUG_LEVEL_VERBOSE, "\n"); 315 periods_print+=100; 316 } 317 318 if(dev->processorManager->waitForPeriod()) { 319 return dev->options.period_size; 320 } else { 321 debugWarning("XRUN detected\n"); 322 323 // do xrun recovery 324 dev->processorManager->handleXrun(); 325 xruns++; 326 return -1; 327 } 327 328 } 328 329 329 330 int freebob_streaming_transfer_capture_buffers(freebob_device_t *dev) { 330 331 return dev->processorManager->transfer(StreamProcessor::E_Receive); 331 332 } 332 333 333 334 int freebob_streaming_transfer_playback_buffers(freebob_device_t *dev) { 334 335 return dev->processorManager->transfer(StreamProcessor::E_Transmit); 335 336 } 336 337 337 338 int freebob_streaming_transfer_buffers(freebob_device_t *dev) { 338 339 return dev->processorManager->transfer(); 339 340 } 340 341 341 342 342 343 int freebob_streaming_write(freebob_device_t *dev, int i, freebob_sample_t *buffer, int nsamples) { 343 // debugFatal("Not implemented\n"); 344 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 345 // use an assert here performancewise, 346 // it should already have failed before, if not correct 347 assert(p); 348 349 return p->writeEvents((void *)buffer, nsamples); 344 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 345 // use an assert here performancewise, 346 // it should already have failed before, if not correct 347 assert(p); 348 349 return p->writeEvents((void *)buffer, nsamples); 350 350 } 351 351 352 352 int freebob_streaming_read(freebob_device_t *dev, int i, freebob_sample_t *buffer, int nsamples) { 353 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 354 // use an assert here performancewise, 355 // it should already have failed before, if not correct 356 assert(p); 357 358 return p->readEvents((void *)buffer, nsamples); 359 } 360 361 pthread_t freebob_streaming_get_packetizer_thread(freebob_device_t *dev) { 362 // debugFatal("Not implemented\n"); 363 return 0; 364 } 365 353 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 354 // use an assert here performancewise, 355 // it should already have failed before, if not correct 356 assert(p); 357 358 return p->readEvents((void *)buffer, nsamples); 359 } 366 360 367 361 int freebob_streaming_get_nb_capture_streams(freebob_device_t *dev) { 368 362 return dev->processorManager->getPortCount(Port::E_Capture); 369 363 } 370 364 371 365 int freebob_streaming_get_nb_playback_streams(freebob_device_t *dev) { 372 366 return dev->processorManager->getPortCount(Port::E_Playback); 373 367 } 374 368 375 369 int freebob_streaming_get_capture_stream_name(freebob_device_t *dev, int i, char* buffer, size_t buffersize) { 376 377 378 379 380 381 382 383 384 385 386 370 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 371 if(!p) { 372 debugWarning("Could not get capture port at index %d\n",i); 373 return -1; 374 } 375 376 std::string name=p->getName(); 377 if (!strncpy(buffer, name.c_str(), buffersize)) { 378 debugWarning("Could not copy name\n"); 379 return -1; 380 } else return 0; 387 381 } 388 382 389 383 int freebob_streaming_get_playback_stream_name(freebob_device_t *dev, int i, char* buffer, size_t buffersize) { 390 391 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 392 if(!p) { 393 debugWarning("Could not get playback port at index %d\n",i); 394 return -1; 395 } 396 397 std::string name=p->getName(); 398 if (!strncpy(buffer, name.c_str(), buffersize)) { 399 debugWarning("Could not copy name\n"); 400 return -1; 401 } else return 0; 384 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 385 if(!p) { 386 debugWarning("Could not get playback port at index %d\n",i); 387 return -1; 388 } 389 390 std::string name=p->getName(); 391 if (!strncpy(buffer, name.c_str(), buffersize)) { 392 debugWarning("Could not copy name\n"); 393 return -1; 394 } else return 0; 402 395 } 403 396 404 397 freebob_streaming_stream_type freebob_streaming_get_capture_stream_type(freebob_device_t *dev, int i) { 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 398 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Capture); 399 if(!p) { 400 debugWarning("Could not get capture port at index %d\n",i); 401 return freebob_stream_type_invalid; 402 } 403 switch(p->getPortType()) { 404 case Port::E_Audio: 405 return freebob_stream_type_audio; 406 case Port::E_Midi: 407 return freebob_stream_type_midi; 408 case Port::E_Control: 409 return freebob_stream_type_control; 410 default: 411 return freebob_stream_type_unknown; 412 } 420 413 } 421 414 422 415 freebob_streaming_stream_type freebob_streaming_get_playback_stream_type(freebob_device_t *dev, int i) { 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 416 Port *p=dev->processorManager->getPortByIndex(i, Port::E_Playback); 417 if(!p) { 418 debugWarning("Could not get playback port at index %d\n",i); 419 return freebob_stream_type_invalid; 420 } 421 switch(p->getPortType()) { 422 case Port::E_Audio: 423 return freebob_stream_type_audio; 424 case Port::E_Midi: 425 return freebob_stream_type_midi; 426 case Port::E_Control: 427 return freebob_stream_type_control; 428 default: 429 return freebob_stream_type_unknown; 430 } 438 431 } 439 432 440 433 int freebob_streaming_set_stream_buffer_type(freebob_device_t *dev, int i, 441 442 443 444 445 446 447 448 449 450 451 434 freebob_streaming_buffer_type t, enum Port::E_Direction direction) { 435 436 Port *p=dev->processorManager->getPortByIndex(i, direction); 437 if(!p) { 438 debugWarning("Could not get %s port at index %d\n", 439 (direction==Port::E_Playback?"Playback":"Capture"),i); 440 return -1; 441 } 442 443 switch(t) { 444 case freebob_buffer_type_int24: 452 445 if (!p->setDataType(Port::E_Int24)) { 453 446 debugWarning("%s: Could not set data type to Int24\n",p->getName().c_str()); … … 459 452 } 460 453 break; 461 454 case freebob_buffer_type_float: 462 455 if (!p->setDataType(Port::E_Float)) { 463 456 debugWarning("%s: Could not set data type to Float\n",p->getName().c_str()); … … 469 462 } 470 463 break; 471 464 case freebob_buffer_type_midi: 472 465 if (!p->setDataType(Port::E_MidiEvent)) { 473 466 debugWarning("%s: Could not set data type to MidiEvent\n",p->getName().c_str()); … … 479 472 } 480 473 break; 481 482 debugWarning("%s: Unsupported buffer type\n",p->getName().c_str());483 return -1;484 474 default: 475 debugWarning("%s: Unsupported buffer type\n",p->getName().c_str()); 476 return -1; 477 } 485 478 return 0; 486 479 … … 496 489 497 490 int freebob_streaming_stream_onoff(freebob_device_t *dev, int i, 498 499 500 501 502 503 504 505 491 int on, enum Port::E_Direction direction) { 492 Port *p=dev->processorManager->getPortByIndex(i, direction); 493 if(!p) { 494 debugWarning("Could not get %s port at index %d\n", 495 (direction==Port::E_Playback?"Playback":"Capture"),i); 496 return -1; 497 } 498 if(on) { 506 499 p->enable(); 507 500 } else { 508 501 p->disable(); 509 510 502 } 503 return 0; 511 504 } 512 505 branches/streaming-rework/src/iavdevice.cpp
r426 r435 33 33 Ieee1394Service& ieee1394service, 34 34 int nodeId ) 35 : m_pConfigRom( configRom ) 35 : OscNode() 36 , m_pConfigRom( configRom ) 36 37 , m_p1394Service( &ieee1394service ) 37 38 , m_verboseLevel( DEBUG_LEVEL_NORMAL ) … … 39 40 { 40 41 addOption(Util::OptionContainer::Option("id",std::string("dev?"))); 41 42 43 std::ostringstream nodestr; 44 nodestr << "node" << nodeId; 45 setOscBase(nodestr.str()); 46 ConfigRom& c = getConfigRom(); 47 48 addChildOscNode(&c); 42 49 } 43 50 branches/streaming-rework/src/iavdevice.h
r426 r435 23 23 24 24 #include "libavc/avc_definitions.h" 25 #include "libfreebob/xmlparser.h"26 25 #include "libutil/OptionContainer.h" 26 #include "libosc/OscNode.h" 27 27 28 28 class ConfigRom; … … 39 39 40 40 */ 41 class IAvDevice : public Util::OptionContainer { 41 class IAvDevice 42 : public Util::OptionContainer, 43 public OSC::OscNode 44 { 42 45 public: 43 46 IAvDevice( std::auto_ptr< ConfigRom >( configRom ), … … 100 103 101 104 /** 102 * @brief Constructs an XML description of the device [obsolete]103 *104 * this is a leftover from v1.0 and isn't used105 * just provide an empty implementation that returns true106 * untill it is removed107 *108 * @param deviceNode109 * @return true if successful, false if not110 */111 bool addXmlDescription( xmlNodePtr deviceNode ) {return true;};112 113 /**114 105 * @brief Outputs the device configuration to stderr/stdout [debug helper] 115 106 * branches/streaming-rework/src/libieee1394/configrom.cpp
r413 r435 56 56 57 57 ConfigRom::ConfigRom( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId ) 58 : m_1394Service( &ieee1394service ) 58 : OscNode("ConfigRom") 59 , m_1394Service( &ieee1394service ) 59 60 , m_nodeId( nodeId ) 60 61 , m_avcDevice( false ) … … 82 83 83 84 ConfigRom::ConfigRom() 84 : m_1394Service( 0 ) 85 : OscNode("ConfigRom") 86 , m_1394Service( 0 ) 85 87 , m_nodeId( -1 ) 86 88 , m_avcDevice( false ) … … 572 574 return true; 573 575 } 576 577 OSC::OscResponse 578 ConfigRom::processOscMessage(OSC::OscMessage *m) { 579 OSC::OscResponse r=OSC::OscResponse(OSC::OscResponse::eUnhandled); 580 581 unsigned int nbArgs=m->nbArguments(); 582 if (nbArgs>=1) { 583 OSC::OscArgument arg0=m->getArgument(0); 584 if(arg0.isString()) { // commands 585 string cmd=arg0.getString(); 586 587 debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) CMD? %s\n", this, cmd.c_str()); 588 if(cmd == "params") { 589 debugOutput( DEBUG_LEVEL_VERBOSE, "Listing node children...\n"); 590 OSC::OscMessage& rm=r.getMessage(); 591 rm.addArgument("GUID"); 592 rm.addArgument("VendorName"); 593 rm.addArgument("ModelName"); 594 r.setType(OSC::OscResponse::eMessage); 595 } 596 if(cmd == "get") { 597 if(nbArgs != 2) { 598 debugError("Erronous get command received, wrong nb of arguments\n"); 599 m->print(); 600 } else { 601 OSC::OscArgument arg1=m->getArgument(1); 602 if(arg1.isString()) { // commands 603 string target=arg1.getString(); 604 OSC::OscMessage& rm=r.getMessage(); 605 if(target == "GUID") { 606 // FIXME: this will only return the lower 32 bits 607 rm.addArgument((int64_t)getGuid()); 608 } else if(target == "VendorName") { 609 rm.addArgument(getVendorName()); 610 } else if(target == "ModelName") { 611 rm.addArgument(getModelName()); 612 } else { 613 debugError("Erronous get command received, non-existant target\n"); 614 m->print(); 615 } 616 r.setType(OSC::OscResponse::eMessage); 617 } else { 618 debugError("Erronous get command received, wrong argument type\n"); 619 m->print(); 620 } 621 } 622 } 623 } 624 } 625 626 return r; 627 628 } branches/streaming-rework/src/libieee1394/configrom.h
r413 r435 28 28 #include "debugmodule/debugmodule.h" 29 29 30 #include "libosc/OscNode.h" 31 30 32 #include <string> 31 33 32 34 class Ieee1394Service; 33 35 34 class ConfigRom { 36 class ConfigRom 37 : public OSC::OscNode 38 { 35 39 public: 36 40 ConfigRom( Ieee1394Service& ieee1394service, fb_nodeid_t nodeId ); … … 110 114 struct csr1212_csr* m_csr; 111 115 116 protected: // OSC handling 117 OSC::OscResponse processOscMessage(OSC::OscMessage *m); 118 112 119 private: 113 120 ConfigRom( const ConfigRom& ); // do not allow copy ctor branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp
r424 r435 86 86 87 87 struct iec61883_packet *packet = (struct iec61883_packet *) data; 88 if (cycle<0) return RAW1394_ISO_OK; 88 89 89 90 m_last_cycle=cycle; … … 145 146 146 147 uint64_t ts_head, fc; 147 if (!m_disabled && m_is_disabled) { 148 // this means that we are trying to enable 149 if ((unsigned int)cycle == m_cycle_to_enable_at) { 148 if (!m_disabled && m_is_disabled) { // this means that we are trying to enable 149 // check if we are on or past the enable point 150 int cycles_past_enable=diffCycles(cycle, m_cycle_to_enable_at); 151 152 if (cycles_past_enable >= 0) { 150 153 m_is_disabled=false; 151 154 … … 170 173 171 174 ts_head = substractTicks(ts_head, TICKS_PER_CYCLE); 175 176 // account for the number of cycles we are too late to enable 177 ts_head = addTicks(ts_head, cycles_past_enable * TICKS_PER_CYCLE); 172 178 173 179 // account for one extra packet of frames … … 233 239 if(m_is_disabled) { 234 240 235 transmitSilenceBlock((char *)(data+8), m_syt_interval, 0); 236 m_dbc += fillDataPacketHeader(packet, length, ts_packet); 237 238 debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT SYNC: CY=%04u TSH=%011llu TSP=%011lu\n", 239 cycle, ts_head, ts_packet); 240 241 // update the base timestamp 242 uint32_t ts_step=(uint32_t)((float)(m_syt_interval) 243 *m_SyncSource->m_data_buffer->getRate()); 244 245 // the next buffer head timestamp 246 ts_head=addTicks(ts_head,ts_step); 247 m_data_buffer->setBufferHeadTimestamp(ts_head); 248 241 // transmitSilenceBlock((char *)(data+8), m_syt_interval, 0); 242 // m_dbc += fillDataPacketHeader(packet, length, ts_packet); 243 // 244 // debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT SYNC: CY=%04u TSH=%011llu TSP=%011lu\n", 245 // cycle, ts_head, ts_packet); 246 // 247 // // update the base timestamp 248 // uint32_t ts_step=(uint32_t)((float)(m_syt_interval) 249 // *m_SyncSource->m_data_buffer->getRate()); 250 // 251 // // the next buffer head timestamp 252 // ts_head=addTicks(ts_head,ts_step); 253 // m_data_buffer->setBufferHeadTimestamp(ts_head); 254 // 255 // no-data 256 debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT SYNC: CY=%04u NONE\n", cycle); 257 m_dbc += fillNoDataPacketHeader(packet, length); 249 258 // defer to make sure we get to be enabled asap 250 259 return RAW1394_ISO_DEFER; … … 589 598 // check if a wraparound on the secs will happen between 590 599 // now and the time we start 591 if (CYCLE_TIMER_GET_CYCLES(now)>time_to_enable_at) { 592 // the start will happen in the next second 600 int until_enable=(int)time_to_enable_at - (int)CYCLE_TIMER_GET_CYCLES(now); 601 602 if(until_enable>4000) { 603 // wraparound on CYCLE_TIMER_GET_CYCLES(now) 604 // this means that we are late starting up, 605 // and that the start lies in the previous second 606 if (now_secs==0) now_secs=127; 607 else now_secs--; 608 } else if (until_enable<-4000) { 609 // wraparound on time_to_enable_at 610 // this means that we are early and that the start 611 // point lies in the next second 593 612 now_secs++; 594 613 if (now_secs>=128) now_secs=0; 595 614 } 596 615 597 616 uint64_t ts_head= now_secs*TICKS_PER_SECOND; 598 617 ts_head+=time_to_enable_at*TICKS_PER_CYCLE; … … 600 619 // we also add the nb of cycles we transmit in advance 601 620 ts_head=addTicks(ts_head, TRANSMIT_ADVANCE_CYCLES*TICKS_PER_CYCLE); 602 603 // we want the SP to start sending silent packets somewhat earlier than the604 // time it is enabled605 ts_head=substractTicks(ts_head, 100*TICKS_PER_CYCLE);606 621 607 622 m_data_buffer->setBufferTailTimestamp(ts_head); … … 752 767 /* idea: 753 768 spec says: current_midi_port=(dbc+j)%8; 754 => if we start at (dbc+stream->location-1)%8 [due to location_min=1],769 => if we start at (dbc+stream->location-1)%8, 755 770 we'll start at the right event for the midi port. 756 771 => if we increment j with 8, we stay at the right event. … … 760 775 // first prefill the buffer with NO_DATA's on all time muxed channels 761 776 762 for(j = (dbc & 0x07)+mp->getLocation() -1; j < nevents; j += 8) {777 for(j = (dbc & 0x07)+mp->getLocation(); j < nevents; j += 8) { 763 778 764 779 target_event=(quadlet_t *)(data + ((j * m_dimension) + mp->getPosition())); … … 914 929 915 930 #endif 916 // check our enable status 917 if (!m_disabled && m_is_disabled) { 918 // this means that we are trying to enable 919 if (cycle == m_cycle_to_enable_at) { 931 if (!m_disabled && m_is_disabled) { // this means that we are trying to enable 932 // check if we are on or past the enable point 933 int cycles_past_enable=diffCycles(cycle, m_cycle_to_enable_at); 934 935 if (cycles_past_enable >= 0) { 920 936 m_is_disabled=false; 921 937 debugOutput(DEBUG_LEVEL_VERBOSE,"Enabling StreamProcessor %p at %d (SYT=%04X)\n", … … 1319 1335 /* idea: 1320 1336 spec says: current_midi_port=(dbc+j)%8; 1321 => if we start at (dbc+stream->location-1)%8 [due to location_min=1],1337 => if we start at (dbc+stream->location-1)%8, 1322 1338 we'll start at the right event for the midi port. 1323 1339 => if we increment j with 8, we stay at the right event. … … 1325 1341 // FIXME: as we know in advance how big a packet is (syt_interval) we can 1326 1342 // predict how much loops will be present here 1327 for(j = (dbc & 0x07)+mp->getLocation() -1; j < nevents; j += 8) {1343 for(j = (dbc & 0x07)+mp->getLocation(); j < nevents; j += 8) { 1328 1344 target_event=(quadlet_t *)(data + ((j * m_dimension) + mp->getPosition())); 1329 1345 quadlet_t sample_int=ntohl(*target_event); branches/streaming-rework/src/libstreaming/cip.h
r261 r435 151 151 struct iec61883_packet *packet); 152 152 153 #endif154 155 153 #ifdef __cplusplus 156 154 } 157 155 #endif 156 157 #endif branches/streaming-rework/src/libstreaming/StreamProcessorManager.cpp
r424 r435 35 35 #include "libstreaming/cycletimer.h" 36 36 37 #define CYCLES_TO_SLEEP_AFTER_RUN_SIGNAL 5 037 #define CYCLES_TO_SLEEP_AFTER_RUN_SIGNAL 5 38 38 39 39 #define RUNNING_TIMEOUT_MSEC 4000 … … 41 41 #define ENABLE_TIMEOUT_MSEC 4000 42 42 43 #define ENABLE_DELAY_CYCLES 200043 #define ENABLE_DELAY_CYCLES 100 44 44 45 45 namespace Streaming { … … 277 277 } 278 278 279 280 279 bool StreamProcessorManager::syncStartAll() { 281 280 … … 289 288 notRunning=false; 290 289 291 //for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin();292 //it != m_ReceiveProcessors.end();293 //++it ) {294 //if(!(*it)->isRunning()) notRunning=true;295 //}296 // 297 //for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin();298 //it != m_TransmitProcessors.end();299 //++it ) {300 //if(!(*it)->isRunning()) notRunning=true;301 //}290 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 291 it != m_ReceiveProcessors.end(); 292 ++it ) { 293 if(!(*it)->isRunning()) notRunning=true; 294 } 295 296 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 297 it != m_TransmitProcessors.end(); 298 ++it ) { 299 if(!(*it)->isRunning()) notRunning=true; 300 } 302 301 303 302 // EXPERIMENT: … … 314 313 // other streams still have at least ENABLE_DELAY_CYCLES cycles 315 314 // to start up 316 if(!m_SyncSource->isRunning()) notRunning=true;315 // if(!m_SyncSource->isRunning()) notRunning=true; 317 316 318 317 usleep(1000); branches/streaming-rework/src/libutil/unittests.cpp
r419 r435 28 28 using namespace Util; 29 29 30 #define TEST_SHOULD_RETURN_TRUE(test) \ 31 (test ? true : printf( "'" #test "' should return true\n") && false ) 32 #define TEST_SHOULD_RETURN_FALSE(test) \ 33 (test ? printf( "'" #test "' should return true\n") && false : true ) 34 30 35 /////////////////////////////////////// 31 36 … … 416 421 417 422 Option op1=Option(); 418 if(addOption(op1)) { 419 printf( "adding an empty option should not succeed\n" ); 420 result=false; 421 } 423 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 422 424 423 425 op1=Option("option1"); 424 if(addOption(op1)) { 425 printf( "adding an option without a value should not succeed\n" ); 426 result=false; 427 } 428 426 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 427 429 428 op1=Option("option1", (float)(1.0)); 430 if(!addOption(op1)) { 431 printf( "could not add valid option (1)\n" ); 432 result=false; 433 } 434 if(addOption(op1)) { 435 printf( "adding the same option twice should not succeed\n" ); 436 result=false; 437 } 438 if(!removeOption(op1)) { 439 printf( "could not remove option by reference\n" ); 440 result=false; 441 } 442 if(hasOption(op1)) { 443 printf( "option not removed (by reference)\n" ); 444 result=false; 445 } 429 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 430 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 431 result &= TEST_SHOULD_RETURN_TRUE(removeOption(op1)); 432 result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); 433 446 434 447 435 op1=Option("option1", (int64_t)1); 448 if(!addOption(op1)) { 449 printf( "could not add valid option (2)\n" ); 450 result=false; 451 } 452 if(!removeOption("option1")) { 453 printf( "could not remove option by name\n" ); 454 result=false; 455 } 456 if(hasOption(op1)) { 457 printf( "option not removed (by name)\n" ); 458 result=false; 459 } 436 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 437 438 result &= TEST_SHOULD_RETURN_TRUE(removeOption("option1")); 439 440 result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); 441 460 442 461 443 op1=Option("option1", (int64_t)(-1)); 462 if(!addOption(op1)) { 463 printf( "could not add valid option (3)\n" ); 464 result=false; 465 } 444 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 445 466 446 Option op2=Option("option1", (double)(1.75)); 467 if(addOption(op2)) { 468 printf( "adding two options with the same name should not be allowed\n" ); 469 result=false; 470 } 447 result &= TEST_SHOULD_RETURN_FALSE(addOption(op2)); 448 471 449 472 450 op2=Option("option2", (double)(1.75)); 473 if(!addOption(op2)) { 474 printf( "adding an option with a different name should be allowed (1)\n" ); 475 result=false; 476 } 451 result &= TEST_SHOULD_RETURN_TRUE(addOption(op2)); 452 477 453 Option op3=Option("option3", (int64_t)(1.75)); 478 if(!addOption(op3)) { 479 printf( "adding an option with a different name should be allowed (2)\n" ); 480 result=false; 481 } 482 483 if(countOptions() != 3) { 484 printf( "countOptions failed\n" ); 485 result=false; 486 } 487 454 result &= TEST_SHOULD_RETURN_TRUE(addOption(op3)); 455 456 457 result &= TEST_SHOULD_RETURN_TRUE(countOptions() == 3); 458 488 459 int i=0; 489 460 for ( OptionContainer::iterator it = begin(); … … 494 465 i++; 495 466 } 496 if(i!=3) { 497 printf( "did not iterate through the right amount of options\n" ); 498 result=false; 499 } 467 result &= TEST_SHOULD_RETURN_TRUE(i==3); 500 468 501 469 clearOptions(); … … 525 493 bool result=true; 526 494 testOC oc; 527 if(!oc.test()) { 528 printf( "OptionContainer test failed\n" ); 529 result=false; 530 } 495 result &= TEST_SHOULD_RETURN_TRUE(oc.test()); 531 496 532 497 // now manipulate it externally 533 498 oc.prepare(); 534 499 535 if(!oc.hasOption("option1")) { 536 printf( "option1 should be present\n" ); 537 result=false; 538 } 539 if(!oc.hasOption("option2")) { 540 printf( "option2 should be present\n" ); 541 result=false; 542 } 543 if(!oc.hasOption("option3")) { 544 printf( "option3 should be present\n" ); 545 result=false; 546 } 547 if(oc.hasOption("option4")) { 548 printf( "option4 should not be present\n" ); 549 result=false; 550 } 551 500 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option1")); 501 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option2")); 502 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option3")); 503 result &= TEST_SHOULD_RETURN_FALSE(oc.hasOption("option4")); 504 552 505 oc.setOption("option1", 1024); 553 506 int tst; 554 if (!oc.getOption("option1", tst)) { 555 printf( "could not get option1 value\n" ); 556 result=false; 557 } 558 559 if(tst != 1024) { 560 printf( "option1 should be 1024\n" ); 561 result=false; 562 } 507 result &= TEST_SHOULD_RETURN_TRUE(oc.getOption("option1", tst)); 508 result &= TEST_SHOULD_RETURN_TRUE(tst == 1024); 563 509 564 510 return result; branches/streaming-rework/src/Makefile.am
r426 r435 19 19 INCLUDES = \ 20 20 $(LIBRAW1394_CFLAGS) $(LIBIEC61883_CFLAGS) \ 21 $(LIBAVC1394_CFLAGS) $(LIBXML_CFLAGS)\22 $(LIBXMLCPP_CFLAGS) \21 $(LIBAVC1394_CFLAGS) \ 22 $(LIBXMLCPP_CFLAGS) $(LIBLO_CFLAGS) \ 23 23 -I$(top_srcdir) -I$(top_srcdir)/src 24 24 … … 28 28 -version-info $(LT_VERSION) $(LIBRAW1394_LIBS) \ 29 29 $(LIBIEC61883_LIBS) $(LIBAVC1394_LIBS) \ 30 $(LIBXML_LIBS) $(LIBXMLCPP_LIBS) -lpthread -lrt 30 $(LIBXMLCPP_LIBS) $(LIBLO_LIBS) \ 31 -lpthread -lrt 31 32 32 33 libfreebob_la_LIBADD = -lrt … … 48 49 libavc/avc_plug_info.h libavc/avc_serialize.h libavc/avc_signal_source.h \ 49 50 libavc/avc_subunit_info.h libavc/avc_unit_info.h \ 51 libosc/OscArgument.h libosc/OscNode.h libosc/OscResponse.h libosc/OscServer.h libosc/OscMessage.h \ 50 52 libstreaming/AmdtpPort.h libstreaming/AmdtpPortInfo.h libstreaming/AmdtpStreamProcessor.h \ 53 libstreaming/AmdtpSlaveStreamProcessor.h \ 51 54 libstreaming/cip.h libstreaming/cycletimer.h libstreaming/IsoHandler.h \ 52 55 libstreaming/IsoHandlerManager.h libstreaming/IsoStream.h libstreaming/MotuPort.h \ … … 66 69 freebob_streaming.cpp \ 67 70 iavdevice.cpp \ 68 xmlparser.c \69 71 debugmodule/debugmodule.cpp \ 70 72 libavc/avc_connect.cpp \ … … 86 88 libieee1394/ieee1394service.cpp \ 87 89 libieee1394/IEC61883.cpp \ 90 libosc/OscArgument.cpp \ 91 libosc/OscMessage.cpp \ 92 libosc/OscNode.cpp \ 93 libosc/OscResponse.cpp \ 94 libosc/OscServer.cpp \ 88 95 libstreaming/cip.c \ 89 96 libstreaming/IsoHandler.cpp \ … … 110 117 bebob/bebob_avdevice.cpp \ 111 118 bebob/bebob_avdevice_subunit.cpp \ 112 bebob/bebob_avdevice_xml.cpp \113 119 bebob/bebob_avplug.cpp \ 114 bebob/bebob_avplug_xml.cpp \115 120 bebob/bebob_dl_bcd.cpp \ 116 121 bebob/bebob_dl_codes.cpp \ … … 130 135 bounce_src = \ 131 136 bounce/bounce_avdevice.cpp \ 132 bounce/bounce_slave_avdevice.cpp 137 bounce/bounce_slave_avdevice.cpp \ 138 libstreaming/AmdtpSlaveStreamProcessor.cpp 133 139 134 140 metric_halo_src = \ … … 167 173 # programs not intended for installation 168 174 # generic 169 noinst_PROGRAMS = test-dll test-debugmodule test-unittests test-ser 175 noinst_PROGRAMS = test-dll test-debugmodule \ 176 test-unittests-util test-unittests-osc \ 177 test-ser 170 178 171 179 test_dll_SOURCES = libutil/test-dll.cpp … … 175 183 test_debugmodule_LDADD = $(top_builddir)/src/libfreebob.la 176 184 177 test_unittests_SOURCES = libutil/unittests.cpp 178 test_unittests_LDADD = $(top_builddir)/src/libfreebob.la 185 test_unittests_util_SOURCES = libutil/unittests.cpp 186 test_unittests_util_LDADD = $(top_builddir)/src/libfreebob.la 187 188 test_unittests_osc_SOURCES = libosc/unittests.cpp 189 test_unittests_osc_LDADD = $(top_builddir)/src/libfreebob.la 179 190 180 191 test_ser_SOURCES = ser.cpp branches/streaming-rework/src/maudio/maudio_avdevice.h
r426 r435 25 25 #include "libavc/avc_definitions.h" 26 26 #include "libavc/avc_extended_cmd_generic.h" 27 #include "libfreebob/xmlparser.h"28 27 29 28 #include "bebob/bebob_avdevice.h" branches/streaming-rework/src/metrichalo/mh_avdevice.h
r426 r435 26 26 #include "debugmodule/debugmodule.h" 27 27 #include "libavc/avc_definitions.h" 28 #include "libfreebob/xmlparser.h"29 28 30 29 // #include "libstreaming/MHStreamProcessor.h" branches/streaming-rework/src/motu/motu_avdevice.h
r426 r435 27 27 #include "debugmodule/debugmodule.h" 28 28 #include "libavc/avc_definitions.h" 29 #include "libfreebob/xmlparser.h"30 29 31 30 #include "libstreaming/MotuStreamProcessor.h" branches/streaming-rework/src/rme/rme_avdevice.h
r426 r435 26 26 #include "debugmodule/debugmodule.h" 27 27 #include "libavc/avc_definitions.h" 28 #include "libfreebob/xmlparser.h"29 28 30 29 // #include "libstreaming/RmeStreamProcessor.h" branches/streaming-rework/tests/Makefile.am
r412 r435 24 24 25 25 if BUILD_TESTS 26 noinst_PROGRAMS += test-freebob test- freebob-cpp test-extplugcmd test-fw410 freebob-server\26 noinst_PROGRAMS += test-freebob test-extplugcmd test-fw410 \ 27 27 test-volume test-mixer test-cycletimer test-sytmonitor \ 28 28 test-timestampedbuffer test-ieee1394service … … 31 31 noinst_HEADERS = 32 32 33 test_freebob_SOURCES = test-freebob.c 33 test_freebob_SOURCES = test-freebob.cpp 34 34 test_freebob_LDADD = $(top_builddir)/src/libfreebob.la \ 35 $(LIBXML_LIBS) $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS)36 37 test_freebob_cpp_SOURCES = test-freebob-cpp.cpp38 test_freebob_cpp_LDADD = $(top_builddir)/src/libfreebob.la \39 35 $(LIBXML_LIBS) $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) 40 36 … … 58 54 $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) -lrom1394 59 55 60 freebob_server_SOURCES = freebob-server.c61 freebob_server_LDADD = $(top_builddir)/src/libfreebob.la $(LIBXML_LIBS) \62 $(LIBAVC1394_LIBS) $(LIBIEC61883_LIBS) -lrom139463 64 56 #TESTS_ENVIRONMENT 65 57 TEST = test-freebob branches/streaming-rework/tests/test-freebob.cpp
r412 r435 27 27 28 28 #include "libfreebob/freebob.h" 29 #include "libfreebob/freebob_bounce.h"30 29 31 30 #include "debugmodule/debugmodule.h" … … 41 40 #include <string.h> 42 41 42 #include <vector> 43 #include <string> 44 #include <iostream> 45 #include <sstream> 46 47 #include <lo/lo.h> 48 49 using namespace std; 50 43 51 DECLARE_GLOBAL_DEBUG_MODULE; 44 52 53 // prototypes & stuff for listing the OSC space 54 void list_osc_paths(lo_server s, lo_address t, const char *path); 55 void list_osc_params(lo_server s, lo_address t, const char *path); 56 string osc_param_get_value(lo_server s, lo_address t, const char *path, const char *param); 57 58 vector<string> osc_paths; 59 vector<string> osc_params; 60 string osc_value; 61 62 int osc_path_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 63 void *data, void *user_data); 64 65 int osc_param_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 66 void *data, void *user_data); 67 68 int osc_data_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 69 void *data, void *user_data); 70 71 void osc_error_handler(int num, const char *msg, const char *path); 72 73 // signal handler 45 74 int run=1; 46 75 static void sighandler (int sig) … … 49 78 } 50 79 80 // global's 51 81 const char *argp_program_version = PACKAGE_STRING; 52 82 const char *argp_program_bug_address = PACKAGE_BUGREPORT; … … 54 84 // Program documentation. 55 85 static char doc[] = "FreeBoB -- a driver for Firewire Audio devices (test application)\n\n" 56 "OPERATION: discover\n" 57 " setsamplerate\n"; 86 "OPERATION: Discover\n" 87 " SetSamplerate\n" 88 " ListOscSpace\n" 89 " OscServer\n"; 58 90 59 91 // A description of the arguments we accept. … … 182 214 183 215 printf( "Using freebob library version: %s\n\n", freebob_get_version() ); 184 185 DeviceManager *m_deviceManager = new DeviceManager(); 186 if ( !m_deviceManager ) { 187 fprintf( stderr, "Could not allocate device manager\n" ); 188 return -1; 189 } 190 if ( !m_deviceManager->initialize( arguments.port ) ) { 191 fprintf( stderr, "Could not initialize device manager\n" ); 216 217 if ( strcmp( arguments.args[0], "Discover" ) == 0 ) { 218 DeviceManager *m_deviceManager = new DeviceManager(); 219 if ( !m_deviceManager ) { 220 fprintf( stderr, "Could not allocate device manager\n" ); 221 return -1; 222 } 223 if ( !m_deviceManager->initialize( arguments.port ) ) { 224 fprintf( stderr, "Could not initialize device manager\n" ); 225 delete m_deviceManager; 226 return -1; 227 } 228 if ( !m_deviceManager->discover(arguments.verbose) ) { 229 fprintf( stderr, "Could not discover devices\n" ); 230 delete m_deviceManager; 231 return -1; 232 } 192 233 delete m_deviceManager; 193 return -1; 194 } 195 196 if ( strcmp( arguments.args[0], "discover" ) == 0 ) { 197 if ( m_deviceManager->discover(arguments.verbose) ) { 198 fprintf( stderr, "Could not discover devices\n" ); 199 delete m_deviceManager; 200 return -1; 201 } 202 } else if ( strcmp( arguments.args[0], "setsamplerate" ) == 0 ) { 234 return 0; 235 } else if ( strcmp( arguments.args[0], "SetSamplerate" ) == 0 ) { 203 236 char* tail; 204 237 int samplerate = strtol( arguments.args[1], &tail, 0 ); … … 207 240 return -1; 208 241 } 209 210 if ( m_deviceManager->discover(arguments.verbose) ) { 242 243 DeviceManager *m_deviceManager = new DeviceManager(); 244 if ( !m_deviceManager ) { 245 fprintf( stderr, "Could not allocate device manager\n" ); 246 return -1; 247 } 248 if ( !m_deviceManager->initialize( arguments.port ) ) { 249 fprintf( stderr, "Could not initialize device manager\n" ); 250 delete m_deviceManager; 251 return -1; 252 } 253 254 if ( !m_deviceManager->discover(arguments.verbose) ) { 211 255 fprintf( stderr, "Could not discover devices\n" ); 212 256 delete m_deviceManager; … … 224 268 } 225 269 } else { 226 int i=0; 227 228 int devices_on_bus = m_deviceManager->getNbDevices(); 229 printf(" port = %d, devices_on_bus = %d\n", arguments.port, devices_on_bus); 230 231 for(i=0;i<devices_on_bus;i++) { 232 int node_id=m_deviceManager->getDeviceNodeId(i); 233 printf(" set samplerate for device = %d, node = %d\n", i, node_id); 234 IAvDevice* avDevice = m_deviceManager->getAvDevice( node_id ); 235 if ( avDevice ) { 236 if ( !avDevice->setSamplingFrequency( parseSampleRate( samplerate ) ) ) { 237 fprintf( stderr, "Could not set samplerate\n" ); 270 int i=0; 271 272 int devices_on_bus = m_deviceManager->getNbDevices(); 273 printf(" port = %d, devices_on_bus = %d\n", arguments.port, devices_on_bus); 274 275 for(i=0;i<devices_on_bus;i++) { 276 int node_id=m_deviceManager->getDeviceNodeId(i); 277 printf(" set samplerate for device = %d, node = %d\n", i, node_id); 278 IAvDevice* avDevice = m_deviceManager->getAvDevice( node_id ); 279 if ( avDevice ) { 280 if ( !avDevice->setSamplingFrequency( parseSampleRate( samplerate ) ) ) { 281 fprintf( stderr, "Could not set samplerate\n" ); 282 } 238 283 } 239 284 } 240 285 } 241 242 } 286 delete m_deviceManager; 287 return 0; 288 } else if ( strcmp( arguments.args[0], "ListOscSpace" ) == 0 ) { 289 // list osc space by using OSC messages 290 // a server is assumed to be present 291 292 /* start a new server. 293 when sending a message from this context, the response 294 address will be set to this server's address. 295 */ 296 lo_server s = lo_server_new(NULL, osc_error_handler); 297 lo_address t = lo_address_new(NULL, "17820"); 298 299 list_osc_paths(s, t, "/"); 300 301 lo_address_free(t); 302 lo_server_free(s); 303 304 } else if ( strcmp( arguments.args[0], "OscServer" ) == 0 ) { 305 DeviceManager *m_deviceManager = new DeviceManager(); 306 if ( !m_deviceManager ) { 307 fprintf( stderr, "Could not allocate device manager\n" ); 308 return -1; 309 } 310 if ( !m_deviceManager->initialize( arguments.port ) ) { 311 fprintf( stderr, "Could not initialize device manager\n" ); 312 delete m_deviceManager; 313 return -1; 314 } 315 316 if ( !m_deviceManager->discover(arguments.verbose) ) { 317 fprintf( stderr, "Could not discover devices\n" ); 318 delete m_deviceManager; 319 return -1; 320 } 321 322 printf("server started\n"); 323 printf("press ctrl-c to stop it & continue\n"); 324 325 signal (SIGINT, sighandler); 326 327 run=1; 328 while(run) { 329 sleep(1); 330 fflush(stdout); 331 fflush(stderr); 332 } 333 signal (SIGINT, SIG_DFL); 334 335 printf("server stopped\n"); 336 delete m_deviceManager; 337 return 0; 338 243 339 } else { 244 340 printf( "unknown operation\n" ); 245 341 } 246 342 247 return 0; 248 } 343 } 344 345 void list_osc_paths(lo_server s, lo_address t, const char *path) { 346 vector<string> my_paths; 347 348 printf("listing path: %s\n", path); 349 350 osc_paths.clear(); 351 lo_server_add_method(s, "/response", NULL, osc_path_response_handler, NULL); 352 353 if (lo_send(t, path, "s", "list") == -1) { 354 printf(" OSC error %d: %s\n", lo_address_errno(t), lo_address_errstr(t)); 355 } 356 357 if (lo_server_recv_noblock(s, 1000) == 0) { 358 printf("timeout\n"); 359 return; 360 } 361 362 lo_server_del_method(s, "/response", NULL); 363 364 list_osc_params(s, t, path); 365 366 my_paths=osc_paths; 367 for ( vector<string>::iterator it = my_paths.begin(); 368 it != my_paths.end(); 369 ++it ) 370 { 371 string new_path=string(path) + *it; 372 new_path += string("/"); 373 list_osc_paths(s, t, new_path.c_str()); 374 } 375 376 } 377 378 void list_osc_params(lo_server s, lo_address t, const char *path) { 379 vector<string> my_paths; 380 printf("params for: %s\n", path); 381 382 osc_params.clear(); 383 lo_server_add_method(s, "/response", NULL, osc_param_response_handler, NULL); 384 385 if (lo_send(t, path, "s", "params") == -1) { 386 printf(" OSC error %d: %s\n", lo_address_errno(t), lo_address_errstr(t)); 387 } 388 389 if (lo_server_recv_noblock(s, 1000) == 0) { 390 printf("timeout\n"); 391 return; 392 } 393 394 lo_server_del_method(s, "/response", NULL); 395 396 vector<string> my_params=osc_params; 397 398 for ( vector<string>::iterator it = my_params.begin(); 399 it != my_params.end(); 400 ++it ) 401 { 402 string value=osc_param_get_value(s, t, path, (*it).c_str()); 403 printf(" %20s = %s\n", (*it).c_str(), value.c_str()); 404 } 405 406 } 407 408 string osc_param_get_value(lo_server s, lo_address t, const char *path, const char *param) { 409 lo_server_add_method(s, "/response", NULL, osc_data_response_handler, NULL); 410 411 if (lo_send(t, path, "ss", "get", param) == -1) { 412 printf(" OSC error %d: %s\n", lo_address_errno(t), lo_address_errstr(t)); 413 } 414 415 if (lo_server_recv_noblock(s, 1000) == 0) { 416 return string("timeout"); 417 } 418 419 lo_server_del_method(s, "/response", NULL); 420 return osc_value; 421 } 422 423 void osc_error_handler(int num, const char *msg, const char *path) 424 { 425 printf("liblo server error %d in path %s: %s\n", num, path, msg); 426 } 427 428 int osc_path_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 429 void *data, void *user_data) 430 { 431 for (int i=0; i< argc;i++) { 432 switch (lo_type(types[i])) { 433 /** Standard C, NULL terminated string. */ 434 case LO_STRING: 435 osc_paths.push_back(string(&(argv[i]->s))); 436 break; 437 default: 438 printf("unexpected data type in response message\n"); 439 } 440 } 441 return 1; 442 } 443 444 int osc_param_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 445 void *data, void *user_data) 446 { 447 for (int i=0; i< argc;i++) { 448 switch (lo_type(types[i])) { 449 /** Standard C, NULL terminated string. */ 450 case LO_STRING: 451 osc_params.push_back(string(&(argv[i]->s))); 452 break; 453 default: 454 printf("unexpected data type in response message\n"); 455 } 456 } 457 return 1; 458 } 459 460 int osc_data_response_handler(const char *path, const char *types, lo_arg **argv, int argc, 461 void *data, void *user_data) 462 { 463 std::ostringstream str; 464 465 if(argc==1) { 466 switch (lo_type(types[0])) { 467 /* basic OSC types */ 468 /** 32 bit signed integer. */ 469 case LO_INT32: 470 str << "0x" << std::hex << argv[0]->i; 471 osc_value=str.str(); 472 break; 473 case LO_INT64: 474 str << "0x" << std::hex << argv[0]->h; 475 osc_value=str.str(); 476 break; 477 /** 32 bit IEEE-754 float. */ 478 case LO_FLOAT: 479 str << argv[0]->f; 480 osc_value=str.str(); 481 break; 482 /** Standard C, NULL terminated string. */ 483 case LO_STRING: 484 osc_value=string(&argv[0]->s); 485 break; 486 default: 487 osc_value="unsupported response datatype"; 488 } 489 } else { 490 osc_value="invalid response"; 491 } 492 return 1; 493 }