Changeset 721
- Timestamp:
- 11/23/07 10:09:15 (13 years ago)
- Files:
-
- branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (modified) (2 diffs)
- branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.cpp (modified) (7 diffs)
- branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.h (modified) (2 diffs)
- branches/ppalmers-streaming/src/libstreaming/StreamProcessorManager.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp
r720 r721 145 145 { 146 146 // not enough frames in the buffer, 147 debugOutput ( DEBUG_LEVEL_VERBOSE, 148 "Insufficient frames: N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", 149 fc, cycle, transmit_at_cycle, cycles_until_transmit ); 147 150 148 // we can still postpone the queueing of the packets 151 149 // if we are far enough ahead of the presentation time 152 150 if ( cycles_until_presentation <= min_cycles_before_presentation ) 153 151 { 152 debugOutput ( DEBUG_LEVEL_VERBOSE, 153 "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", 154 fc, cycle, transmit_at_cycle, cycles_until_transmit ); 154 155 // we are too late 155 156 // meaning that we in some sort of xrun state … … 161 162 else 162 163 { 164 debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, 165 "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", 166 fc, cycle, transmit_at_cycle, cycles_until_transmit ); 163 167 // there is still time left to send the packet 164 168 // we want the system to give this packet another go branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.cpp
r720 r721 464 464 } 465 465 return RAW1394_ISO_OK; 466 } else { // pick up the possible xruns 467 466 468 } 467 469 } … … 512 514 // use the ts parameter. It specifies the time of the block's 513 515 // last sample. 514 515 // determine the time at which we want reception to start516 516 float srate = m_manager->getSyncSource().getTicksPerFrame(); 517 517 assert(srate != 0.0); 518 518 int64_t this_block_length_in_ticks = (int64_t)(((float)nbframes) * srate); 519 519 520 520 ffado_timestamp_t ts_head_tmp; 521 521 m_data_buffer->getBufferHeadTimestamp(&ts_head_tmp, &fc); 522 522 ts_expected = addTicks((uint64_t)ts_head_tmp, this_block_length_in_ticks); 523 523 524 524 lag_ticks = diffTicks(ts, ts_expected); 525 526 527 525 lag_frames = (((float)lag_ticks) / srate); 528 529 526 debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "stream (%p): drifts %6d ticks = %10.5f frames (rate=%10.5f), %lld, %llu, %d\n", 530 527 this, lag_ticks, lag_frames, srate, ts, ts_expected, fc); 531 532 528 if (lag_frames >= 1.0) { 533 529 // the stream lags … … 611 607 } 612 608 613 bool StreamProcessor::stop()614 {615 debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "stop...\n");616 switch (m_state) {617 case ePS_Stopped: return true;618 case ePS_DryRunning:619 return stopDryRunning(-1);620 case ePS_Running:621 return stopRunning(-1) &&622 stopDryRunning(-1);623 default:624 debugError("Bad state: %s\n", ePSToString(m_state));625 return false;626 }627 }628 629 609 bool 630 610 StreamProcessor::scheduleStateTransition(enum eProcessorState state, uint64_t time_instant) … … 661 641 } 662 642 debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 663 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011lu\n", m_handler->getCycleTimerTicks()); 664 debugOutput(DEBUG_LEVEL_VERBOSE," Start at : %011llu (%u)\n", tx, TICKS_TO_CYCLES(tx)); 643 uint64_t now = m_handler->getCycleTimerTicks(); 644 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011llu (%03us %04uc %04ut)\n", 645 now, 646 (unsigned int)TICKS_TO_SECS(now), 647 (unsigned int)TICKS_TO_CYCLES(now), 648 (unsigned int)TICKS_TO_OFFSET(now)); 649 debugOutput(DEBUG_LEVEL_VERBOSE," Start at : %011llu (%03us %04uc %04ut)\n", 650 tx, 651 (unsigned int)TICKS_TO_SECS(tx), 652 (unsigned int)TICKS_TO_CYCLES(tx), 653 (unsigned int)TICKS_TO_OFFSET(tx)); 665 654 if (m_state == ePS_Stopped) { 666 655 return scheduleStateTransition(ePS_WaitingForStream, tx); … … 681 670 } 682 671 debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 683 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011lu\n", m_handler->getCycleTimerTicks()); 684 debugOutput(DEBUG_LEVEL_VERBOSE," Start at : %011llu (%u)\n", tx, TICKS_TO_CYCLES(tx)); 672 uint64_t now = m_handler->getCycleTimerTicks(); 673 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011llu (%03us %04uc %04ut)\n", 674 now, 675 (unsigned int)TICKS_TO_SECS(now), 676 (unsigned int)TICKS_TO_CYCLES(now), 677 (unsigned int)TICKS_TO_OFFSET(now)); 678 debugOutput(DEBUG_LEVEL_VERBOSE," Start at : %011llu (%03us %04uc %04ut)\n", 679 tx, 680 (unsigned int)TICKS_TO_SECS(tx), 681 (unsigned int)TICKS_TO_CYCLES(tx), 682 (unsigned int)TICKS_TO_OFFSET(tx)); 685 683 return scheduleStateTransition(ePS_WaitingForStreamEnable, tx); 686 684 } … … 694 692 } 695 693 debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 696 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011lu\n", m_handler->getCycleTimerTicks()); 697 debugOutput(DEBUG_LEVEL_VERBOSE," Stop at : %011llu (%u)\n", tx, TICKS_TO_CYCLES(tx)); 694 uint64_t now = m_handler->getCycleTimerTicks(); 695 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011llu (%03us %04uc %04ut)\n", 696 now, 697 (unsigned int)TICKS_TO_SECS(now), 698 (unsigned int)TICKS_TO_CYCLES(now), 699 (unsigned int)TICKS_TO_OFFSET(now)); 700 debugOutput(DEBUG_LEVEL_VERBOSE," Stop at : %011llu (%03us %04uc %04ut)\n", 701 tx, 702 (unsigned int)TICKS_TO_SECS(tx), 703 (unsigned int)TICKS_TO_CYCLES(tx), 704 (unsigned int)TICKS_TO_OFFSET(tx)); 698 705 return scheduleStateTransition(ePS_Stopped, tx); 699 706 } … … 707 714 } 708 715 debugOutput(DEBUG_LEVEL_VERBOSE,"for %s SP (%p)\n", ePTToString(getType()), this); 709 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011lu\n", m_handler->getCycleTimerTicks()); 710 debugOutput(DEBUG_LEVEL_VERBOSE," Stop at : %011llu (%u)\n", tx, TICKS_TO_CYCLES(tx)); 716 uint64_t now = m_handler->getCycleTimerTicks(); 717 debugOutput(DEBUG_LEVEL_VERBOSE," Now : %011llu (%03us %04uc %04ut)\n", 718 now, 719 (unsigned int)TICKS_TO_SECS(now), 720 (unsigned int)TICKS_TO_CYCLES(now), 721 (unsigned int)TICKS_TO_OFFSET(now)); 722 debugOutput(DEBUG_LEVEL_VERBOSE," Stop at : %011llu (%03us %04uc %04ut)\n", 723 tx, 724 (unsigned int)TICKS_TO_SECS(tx), 725 (unsigned int)TICKS_TO_CYCLES(tx), 726 (unsigned int)TICKS_TO_OFFSET(tx)); 711 727 return scheduleStateTransition(ePS_WaitingForStreamDisable, tx); 712 728 } branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.h
r720 r721 110 110 bool isDryRunning() 111 111 {return m_state == ePS_DryRunning;}; 112 bool isStopped() 113 {return m_state == ePS_Stopped;}; 112 114 113 115 // these schedule and wait for the state transition … … 127 129 bool init(); 128 130 bool prepare(); 129 130 ///> stop the SP from running or dryrunning131 bool stop();132 131 133 132 public: // constructor/destructor branches/ppalmers-streaming/src/libstreaming/StreamProcessorManager.cpp
r720 r721 268 268 // the received frames will all be presented to the SP 269 269 debugOutput( DEBUG_LEVEL_VERBOSE, "Finding minimal sync delay...\n"); 270 int max_of_min_delay =0;271 int min_delay =0;270 int max_of_min_delay = 0; 271 int min_delay = 0; 272 272 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 273 273 it != m_ReceiveProcessors.end(); 274 274 ++it ) { 275 min_delay =(*it)->getMaxFrameLatency();276 if(min_delay >max_of_min_delay) max_of_min_delay=min_delay;275 min_delay = (*it)->getMaxFrameLatency(); 276 if(min_delay > max_of_min_delay) max_of_min_delay = min_delay; 277 277 } 278 278 … … 459 459 assert(m_isoManager); 460 460 461 debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for all StreamProcessors to prepare to stop...\n"); 462 // Most stream processors can just stop without special treatment. However, some 463 // (like the MOTU) need to do a few things before it's safe to turn off the iso 464 // handling. 461 debugOutput( DEBUG_LEVEL_VERBOSE, " scheduling stop for all SP's...\n"); 462 463 // switch SP's over to the dry-running state 465 464 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 466 465 it != m_ReceiveProcessors.end(); 467 466 ++it ) { 468 if(!(*it)->stop()) { 469 debugError("Could not stop SP %p", (*it)); 467 if(!(*it)->scheduleStopRunning(-1)) { 468 debugError("%p->scheduleStopRunning(-1) failed\n", *it); 469 return false; 470 470 } 471 471 } … … 473 473 it != m_TransmitProcessors.end(); 474 474 ++it ) { 475 if(!(*it)->stop()) { 476 debugError("Could not stop SP %p", (*it)); 477 } 475 if(!(*it)->scheduleStopRunning(-1)) { 476 debugError("%p->scheduleStopRunning(-1) failed\n", *it); 477 return false; 478 } 479 } 480 // wait for the SP's to get into the dry-running state 481 int cnt = 200; 482 bool ready = false; 483 while (!ready && cnt) { 484 ready = true; 485 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 486 it != m_ReceiveProcessors.end(); 487 ++it ) { 488 ready &= ((*it)->isDryRunning() || (*it)->isStopped()); 489 } 490 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 491 it != m_TransmitProcessors.end(); 492 ++it ) { 493 ready &= ((*it)->isDryRunning() || (*it)->isStopped()); 494 } 495 usleep(125); 496 cnt--; 497 } 498 if(cnt==0) { 499 debugOutput(DEBUG_LEVEL_VERBOSE, " Timeout waiting for the SP's to start dry-running\n"); 500 return false; 501 } 502 503 // switch SP's over to the stopped state 504 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 505 it != m_ReceiveProcessors.end(); 506 ++it ) { 507 if(!(*it)->scheduleStopDryRunning(-1)) { 508 debugError("%p->scheduleStopDryRunning(-1) failed\n", *it); 509 return false; 510 } 511 } 512 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 513 it != m_TransmitProcessors.end(); 514 ++it ) { 515 if(!(*it)->scheduleStopDryRunning(-1)) { 516 debugError("%p->scheduleStopDryRunning(-1) failed\n", *it); 517 return false; 518 } 519 } 520 // wait for the SP's to get into the running state 521 cnt = 200; 522 ready = false; 523 while (!ready && cnt) { 524 ready = true; 525 for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 526 it != m_ReceiveProcessors.end(); 527 ++it ) { 528 ready &= (*it)->isStopped(); 529 } 530 for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 531 it != m_TransmitProcessors.end(); 532 ++it ) { 533 ready &= (*it)->isStopped(); 534 } 535 usleep(125); 536 cnt--; 537 } 538 if(cnt==0) { 539 debugOutput(DEBUG_LEVEL_VERBOSE, " Timeout waiting for the SP's to stop\n"); 540 return false; 478 541 } 479 542 … … 504 567 } 505 568 } 506 507 569 return true; 508 570 }