- Timestamp:
- 10/24/08 02:37:37 (15 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libffado-2.0/src/libstreaming/StreamProcessorManager.cpp
r1346 r1373 45 45 , m_parent( p ) 46 46 , m_xrun_happened( false ) 47 , m_activity_wait_timeout_ usec( 1000*1000 )47 , m_activity_wait_timeout_nsec( 0 ) // dynamically set 48 48 , m_nb_buffers( 0 ) 49 49 , m_period( 0 ) … … 65 65 , m_parent( p ) 66 66 , m_xrun_happened( false ) 67 , m_activity_wait_timeout_ usec( 1000*1000 )67 , m_activity_wait_timeout_nsec( 0 ) // dynamically set 68 68 , m_nb_buffers(nb_buffers) 69 69 , m_period(period) … … 149 149 int result; 150 150 151 long long int timeout_nsec=0; 152 if (m_activity_wait_timeout_usec >= 0) { 153 timeout_nsec = m_activity_wait_timeout_usec * 1000LL; 151 if (m_activity_wait_timeout_nsec >= 0) { 154 152 155 153 if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { … … 157 155 return eAR_Error; 158 156 } 159 ts.tv_nsec += timeout_nsec;157 ts.tv_nsec += m_activity_wait_timeout_nsec; 160 158 while(ts.tv_nsec >= 1000000000LL) { 161 159 ts.tv_sec += 1; … … 164 162 } 165 163 166 if (m_activity_wait_timeout_ usec >= 0) {164 if (m_activity_wait_timeout_nsec >= 0) { 167 165 result = sem_timedwait(&m_activity_semaphore, &ts); 168 166 } else { … … 185 183 this, result); 186 184 debugError("(%p) timeout_nsec=%lld ts.sec=%d ts.nsec=%lld\n", 187 this, timeout_nsec, ts.tv_sec, ts.tv_nsec);185 this, m_activity_wait_timeout_nsec, ts.tv_sec, ts.tv_nsec); 188 186 return eAR_Error; 189 187 } else { … … 191 189 this, result, errno); 192 190 debugError("(%p) timeout_nsec=%lld ts.sec=%d ts.nsec=%lld\n", 193 this, timeout_nsec, ts.tv_sec, ts.tv_nsec);191 this, m_activity_wait_timeout_nsec, ts.tv_sec, ts.tv_nsec); 194 192 return eAR_Error; 195 193 } … … 439 437 bool StreamProcessorManager::syncStartAll() { 440 438 if(m_SyncSource == NULL) return false; 439 440 // get the options 441 int signal_delay_ticks = STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS; 442 int sync_wait_time_msec = STREAMPROCESSORMANAGER_SYNC_WAIT_TIME_MSEC; 443 int cycles_for_startup = STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP; 444 int prestart_cycles_for_xmit = STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT; 445 int prestart_cycles_for_recv = STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV; 446 Util::Configuration &config = m_parent.getConfiguration(); 447 config.getValueForSetting("streaming.spm.signal_delay_ticks", signal_delay_ticks); 448 config.getValueForSetting("streaming.spm.sync_wait_time_msec", sync_wait_time_msec); 449 config.getValueForSetting("streaming.spm.cycles_for_startup", cycles_for_startup); 450 config.getValueForSetting("streaming.spm.prestart_cycles_for_xmit", prestart_cycles_for_xmit); 451 config.getValueForSetting("streaming.spm.prestart_cycles_for_recv", prestart_cycles_for_recv); 452 441 453 // figure out when to get the SP's running. 442 454 // the xmit SP's should also know the base timestamp … … 460 472 // time to a later time instant also causes the xmit buffer fill to be 461 473 // lower on average. 462 max_of_min_delay += STREAMPROCESSORMANAGER_SIGNAL_DELAY_TICKS;474 max_of_min_delay += signal_delay_ticks; 463 475 464 476 m_SyncSource->setSyncDelay(max_of_min_delay); … … 479 491 debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for sync...\n"); 480 492 481 unsigned int nb_sync_runs = ( STREAMPROCESSORMANAGER_SYNC_WAIT_TIME_MSEC* getNominalRate());493 unsigned int nb_sync_runs = (sync_wait_time_msec * getNominalRate()); 482 494 nb_sync_runs /= 1000; 483 495 nb_sync_runs /= getPeriodSize(); … … 512 524 // can start wet-running correctly. 513 525 time_of_first_sample = addTicks(time_of_first_sample, 514 STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP* TICKS_PER_CYCLE);526 cycles_for_startup * TICKS_PER_CYCLE); 515 527 516 528 debugOutput( DEBUG_LEVEL_VERBOSE, " => first sample at TS=%011llu (%03us %04uc %04ut)...\n", … … 523 535 // such that we know it is wet-running when it should output its first sample 524 536 uint64_t time_to_start_xmit = substractTicks(time_of_first_sample, 525 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_XMIT* TICKS_PER_CYCLE);537 prestart_cycles_for_xmit * TICKS_PER_CYCLE); 526 538 527 539 uint64_t time_to_start_recv = substractTicks(time_of_first_sample, 528 STREAMPROCESSORMANAGER_PRESTART_CYCLES_FOR_RECV* TICKS_PER_CYCLE);540 prestart_cycles_for_recv * TICKS_PER_CYCLE); 529 541 debugOutput( DEBUG_LEVEL_VERBOSE, " => xmit starts at TS=%011llu (%03us %04uc %04ut)...\n", 530 542 time_to_start_xmit, … … 585 597 // note: the SP's are scheduled to start in STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP cycles, 586 598 // so a 20 times this value should be a good timeout 587 int cnt = STREAMPROCESSORMANAGER_CYCLES_FOR_STARTUP* 20; // by then it should have started599 int cnt = cycles_for_startup * 20; // by then it should have started 588 600 while (!m_SyncSource->isRunning() && cnt) { 589 601 SleepRelativeUsec(125); … … 649 661 unsigned int i; 650 662 651 unsigned int periods_per_align_try = (STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC * getNominalRate()); 663 int cnt = STREAMPROCESSORMANAGER_NB_ALIGN_TRIES; 664 int align_average_time_msec = STREAMPROCESSORMANAGER_ALIGN_AVERAGE_TIME_MSEC; 665 Util::Configuration &config = m_parent.getConfiguration(); 666 config.getValueForSetting("streaming.spm.align_tries", cnt); 667 config.getValueForSetting("streaming.spm.align_average_time_msec", align_average_time_msec); 668 669 unsigned int periods_per_align_try = (align_average_time_msec * getNominalRate()); 652 670 periods_per_align_try /= 1000; 653 671 periods_per_align_try /= getPeriodSize(); … … 655 673 656 674 bool aligned = false; 657 int cnt = STREAMPROCESSORMANAGER_NB_ALIGN_TRIES;658 675 while (!aligned && cnt--) { 659 676 nb_sync_runs = periods_per_align_try;