Changeset 707

Show
Ignore:
Timestamp:
11/04/07 09:19:44 (13 years ago)
Author:
ppalmers
Message:

- code cleanup
- make transmit handler AMDTP compliant (don't send too much in advance)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ppalmers-streaming/src/debugmodule/debugmodule.cpp

    r698 r707  
    428428    for (unsigned int i=0; i<BACKLOG_MB_BUFFERS;i++) { 
    429429        unsigned int idx=(i+bl_mb_inbuffer)%BACKLOG_MB_BUFFERS; 
     430        fputs("BL: ", stderr); 
    430431        fputs(bl_mb_buffers[idx], stderr); 
    431432    } 
    432     fprintf(stderr, "\n"); 
     433    fprintf(stderr, "BL: \n"); 
    433434 
    434435    fprintf(stderr, "=====================================================\n"); 
     
    454455        if (lines_to_skip-- < 0) { 
    455456            unsigned int idx=(i+bl_mb_inbuffer)%BACKLOG_MB_BUFFERS; 
     457            fputs("BL: ", stderr); 
    456458            fputs(bl_mb_buffers[idx], stderr); 
    457459        } 
    458460    } 
    459     fprintf(stderr, "\n"); 
     461    fprintf(stderr, "BL: \n"); 
    460462 
    461463    fprintf(stderr, "=====================================================\n"); 
  • branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpStreamProcessor.cpp

    r705 r707  
    3131 
    3232// in ticks 
    33 #define TRANSMIT_TRANSFER_DELAY 9000U 
    34 // the number of cycles to send a packet in advance of it's timestamp 
    35 #define TRANSMIT_ADVANCE_CYCLES 4U 
     33// as per AMDTP2.1: 
     34// 354.17us + 125us @ 24.576ticks/usec = 11776.08192 ticks 
     35#define DEFAULT_TRANSFER_DELAY (11776U) 
     36 
     37#define TRANSMIT_TRANSFER_DELAY DEFAULT_TRANSFER_DELAY 
    3638 
    3739namespace Streaming { 
    38  
    39 IMPL_DEBUG_MODULE( AmdtpTransmitStreamProcessor, AmdtpTransmitStreamProcessor, DEBUG_LEVEL_VERBOSE ); 
    40 IMPL_DEBUG_MODULE( AmdtpReceiveStreamProcessor, AmdtpReceiveStreamProcessor, DEBUG_LEVEL_VERBOSE ); 
    41  
    4240 
    4341/* transmit */ 
     
    4543        : TransmitStreamProcessor(port, framerate), m_dimension(dimension) 
    4644        , m_last_timestamp(0), m_dbc(0), m_ringbuffer_size_frames(0) 
    47 
    48  
    49 
    50  
    51 AmdtpTransmitStreamProcessor::~AmdtpTransmitStreamProcessor() { 
    52  
    53 
     45{} 
    5446 
    5547/** 
     
    6658        return false; 
    6759    } 
    68  
    6960    return true; 
    70 } 
    71  
    72 void AmdtpTransmitStreamProcessor::setVerboseLevel(int l) { 
    73     setDebugLevel(l); 
    74     TransmitStreamProcessor::setVerboseLevel(l); 
    7561} 
    7662 
     
    7965                  unsigned char *tag, unsigned char *sy, 
    8066                  int cycle, unsigned int dropped, unsigned int max_length) { 
    81      
    8267    struct iec61883_packet *packet = (struct iec61883_packet *) data; 
    83      
     68 
    8469    if (cycle<0) { 
    8570        debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,"Xmit handler for cycle %d, (running=%d)\n", 
    8671            cycle, m_running); 
    87          
    8872        *tag = 0; 
    8973        *sy = 0; 
    9074        *length=0; 
    9175        return RAW1394_ISO_OK; 
    92      
    93     } 
    94      
     76    } 
     77 
    9578    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE,"Xmit handler for cycle %d, (running=%d)\n", 
    9679        cycle, m_running); 
    97      
     80 
    9881    m_last_cycle=cycle; 
    9982 
     
    139122            cycle, now_cycles); 
    140123    } 
     124 
     125    // keep track of the lag 
     126    m_PacketStat.mark(cycle_diff); 
    141127#endif 
    142128 
     
    150136    } 
    151137 
    152     uint64_t ts_head; 
    153138    signed int fc; 
    154139    uint64_t presentation_time; 
     
    156141    int cycles_until_presentation; 
    157142 
    158     const int min_cycles_beforehand = 2;  // FIXME: should become a define 
    159     const int max_cycles_beforehand = 15; // FIXME: should become a define 
     143    uint64_t transmit_at_time; 
     144    unsigned int transmit_at_cycle; 
     145    int cycles_until_transmit; 
     146 
     147    // FIXME: should become a define 
     148    // the absolute minimum number of cycles we want to transmit 
     149    // a packet ahead of the presentation time. The nominal time 
     150    // the packet is transmitted ahead of the presentation time is 
     151    // given by TRANSMIT_TRANSFER_DELAY (in ticks), but in case we 
     152    // are too late for that, this constant defines how late we can 
     153    // be. 
     154    const int min_cycles_before_presentation = 1; 
     155    // FIXME: should become a define 
     156    // the absolute maximum number of cycles we want to transmit 
     157    // a packet ahead of the ideal transmit time. The nominal time 
     158    // the packet is transmitted ahead of the presentation time is 
     159    // given by TRANSMIT_TRANSFER_DELAY (in ticks), but we can send 
     160    // packets early if we want to. (not completely according to spec) 
     161    const int max_cycles_to_transmit_early = 1; 
    160162 
    161163    if( !m_running || !m_data_buffer->isEnabled() ) { 
     
    174176    ffado_timestamp_t ts_head_tmp; 
    175177    m_data_buffer->getBufferHeadTimestamp(&ts_head_tmp, &fc); // thread safe 
    176     ts_head=(uint64_t)ts_head_tmp; 
    177  
    178     // first calculate the presentation time of the samples 
    179     presentation_time = addTicks(ts_head, TRANSMIT_TRANSFER_DELAY); 
     178 
     179    // the timestamp gives us the time at which we want the sample block 
     180    // to be output by the device 
     181    presentation_time=(uint64_t)ts_head_tmp; 
     182 
     183    // now we calculate the time when we have to transmit the sample block 
     184    transmit_at_time = substractTicks(presentation_time, TRANSMIT_TRANSFER_DELAY); 
    180185 
    181186    // calculate the cycle this block should be presented in 
     
    184189    presentation_cycle = (unsigned int)(TICKS_TO_CYCLES( presentation_time )); 
    185190 
     191    // calculate the cycle this block should be transmitted in 
     192    transmit_at_cycle = (unsigned int)(TICKS_TO_CYCLES( transmit_at_time )); 
     193 
    186194    // we can check whether this cycle is within the 'window' we have 
    187195    // to send this packet. 
    188196    // first calculate the number of cycles left before presentation time 
    189197    cycles_until_presentation = diffCycles( presentation_cycle, cycle ); 
     198 
     199    // we can check whether this cycle is within the 'window' we have 
     200    // to send this packet. 
     201    // first calculate the number of cycles left before presentation time 
     202    cycles_until_transmit = diffCycles( transmit_at_cycle, cycle ); 
    190203 
    191204    // two different options: 
     
    196209    //      => determine whether we have to send them in this packet 
    197210    if (fc < (signed int)m_syt_interval) { 
     211        m_PacketStat.signal(0); 
    198212        // not enough frames in the buffer, 
    199213        debugOutput(DEBUG_LEVEL_VERBOSE,  
    200                     "Insufficient frames: CY=%04u, PTC=%04u, CUP=%04d\n", 
    201                     cycle, presentation_cycle, cycles_until_presentation); 
     214                    "Insufficient frames: N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", 
     215                    fc, cycle, transmit_at_cycle, cycles_until_transmit); 
    202216        // we can still postpone the queueing of the packets 
    203217        // if we are far enough ahead of the presentation time 
    204         if( cycles_until_presentation <= min_cycles_beforehand ) { 
    205             // we have an invalid timestamp or we are too late 
     218        if( cycles_until_presentation <= min_cycles_before_presentation ) { 
     219            m_PacketStat.signal(1); 
     220            // we are too late 
    206221            // meaning that we in some sort of xrun state 
    207222            // signal xrun situation ??HERE?? 
    208223            m_xruns++; 
     224            // we send an empty packet on this cycle 
     225            goto send_empty_packet; // UGLY but effective 
    209226        } else { 
     227            m_PacketStat.signal(2); 
    210228            // there is still time left to send the packet 
     229            // we want the system to give this packet another go 
     230//             goto try_packet_again; // UGLY but effective 
     231            // unfortunatly the try_again doesn't work very well, 
     232            // so we'll have to either usleep(one cycle) and goto try_block_of_frames 
     233             
     234            // or just fill this with an empty packet 
     235            // if we have to do this too often, the presentation time will 
     236            // get too close and we're in trouble 
     237            goto send_empty_packet; // UGLY but effective 
    211238        } 
    212         // in any case we send an empty packet on this cycle 
    213         goto send_empty_packet; // UGLY but effective 
    214239    } else { 
     240        m_PacketStat.signal(3); 
    215241        // there are enough frames, so check the time they are intended for 
    216242        // all frames have a certain 'time window' in which they can be sent 
     
    229255        //         get next block of frames and repeat 
    230256         
    231         if (cycles_until_presentation <= min_cycles_beforehand) { 
     257        if (cycles_until_transmit <= max_cycles_to_transmit_early) { 
     258            m_PacketStat.signal(4); 
     259            // it's time send the packet 
     260            goto send_packet; // UGLY but effective 
     261        } else if (cycles_until_transmit < 0) { 
    232262            // we are too late 
    233263            debugOutput(DEBUG_LEVEL_VERBOSE,  
    234                         "Too late: CY=%04u, PTC=%04u, CUP=%04d, TSP=%011llu (%04u)\n", 
     264                        "Too late: CY=%04u, TC=%04u, CUT=%04d, TSP=%011llu (%04u)\n", 
    235265                        cycle, 
    236                         presentation_cycle, cycles_until_presentation
     266                        transmit_at_cycle, cycles_until_transmit
    237267                        presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 
    238             // remove the samples 
    239             m_data_buffer->dropFrames(m_syt_interval); 
    240              
    241             // signal some xrun situation ??HERE?? 
    242             m_xruns++; 
    243              
    244             // try a new block of frames 
    245             goto try_block_of_frames; // UGLY but effective 
    246         } else if (cycles_until_presentation >= max_cycles_beforehand) { 
     268 
     269            // however, if we can send this sufficiently before the presentation 
     270            // time, it could be harmless. 
     271            // NOTE: dangerous since the device has no way of reporting that it didn't get 
     272            //       this packet on time. 
     273            if ( cycles_until_presentation <= min_cycles_before_presentation ) { 
     274                m_PacketStat.signal(5); 
     275                // we are not that late and can still try to transmit the packet 
     276                goto send_packet; // UGLY but effective 
     277            } else { // definitely too late 
     278                m_PacketStat.signal(6); 
     279                // remove the samples 
     280                m_data_buffer->dropFrames(m_syt_interval); 
     281                // signal some xrun situation ??HERE?? 
     282                m_xruns++; 
     283                // try a new block of frames 
     284                goto try_block_of_frames; // UGLY but effective 
     285            } 
     286        } else { 
     287            m_PacketStat.signal(7); 
    247288            debugOutput(DEBUG_LEVEL_VERY_VERBOSE,  
    248                         "Too early: CY=%04u, PTC=%04u, CUP=%04d, TSP=%011llu (%04u)\n", 
     289                        "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", 
    249290                        cycle, 
    250                         presentation_cycle, cycles_until_presentation, 
     291                        transmit_at_cycle, cycles_until_transmit, 
     292                        transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), 
    251293                        presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 
     294            #ifdef DEBUG 
     295            if (cycles_until_transmit > max_cycles_to_transmit_early + 1) { 
     296                debugOutput(DEBUG_LEVEL_VERBOSE,  
     297                            "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", 
     298                            cycle, 
     299                            transmit_at_cycle, cycles_until_transmit, 
     300                            transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), 
     301                            presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 
     302            } 
     303            #endif 
    252304            // we are too early, send only an empty packet 
    253305            goto send_empty_packet; // UGLY but effective 
    254         } else { 
    255             // send the packet 
    256             goto send_packet; // UGLY but effective 
    257306        } 
    258307    } 
    259      
    260     debugError("Should never reach this code!\n"); 
     308 
     309    debugFatal("Should never reach this code!\n"); 
    261310    return RAW1394_ISO_ERROR; 
    262      
     311 
    263312send_empty_packet: 
    264313    debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT NONE: CY=%04u, TSP=%011llu (%04u)\n", 
     
    279328        } 
    280329 
    281         debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT DATA: CY=%04u, TSH=%011llu (%04u), TSP=%011llu (%04u)\n", 
     330        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT DATA: CY=%04u, TST=%011llu (%04u), TSP=%011llu (%04u)\n", 
    282331            cycle, 
    283             ts_head, (unsigned int)TICKS_TO_CYCLES(ts_head), 
     332            transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), 
    284333            presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 
    285334 
    286335        return RAW1394_ISO_OK; 
    287336    } 
     337 
     338// the ISO AGAIN does not work very well... 
     339// try_packet_again: 
     340//  
     341//     debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT RETRY: CY=%04u, TSP=%011llu (%04u)\n", 
     342//             cycle, 
     343//             presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 
     344//     return RAW1394_ISO_AGAIN; 
     345 
    288346    // else: 
    289     debugError("This is impossible, since we checked the buffer size before!\n"); 
     347    debugFatal("This is impossible, since we checked the buffer size before!\n"); 
    290348    return RAW1394_ISO_ERROR; 
    291349} 
     
    549607 
    550608bool AmdtpTransmitStreamProcessor::prepareForStart() { 
    551  
    552609    return true; 
    553610} 
     
    589646bool AmdtpTransmitStreamProcessor::putFrames(unsigned int nbframes, int64_t ts) { 
    590647    m_PeriodStat.mark(m_data_buffer->getBufferFill()); 
    591  
    592648    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "AmdtpTransmitStreamProcessor::putFrames(%d, %llu)\n", nbframes, ts); 
    593649 
     
    601657 
    602658bool AmdtpTransmitStreamProcessor::putFramesDry(unsigned int nbframes, int64_t ts) { 
     659    m_PeriodStat.mark(m_data_buffer->getBufferFill()); 
    603660    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "AmdtpTransmitStreamProcessor::putFramesDry(%d, %llu)\n", nbframes, ts); 
    604661 
     
    844901 
    845902AmdtpReceiveStreamProcessor::AmdtpReceiveStreamProcessor(int port, int framerate, int dimension) 
    846     : ReceiveStreamProcessor(port, framerate), m_dimension(dimension), m_last_timestamp(0), m_last_timestamp2(0) { 
    847  
    848 
    849  
    850 AmdtpReceiveStreamProcessor::~AmdtpReceiveStreamProcessor() { 
    851  
    852 
     903    : ReceiveStreamProcessor(port, framerate), m_dimension(dimension), m_last_timestamp(0), m_last_timestamp2(0)  
     904{} 
    853905 
    854906bool AmdtpReceiveStreamProcessor::init() { 
     
    861913        return false; 
    862914    } 
    863  
    864915    return true; 
    865916} 
     
    882933 
    883934    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"ch%2u: CY=%4u, SYT=%08X (%4ucy + %04uticks) (running=%d)\n", 
    884         channel, cycle,ntohs(packet->syt), 
     935        channel, cycle, ntohs(packet->syt), 
    885936        CYCLE_TIMER_GET_CYCLES(ntohs(packet->syt)), CYCLE_TIMER_GET_OFFSET(ntohs(packet->syt)), 
    886937        m_running); 
     
    934985        #ifdef DEBUG_OFF 
    935986        if((cycle % 1000) == 0) { 
     987            uint32_t now=m_handler->getCycleTimer(); 
    936988            uint32_t syt = (uint32_t)ntohs(packet->syt); 
    937             uint32_t now=m_handler->getCycleTimer(); 
    938989            uint32_t now_ticks=CYCLE_TIMER_TO_TICKS(now); 
    939990 
     
    9521003        #endif 
    9531004 
     1005        #ifdef DEBUG 
     1006            // keep track of the lag 
     1007            uint32_t now=m_handler->getCycleTimer(); 
     1008            int32_t diff = diffCycles( cycle,  ((int)CYCLE_TIMER_GET_CYCLES(now)) ); 
     1009            m_PacketStat.mark(diff); 
     1010        #endif 
     1011 
    9541012        //=> process the packet 
    9551013        // add the data payload to the ringbuffer 
     
    9871045void AmdtpReceiveStreamProcessor::dumpInfo() { 
    9881046    StreamProcessor::dumpInfo(); 
    989 } 
    990  
    991 void AmdtpReceiveStreamProcessor::setVerboseLevel(int l) { 
    992     setDebugLevel(l); 
    993     ReceiveStreamProcessor::setVerboseLevel(l); 
    9941047} 
    9951048 
     
    11701223 
    11711224bool AmdtpReceiveStreamProcessor::getFrames(unsigned int nbframes, int64_t ts) { 
     1225    m_PeriodStat.mark(m_data_buffer->getBufferFill()); 
    11721226 
    11731227    // ask the buffer to process nbframes of frames 
     
    11801234 
    11811235bool AmdtpReceiveStreamProcessor::getFramesDry(unsigned int nbframes, int64_t ts) { 
     1236    m_PeriodStat.mark(m_data_buffer->getBufferFill()); 
    11821237    int frames_to_ditch=(int)(nbframes); 
    11831238    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "stream (%p): dry run %d frames (@ ts=%lld)\n", 
  • branches/ppalmers-streaming/src/libstreaming/amdtp/AmdtpStreamProcessor.h

    r705 r707  
    7979     */ 
    8080    AmdtpTransmitStreamProcessor(int port, int framerate, int dimension); 
    81  
    82     virtual ~AmdtpTransmitStreamProcessor(); 
     81    virtual ~AmdtpTransmitStreamProcessor() {}; 
    8382 
    8483    enum raw1394_iso_disposition 
     
    111110 
    112111    int getMinimalSyncDelay(); 
    113  
    114     void setVerboseLevel(int l); 
    115112 
    116113protected: 
     
    150147 
    151148    unsigned int m_ringbuffer_size_frames; 
    152  
    153     DECLARE_DEBUG_MODULE; 
    154  
    155149}; 
    156150/*! 
     
    174168     */ 
    175169    AmdtpReceiveStreamProcessor(int port, int framerate, int dimension); 
    176  
    177     virtual ~AmdtpReceiveStreamProcessor(); 
     170    virtual ~AmdtpReceiveStreamProcessor() {}; 
    178171 
    179172    enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length, 
     
    207200    int getMinimalSyncDelay(); 
    208201 
    209     void setVerboseLevel(int l); 
    210  
    211202protected: 
    212203 
     
    224215    uint64_t m_last_timestamp2; /// last timestamp (in ticks) 
    225216    uint64_t m_last_timestamp_at_period_ticks; 
    226  
    227     DECLARE_DEBUG_MODULE; 
    228  
    229217}; 
    230218 
  • branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.cpp

    r706 r707  
    8484    m_PeriodStat.dumpInfo(); 
    8585    m_PacketStat.dumpInfo(); 
    86     m_WakeupStat.dumpInfo(); 
    87  
     86//     m_WakeupStat.dumpInfo(); 
    8887} 
    8988 
     
    293292    IsoStream::setVerboseLevel(l); 
    294293    PortManager::setVerboseLevel(l); 
    295  
    296294} 
    297295 
     
    334332 
    335333bool TransmitStreamProcessor::canClientTransferFrames(unsigned int nbframes) { 
     334    bool can_transfer; 
    336335    // there has to be enough space to put the frames in 
    337     return m_data_buffer->getBufferSize() - m_data_buffer->getFrameCounter() > nbframes; 
    338 
    339  
    340  
    341 
     336    can_transfer = m_data_buffer->getBufferSize() - m_data_buffer->getFrameCounter() > nbframes; 
     337    // or the buffer is transparent 
     338    can_transfer |= m_data_buffer->isTransparent(); 
     339    return can_transfer; 
     340
     341 
     342 
     343
  • branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.h

    r706 r707  
    111111    Util::TimestampedBuffer *m_data_buffer; 
    112112 
     113    StreamStatistics m_PacketStat; 
     114    StreamStatistics m_PeriodStat; 
     115 
     116    StreamStatistics m_WakeupStat; 
     117 
    113118protected: // SPM related 
    114119    void setManager(StreamProcessorManager *manager) {m_manager=manager;}; 
     
    130135    unsigned int m_cycle_to_enable_at; 
    131136 
    132     StreamStatistics m_PacketStat; 
    133     StreamStatistics m_PeriodStat; 
    134  
    135     StreamStatistics m_WakeupStat; 
    136137 
    137138 
  • branches/ppalmers-streaming/src/libstreaming/StreamProcessorManager.cpp

    r705 r707  
    4141namespace Streaming { 
    4242 
    43 IMPL_DEBUG_MODULE( StreamProcessorManager, StreamProcessorManager, DEBUG_LEVEL_NORMAL ); 
     43IMPL_DEBUG_MODULE( StreamProcessorManager, StreamProcessorManager, DEBUG_LEVEL_VERBOSE ); 
    4444 
    4545StreamProcessorManager::StreamProcessorManager(unsigned int period, unsigned int nb_buffers) 
     
    391391    } 
    392392 
    393     debugOutput( DEBUG_LEVEL_VERBOSE, " sync at TS=%011llu...\n", m_time_of_transfer); 
     393    debugOutput( DEBUG_LEVEL_VERBOSE, " sync at TS=%011llu (%03us %04uc %04ut)...\n",  
     394        m_time_of_transfer, 
     395        (unsigned int)TICKS_TO_SECS(m_time_of_transfer), 
     396        (unsigned int)TICKS_TO_CYCLES(m_time_of_transfer), 
     397        (unsigned int)TICKS_TO_OFFSET(m_time_of_transfer)); 
    394398    // FIXME: xruns can screw up the framecounter accounting. do something more sane here 
    395399    resetXrunCounters(); 
     
    450454    while(nb_dryrun_cycles--) { 
    451455        waitForPeriod(); 
     456        m_TransmitProcessors.at(0)->m_PacketStat.dumpInfo(); 
    452457        no_xrun = dryRun(); // dry run both receive and xmit 
    453458 
    454         if (no_xrun) { 
     459        if (!no_xrun) { 
    455460            debugOutput( DEBUG_LEVEL_VERBOSE, " This dry-run was not xrun free...\n" ); 
    456461            resetXrunCounters(); 
     
    826831    debugOutput( DEBUG_LEVEL_VERBOSE, "Handling Xrun ...\n"); 
    827832 
     833    dumpInfo(); 
     834 
    828835    /* 
    829836     * Reset means: 
     
    892899        } 
    893900 
     901        if(xrun_occurred) break; 
     902 
    894903        // check if we were waked up too soon 
    895904        time_till_next_period=m_SyncSource->getTimeUntilNextPeriodSignalUsecs(); 
     
    941950 
    942951        // if this is true, a xrun will occur 
    943         xrun_occurred |= !((*it)->canClientTransferFrames(m_period))
     952        xrun_occurred |= !((*it)->canClientTransferFrames(m_period)) && (*it)->isEnabled()
    944953 
    945954#ifdef DEBUG 
     
    948957            (*it)->dumpInfo(); 
    949958        } 
    950         if (!((*it)->canClientTransferFrames(m_period))) { 
     959        if (!((*it)->canClientTransferFrames(m_period)) && (*it)->isEnabled()) { 
    951960            debugWarning("Xrun on RECV SP %p due to buffer xrun\n",*it); 
    952961            (*it)->dumpInfo(); 
     
    962971 
    963972        // if this is true, a xrun will occur 
    964         xrun_occurred |= !((*it)->canClientTransferFrames(m_period))
     973        xrun_occurred |= !((*it)->canClientTransferFrames(m_period)) && (*it)->isEnabled()
    965974 
    966975#ifdef DEBUG 
     
    968977            debugWarning("Xrun on XMIT SP %p due to ISO xrun\n",*it); 
    969978        } 
    970         if (!((*it)->canClientTransferFrames(m_period))) { 
     979        if (!((*it)->canClientTransferFrames(m_period)) && (*it)->isEnabled()) { 
    971980            debugWarning("Xrun on XMIT SP %p due to buffer xrun\n",*it); 
    972981        } 
     
    990999 
    9911000    debugOutput( DEBUG_LEVEL_VERBOSE, "Transferring period...\n"); 
    992  
    993     if (!transfer(StreamProcessor::E_Receive)) return false; 
    994     if (!transfer(StreamProcessor::E_Transmit)) return false; 
    995  
    996     return true; 
     1001    bool retval=true; 
     1002    retval &= dryRun(StreamProcessor::E_Receive); 
     1003    retval &= dryRun(StreamProcessor::E_Transmit); 
     1004    return retval; 
    9971005} 
    9981006 
     
    10081016bool StreamProcessorManager::transfer(enum StreamProcessor::EProcessorType t) { 
    10091017    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); 
    1010  
     1018    bool retval = true; 
    10111019    // a static cast could make sure that there is no performance 
    10121020    // penalty for the virtual functions (to be checked) 
    10131021    if (t==StreamProcessor::E_Receive) { 
    1014          
    10151022        // determine the time at which we want reception to start 
    10161023        float rate=m_SyncSource->getTicksPerFrame(); 
     
    10351042                    debugOutput(DEBUG_LEVEL_VERBOSE,"could not getFrames(%u, %11llu) from stream processor (%p)\n", 
    10361043                            m_period, m_time_of_transfer,*it); 
    1037                     return false; // buffer underrun 
    1038             } 
    1039  
     1044                retval &= false; // buffer underrun 
     1045            } 
    10401046        } 
    10411047    } else { 
     
    10551061                debugOutput(DEBUG_LEVEL_VERBOSE, "could not putFrames(%u,%llu) to stream processor (%p)\n", 
    10561062                        m_period, transmit_timestamp, *it); 
    1057                 return false; // buffer overrun 
    1058             } 
    1059  
    1060         } 
    1061     } 
    1062  
    1063     return true; 
     1063                retval &= false; // buffer underrun 
     1064            } 
     1065 
     1066        } 
     1067    } 
     1068    return retval; 
    10641069} 
    10651070 
     
    10751080bool StreamProcessorManager::dryRun() { 
    10761081    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Dry-running period...\n"); 
    1077     if (!dryRun(StreamProcessor::E_Receive)) return false; 
    1078     if (!dryRun(StreamProcessor::E_Transmit)) return false; 
    1079     return true; 
     1082    bool retval=true; 
     1083    retval &= dryRun(StreamProcessor::E_Receive); 
     1084    retval &= dryRun(StreamProcessor::E_Transmit); 
     1085    return retval; 
    10801086} 
    10811087 
     
    10901096 
    10911097bool StreamProcessorManager::dryRun(enum StreamProcessor::EProcessorType t) { 
    1092     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); 
    1093  
     1098    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Dry-running period...\n"); 
     1099    bool retval = true; 
    10941100    // a static cast could make sure that there is no performance 
    10951101    // penalty for the virtual functions (to be checked) 
    10961102    if (t==StreamProcessor::E_Receive) { 
    1097          
    10981103        // determine the time at which we want reception to start 
    10991104        float rate=m_SyncSource->getTicksPerFrame(); 
     
    11181123                    debugOutput(DEBUG_LEVEL_VERBOSE,"could not getFrames(%u, %11llu) from stream processor (%p)\n", 
    11191124                            m_period, m_time_of_transfer,*it); 
    1120                     return false; // buffer underrun 
     1125                retval &= false; // buffer underrun 
    11211126            } 
    11221127 
     
    11381143                debugOutput(DEBUG_LEVEL_VERBOSE, "could not putFrames(%u,%llu) to stream processor (%p)\n", 
    11391144                        m_period, transmit_timestamp, *it); 
    1140                 return false; // buffer overrun 
    1141             } 
    1142  
    1143         } 
    1144     } 
    1145  
    1146     return true; 
     1145                retval &= false; // buffer underrun 
     1146            } 
     1147 
     1148        } 
     1149    } 
     1150    return retval; 
    11471151} 
    11481152 
  • branches/ppalmers-streaming/src/libstreaming/util/cycletimer.h

    r705 r707  
    156156    return x; 
    157157 
     158} 
     159 
     160/** 
     161 * @brief Computes a difference between cycles 
     162 * 
     163 * This function computes a difference between cycles 
     164 * such that it respects wrapping (at 8000 cycles). 
     165 * 
     166 * See diffTicks 
     167 * 
     168 * @param x First cycle value 
     169 * @param y Second cycle value 
     170 * @return the difference x-y, unwrapped 
     171 */ 
     172static inline int diffCycles(unsigned int x, unsigned int y) { 
     173    int diff = x - y; 
     174 
     175    // the maximal difference we allow (64secs) 
     176    const int max=CYCLES_PER_SECOND/2; 
     177 
     178    if(diff > max) { 
     179        diff -= CYCLES_PER_SECOND; 
     180    } else if (diff < -max) { 
     181        diff += CYCLES_PER_SECOND; 
     182    } 
     183 
     184    return diff; 
    158185} 
    159186 
     
    406433} 
    407434 
    408 /** 
    409  * @brief Computes a difference between cycles 
    410  * 
    411  * This function computes a difference between cycles 
    412  * such that it respects wrapping (at 8000 cycles). 
    413  * 
    414  * See diffTicks 
    415  * 
    416  * @param x First cycle value 
    417  * @param y Second cycle value 
    418  * @return the difference x-y, unwrapped 
    419  */ 
    420 static inline int diffCycles(unsigned int x, unsigned int y) { 
    421     int diff = x - y; 
    422  
    423     // the maximal difference we allow (64secs) 
    424     const int max=CYCLES_PER_SECOND/2; 
    425  
    426     if(diff > max) { 
    427         diff -= CYCLES_PER_SECOND; 
    428     } else if (diff < -max) { 
    429         diff += CYCLES_PER_SECOND; 
    430     } 
    431  
    432     return diff; 
    433 } 
    434  
    435435#endif // __CYCLETIMER_H__ 
  • branches/ppalmers-streaming/src/libstreaming/util/IsoHandlerManager.cpp

    r705 r707  
    3030#include <assert.h> 
    3131 
    32 #define MINIMUM_INTERRUPTS_PER_PERIOD  2
     32#define MINIMUM_INTERRUPTS_PER_PERIOD  4
    3333#define PACKETS_PER_INTERRUPT          4U 
    3434 
     
    450450        // event buffers 
    451451 
     452        // FIXME: latency spoiler 
    452453        // every irq_interval packets an interrupt will occur. that is when 
    453454        // buffers get transfered, meaning that we should have at least some 
  • branches/ppalmers-streaming/src/libutil/StreamStatistics.cpp

    r445 r707  
    2626 
    2727namespace Streaming { 
     28IMPL_DEBUG_MODULE( StreamStatistics, StreamStatistics, DEBUG_LEVEL_VERBOSE ); 
    2829 
    2930StreamStatistics::StreamStatistics() 
     
    3536    , m_sum(0) 
    3637{ 
    37  
    38 
    39  
    40  
    41 StreamStatistics::~StreamStatistics() 
    42 
     38    reset(); 
    4339} 
    4440 
     
    5147} 
    5248 
     49void StreamStatistics::signal(unsigned int val) { 
     50    if (val <= MAX_SIGNAL_VALUE) { 
     51        m_signalled[val]++; 
     52    } 
     53} 
     54 
    5355void StreamStatistics::dumpInfo() { 
    54      printf("--- Stats for %s: min=%ld avg=%f max=%ld cnt=%ld sum=%ld\n",m_name.c_str(), 
    55          m_min,m_average,m_max,m_count,m_sum); 
     56    debugOutputShort( DEBUG_LEVEL_VERBOSE,  
     57                      "--- Stats for %s: min=%ld avg=%f max=%ld cnt=%ld sum=%ld\n", 
     58                      m_name.c_str(), m_min, m_average, m_max, m_count, m_sum); 
     59    debugOutputShort( DEBUG_LEVEL_VERBOSE, "    Signal stats\n"); 
     60    for (unsigned int i=0;i <= MAX_SIGNAL_VALUE; i++) { 
     61        debugOutputShort(DEBUG_LEVEL_VERBOSE,  
     62                         "     Stats for %3u: %8u\n", 
     63                         i, m_signalled[i]); 
     64    } 
    5665} 
    5766 
     
    6271    m_max=0; 
    6372    m_sum=0; 
     73 
     74    for (unsigned int i=0;i <= MAX_SIGNAL_VALUE; i++) { 
     75        m_signalled[i]=0; 
     76    } 
    6477} 
    6578 
  • branches/ppalmers-streaming/src/libutil/StreamStatistics.h

    r445 r707  
    2727#include <string> 
    2828 
     29#include "debugmodule/debugmodule.h" 
     30 
     31#define MAX_SIGNAL_VALUE 7 
    2932namespace Streaming { 
    3033 
     
    3336    StreamStatistics(); 
    3437 
    35     ~StreamStatistics()
     38    ~StreamStatistics() {}
    3639 
    3740    void setName(std::string n) {m_name=n;}; 
     
    5053    long m_sum; 
    5154 
     55    // some tools to do run statistics 
     56    // will keep a histogram of the number of times a certain value 
     57    // is added. 
     58    void signal(unsigned int val); 
     59 
     60    unsigned int m_signalled[MAX_SIGNAL_VALUE+1]; 
     61 
    5262private: 
    53  
     63    DECLARE_DEBUG_MODULE; 
    5464}; 
    5565 
  • branches/ppalmers-streaming/src/libutil/TimestampedBuffer.cpp

    r705 r707  
    501501 
    502502        if(vec[0].len==0) { // this indicates a full event buffer 
    503             debugError("Event buffer overrun in buffer %p\n",this); 
    504             break; 
     503            debugError("Event buffer overrun in buffer %p, fill: %u, bytes2write: %u \n", 
     504                       this, ffado_ringbuffer_read_space(m_event_buffer), bytes2write); 
     505            debugShowBackLog(); 
     506            return false; 
    505507        } 
    506508