Changeset 796
- Timestamp:
- 01/01/08 11:31:39 (14 years ago)
- Files:
-
- trunk/libffado/config.h.in (modified) (1 diff)
- trunk/libffado/src/libieee1394/IsoHandler.cpp (modified) (5 diffs)
- trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (modified) (5 diffs)
- trunk/libffado/src/libieee1394/IsoHandlerManager.h (modified) (3 diffs)
- trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (modified) (4 diffs)
- trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp (modified) (2 diffs)
- trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp (modified) (5 diffs)
- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (modified) (10 diffs)
- trunk/libffado/src/libutil/TimestampedBuffer.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/config.h.in
r756 r796 36 36 #define SHAREDIR "$sharedir" 37 37 38 #define MINIMUM_INTERRUPTS_PER_PERIOD 4U 39 #define MAX_ISO_XMIT_BUFFER_FILL_PCT 70 40 41 #define ISOHANDLER_PER_HANDLER_THREAD 0 42 #define ISOHANDLER_USE_POLL 0 43 44 #define ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT 16 45 46 // allows to add some processing margin. This shifts the time 47 // at which the buffer is transfer()'ed, making things somewhat 48 // more robust. It should be noted though that shifting the transfer 49 // time to a later time instant also causes the xmit buffer fill to be 50 // lower on average. 51 #define STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS (3072*1) 52 53 #define STREAMPROCESSORMANAGER_CYCLES_FOR_DRYRUN 40000 54 #define STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP 2000 55 #define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT 20 56 #define STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV 0 57 #define STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC 200 58 #define STREAMPROCESSORMANAGER_NB_ALIGN_TRIES 40 59 60 61 // FIXME: note that it will probably be better to use a DLL bandwidth that is 62 // dependant on the sample rate 63 #define TIMESTAMPEDBUFFER_DLL_BANDWIDTH (0.01) 64 65 // in ticks 66 // as per AMDTP2.1: 67 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks 68 #define AMDTP_TRANSMIT_TRANSFER_DELAY (11776U) 69 70 #define MOTU_TRANSMIT_TRANSFER_DELAY (11776U) 71 38 72 #endif // CONFIG_H trunk/libffado/src/libieee1394/IsoHandler.cpp
r791 r796 22 22 */ 23 23 24 //#define PER_HANDLER_THREAD 24 #include "config.h" 25 25 26 26 #include "IsoHandler.h" … … 183 183 } 184 184 185 #if def DO_POLL185 #if ISOHANDLER_USE_POLL 186 186 uint64_t poll_enter = m_manager.get1394Service().getCurrentTimeAsUsecs(); 187 187 err = poll(&m_poll_fd, 1, m_poll_timeout); … … 228 228 bool 229 229 IsoHandler::iterate() { 230 flush();230 //flush(); 231 231 if(raw1394_loop_iterate(m_handle)) { 232 232 debugOutput( DEBUG_LEVEL_VERBOSE, … … 288 288 } 289 289 290 #if def THREAD_PER_ISOHANDLER290 #if ISOHANDLER_PER_HANDLER_THREAD 291 291 // create a thread to iterate ourselves 292 292 debugOutput( DEBUG_LEVEL_VERBOSE, "Start thread for %p...\n", this); … … 471 471 m_max_packet_size, 472 472 m_Client->getChannel(), 473 RAW1394_DMA_BUFFERFILL, 473 // RAW1394_DMA_BUFFERFILL, 474 RAW1394_DMA_PACKET_PER_BUFFER, 474 475 m_irq_interval)) { 475 476 debugFatal("Could not do receive initialisation (DMA_BUFFERFILL)!\n" ); trunk/libffado/src/libieee1394/IsoHandlerManager.cpp
r791 r796 22 22 */ 23 23 24 #include "config.h" 24 25 #include "IsoHandlerManager.h" 25 26 #include "ieee1394service.h" … … 32 33 33 34 #include <assert.h> 34 35 #define MINIMUM_INTERRUPTS_PER_PERIOD 4U36 35 37 36 IMPL_DEBUG_MODULE( IsoHandlerManager, IsoHandlerManager, DEBUG_LEVEL_NORMAL ); … … 101 100 unsigned int i; 102 101 m_poll_nfds_shadow = m_IsoHandlers.size(); 103 if(m_poll_nfds_shadow > FFADO_MAX_ISO_HANDLERS_PER_PORT) {102 if(m_poll_nfds_shadow > ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT) { 104 103 debugWarning("Too much ISO Handlers in manager...\n"); 105 m_poll_nfds_shadow = FFADO_MAX_ISO_HANDLERS_PER_PORT;104 m_poll_nfds_shadow = ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT; 106 105 } 107 106 for (i = 0; i < m_poll_nfds_shadow; i++) { … … 209 208 } 210 209 211 #ifndef THREAD_PER_ISOHANDLER 210 #if ISOHANDLER_PER_HANDLER_THREAD 211 #else 212 212 // create a thread to iterate our handlers 213 213 debugOutput( DEBUG_LEVEL_VERBOSE, "Start thread for %p...\n", this); … … 368 368 } 369 369 370 //unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD;371 //if(irq_interval <= 0) irq_interval=1;372 unsigned int irq_interval=2; // this is not the HW IRQ interval370 unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 371 if(irq_interval <= 0) irq_interval=1; 372 // unsigned int irq_interval=2; // this is not the HW IRQ interval 373 373 374 374 // the receive buffer size doesn't matter for the latency, trunk/libffado/src/libieee1394/IsoHandlerManager.h
r795 r796 25 25 #define __FFADO_ISOHANDLERMANAGER__ 26 26 27 #include "config.h" 28 27 29 #include "debugmodule/debugmodule.h" 28 30 … … 34 36 #include <vector> 35 37 36 //#define THREAD_PER_ISOHANDLER37 38 #define FFADO_MAX_ISO_HANDLERS_PER_PORT 1639 40 #define USLEEP_AFTER_UPDATE_FAILURE 1041 #define USLEEP_AFTER_UPDATE 10042 #define MAX_UPDATE_TRIES 1043 38 class Ieee1394Service; 44 39 … … 74 69 private: 75 70 // shadow variables 76 struct pollfd m_poll_fds_shadow[ FFADO_MAX_ISO_HANDLERS_PER_PORT];77 IsoHandler *m_IsoHandler_map_shadow[ FFADO_MAX_ISO_HANDLERS_PER_PORT];71 struct pollfd m_poll_fds_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT]; 72 IsoHandler *m_IsoHandler_map_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT]; 78 73 unsigned int m_poll_nfds_shadow; 79 74 trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp
r790 r796 37 37 #include <assert.h> 38 38 39 // in ticks40 // as per AMDTP2.1:41 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks42 #define DEFAULT_TRANSFER_DELAY (11776U)43 44 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY45 46 39 namespace Streaming 47 40 { … … 90 83 // a packet ahead of the presentation time. The nominal time 91 84 // the packet is transmitted ahead of the presentation time is 92 // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we85 // given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 93 86 // are too late for that, this constant defines how late we can 94 87 // be. … … 98 91 // a packet ahead of the ideal transmit time. The nominal time 99 92 // the packet is transmitted ahead of the presentation time is 100 // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send93 // given by AMDTP_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 101 94 // packets early if we want to. (not completely according to spec) 102 95 const int max_cycles_to_transmit_early = 2; … … 114 107 115 108 // now we calculate the time when we have to transmit the sample block 116 transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY );109 transmit_at_time = substractTicks ( presentation_time, AMDTP_TRANSMIT_TRANSFER_DELAY ); 117 110 118 111 // calculate the cycle this block should be presented in trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp
r795 r796 21 21 * 22 22 */ 23 24 #include "config.h" 23 25 24 26 #include "StreamProcessor.h" … … 112 114 // in the transmit buffer (the others are still to be put into the xmit frame buffer) 113 115 unsigned int packets_to_prebuffer = (getPacketsPerPeriod() * (m_StreamProcessorManager.getNbBuffers()-1)); 116 debugOutput(DEBUG_LEVEL_VERBOSE, "Nominal prebuffer: %u\n", packets_to_prebuffer); 114 117 115 // however we have to take into account the fact that there is some sync delay (unknown at this point) 116 packets_to_prebuffer -= 16; //FIXME: magic 118 // however we have to take into account the fact that there is some sync delay 119 // we assume that the SPM has indicated 120 // HACK: this counts on the fact that the latency for this stream will be the same as the 121 // latency for the receive sync source 122 unsigned int est_sync_delay = getPacketsPerPeriod() / MINIMUM_INTERRUPTS_PER_PERIOD; 123 est_sync_delay += STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS / TICKS_PER_CYCLE; 124 packets_to_prebuffer -= est_sync_delay; 125 debugOutput(DEBUG_LEVEL_VERBOSE, " correct for sync delay (%d): %u\n", 126 est_sync_delay, 127 packets_to_prebuffer); 117 128 118 // only queue a part (80%) of the theoretical max in order not to have too much 'not ready' cycles 119 packets_to_prebuffer = (packets_to_prebuffer * 7000) / 10000; 129 // only queue a part (70%) of the theoretical max in order not to have too much 'not ready' cycles 130 packets_to_prebuffer = (packets_to_prebuffer * MAX_ISO_XMIT_BUFFER_FILL_PCT * 1000) / 100000; 131 debugOutput(DEBUG_LEVEL_VERBOSE, " reduce to %d%%: %u\n", 132 MAX_ISO_XMIT_BUFFER_FILL_PCT, packets_to_prebuffer); 120 133 121 134 return packets_to_prebuffer; trunk/libffado/src/libstreaming/motu/MotuTransmitStreamProcessor.cpp
r753 r796 23 23 */ 24 24 25 #include "config.h" 26 25 27 #include "MotuTransmitStreamProcessor.h" 26 28 #include "MotuPort.h" … … 34 36 #include <netinet/in.h> 35 37 #include <assert.h> 36 37 // in ticks38 // as per AMDTP2.1:39 // 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks40 #define DEFAULT_TRANSFER_DELAY (11776U)41 42 #define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY43 38 44 39 // Set to 1 to enable the generation of a 1 kHz test tone in analog output 1 … … 110 105 // a packet ahead of the presentation time. The nominal time 111 106 // the packet is transmitted ahead of the presentation time is 112 // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we107 // given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 113 108 // are too late for that, this constant defines how late we can 114 109 // be. … … 118 113 // a packet ahead of the ideal transmit time. The nominal time 119 114 // the packet is transmitted ahead of the presentation time is 120 // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send115 // given by MOTU_TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 121 116 // packets early if we want to. (not completely according to spec) 122 117 const int max_cycles_to_transmit_early = 2; … … 135 130 136 131 // now we calculate the time when we have to transmit the sample block 137 transmit_at_time = substractTicks ( presentation_time, TRANSMIT_TRANSFER_DELAY );132 transmit_at_time = substractTicks ( presentation_time, MOTU_TRANSMIT_TRANSFER_DELAY ); 138 133 139 134 // calculate the cycle this block should be presented in trunk/libffado/src/libstreaming/StreamProcessorManager.cpp
r795 r796 21 21 * 22 22 */ 23 #include "config.h" 23 24 24 25 #include "StreamProcessorManager.h" … … 32 33 #include <assert.h> 33 34 #include <math.h> 34 35 #define RUNNING_TIMEOUT_MSEC 400036 #define PREPARE_TIMEOUT_MSEC 400037 #define ENABLE_TIMEOUT_MSEC 400038 39 // allows to add some processing margin. This shifts the time40 // at which the buffer is transfer()'ed, making things somewhat41 // more robust. It should be noted though that shifting the transfer42 // time to a later time instant also causes the xmit buffer fill to be43 // lower on average.44 #define FFADO_SIGNAL_DELAY_TICKS (3072*1)45 35 46 36 namespace Streaming { … … 257 247 // wait for the syncsource to start running. 258 248 // that will block the waitForPeriod call until everyone has started (theoretically) 259 #define CYCLES_FOR_DRYRUN 40000 260 int cnt = CYCLES_FOR_DRYRUN; // by then it should have started 249 int cnt = STREAMPROCESSORMANAGER_CYCLES_FOR_DRYRUN; // by then it should have started 261 250 bool all_dry_running = false; 262 251 while (!all_dry_running && cnt) { … … 319 308 // time to a later time instant also causes the xmit buffer fill to be 320 309 // lower on average. 321 max_of_min_delay += FFADO_SIGNAL_DELAY_TICKS;310 max_of_min_delay += STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS; 322 311 debugOutput( DEBUG_LEVEL_VERBOSE, " sync delay = %d ticks (%03us %04uc %04ut)...\n", 323 312 max_of_min_delay, … … 361 350 (unsigned int)TICKS_TO_OFFSET(time_of_first_sample)); 362 351 363 #define CYCLES_FOR_STARTUP 2000 364 // start wet-running in CYCLES_FOR_STARTUP cycles 352 // start wet-running in STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP cycles 365 353 // this is the time window we have to setup all SP's such that they 366 354 // can start wet-running correctly. 367 355 time_of_first_sample = addTicks(time_of_first_sample, 368 CYCLES_FOR_STARTUP * TICKS_PER_CYCLE);356 STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP * TICKS_PER_CYCLE); 369 357 370 358 debugOutput( DEBUG_LEVEL_VERBOSE, " => first sample at TS=%011llu (%03us %04uc %04ut)...\n", … … 376 364 // we should start wet-running the transmit SP's some cycles in advance 377 365 // such that we know it is wet-running when it should output its first sample 378 #define PRESTART_CYCLES_FOR_XMIT 20379 366 uint64_t time_to_start_xmit = substractTicks(time_of_first_sample, 380 PRESTART_CYCLES_FOR_XMIT * TICKS_PER_CYCLE); 381 382 #define PRESTART_CYCLES_FOR_RECV 0 367 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT * TICKS_PER_CYCLE); 368 383 369 uint64_t time_to_start_recv = substractTicks(time_of_first_sample, 384 PRESTART_CYCLES_FOR_RECV * TICKS_PER_CYCLE);370 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV * TICKS_PER_CYCLE); 385 371 debugOutput( DEBUG_LEVEL_VERBOSE, " => xmit starts at TS=%011llu (%03us %04uc %04ut)...\n", 386 372 time_to_start_xmit, … … 421 407 // wait for the syncsource to start running. 422 408 // that will block the waitForPeriod call until everyone has started (theoretically) 423 int cnt = CYCLES_FOR_STARTUP * 20; // by then it should have started409 int cnt = STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP * 20; // by then it should have started 424 410 while (!m_SyncSource->isRunning() && cnt) { 425 411 SleepRelativeUsec(125); … … 444 430 { 445 431 if(m_SyncSource == NULL) return false; 446 #define ALIGN_AVERAGE_TIME_MSEC 200447 #define NB_ALIGN_TRIES 40448 432 debugOutput( DEBUG_LEVEL_VERBOSE, "Aligning received streams...\n"); 449 433 unsigned int nb_sync_runs; … … 454 438 unsigned int i; 455 439 456 unsigned int periods_per_align_try = ( ALIGN_AVERAGE_TIME_MSEC * getNominalRate());440 unsigned int periods_per_align_try = (STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC * getNominalRate()); 457 441 periods_per_align_try /= 1000; 458 442 periods_per_align_try /= getPeriodSize(); … … 460 444 461 445 bool aligned = false; 462 int cnt = NB_ALIGN_TRIES;446 int cnt = STREAMPROCESSORMANAGER_NB_ALIGN_TRIES; 463 447 while (!aligned && cnt--) { 464 448 nb_sync_runs = periods_per_align_try; trunk/libffado/src/libutil/TimestampedBuffer.cpp
r795 r796 22 22 */ 23 23 24 #include "config.h" 25 24 26 #include "libutil/Atomic.h" 25 27 #include "libieee1394/cycletimer.h" … … 29 31 #include "errno.h" 30 32 31 // FIXME: note that it will probably be better to use a DLL bandwidth that is 32 // dependant on the sample rate 33 34 35 // #define DLL_BANDWIDTH (4800/48000.0) 36 #define DLL_BANDWIDTH (0.01) 33 37 34 #define DLL_PI (3.141592653589793238) 38 35 #define DLL_SQRT2 (1.414213562373095049) 39 #define DLL_OMEGA (2.0*DLL_PI* DLL_BANDWIDTH)36 #define DLL_OMEGA (2.0*DLL_PI*TIMESTAMPEDBUFFER_DLL_BANDWIDTH) 40 37 #define DLL_COEFF_B (DLL_SQRT2 * DLL_OMEGA) 41 38 #define DLL_COEFF_C (DLL_OMEGA * DLL_OMEGA)