Changeset 1031

Show
Ignore:
Timestamp:
04/25/08 09:39:51 (13 years ago)
Author:
ppalmers
Message:

reorganize handler code a bit. prepare to move the cycle timer read calls out of the SP callbacks into the 1394 subsystem. remove bit rot and clean up compiler warnings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r1005 r1031  
    2727#include "ieee1394service.h"  
    2828#include "IsoHandlerManager.h" 
     29 
     30#include "cycletimer.h" 
    2931 
    3032#include "libstreaming/generic/StreamProcessor.h" 
     
    5456    unsigned int skipped = (dropped1 & 0xFFFF0000) >> 16; 
    5557    unsigned int dropped = dropped1 & 0xFFFF; 
    56  
    5758    return xmitHandler->getPacket(data, length, tag, sy, cycle, dropped, skipped); 
    5859} 
     
    8990   , m_max_packet_size( 1024 ) 
    9091   , m_irq_interval( -1 ) 
     92   , m_last_cycle( -1 ) 
    9193   , m_Client( 0 ) 
    9294   , m_speed( RAW1394_ISO_SPEED_400 ) 
     
    108110   , m_max_packet_size( max_packet_size ) 
    109111   , m_irq_interval( irq ) 
     112   , m_last_cycle( -1 ) 
    110113   , m_Client( 0 ) 
    111114   , m_speed( RAW1394_ISO_SPEED_400 ) 
     
    114117#ifdef DEBUG 
    115118   , m_packets ( 0 ) 
     119   , m_dropped( 0 ) 
    116120#endif 
    117121{ 
     
    132136   , m_State( E_Created ) 
    133137#ifdef DEBUG 
    134    , m_packets ( 0 ) 
     138   , m_packets( 0 ) 
     139   , m_dropped( 0 ) 
    135140#endif 
    136141{ 
     
    298303                                            m_speed, m_prebuffers); 
    299304    } 
     305    #ifdef DEBUG 
     306    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Last cycle, dropped.........: %4d, %4u\n", 
     307            m_last_cycle, m_dropped); 
     308    #endif 
     309 
    300310} 
    301311 
    302312void IsoHandler::setVerboseLevel(int l) 
    303313{ 
     314    debugError("setdebuglevel (%p, %d)\n", this, l); 
    304315    setDebugLevel(l); 
    305316} 
     
    345356                    unsigned char channel, unsigned char tag, unsigned char sy, 
    346357                    unsigned int cycle, unsigned int dropped, unsigned int skipped) { 
     358 
     359    unsigned int pkt_ctr = cycle << 12; 
    347360 
    348361    debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, 
     
    355368                     this, getTypeString(), length, m_max_packet_size); 
    356369    } 
     370    if(m_last_cycle == -1) { 
     371        debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %u)\n", getTypeString(), this, cycle); 
     372    } 
    357373    #endif 
     374 
     375    // keep track of dropped cycles 
     376    int dropped_cycles = 0; 
     377    if (m_last_cycle != (int)cycle && m_last_cycle != -1) { 
     378        dropped_cycles = diffCycles(cycle, m_last_cycle) - 1; 
     379        if (dropped_cycles < 0) { 
     380            debugWarning("(%p) dropped < 1 (%d), cycle: %d, last_cycle: %d, dropped: %d, 'skipped'=%u\n",  
     381                        this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
     382        } 
     383        if (dropped_cycles > 0) { 
     384            debugWarning("(%p) dropped %d packets on cycle %u, 'dropped'=%u, 'skipped'=%u, cycle=%d, m_last_cycle=%d\n", 
     385                this, dropped_cycles, cycle, dropped, skipped, cycle, m_last_cycle); 
     386            m_dropped += dropped_cycles; 
     387        } 
     388    } 
     389    m_last_cycle = cycle; 
     390 
     391    // iterate the client if required 
    358392    if(m_Client) { 
    359         enum raw1394_iso_disposition retval = m_Client->putPacket(data, length, channel, tag, sy, cycle, dropped, skipped); 
     393        enum raw1394_iso_disposition retval = m_Client->putPacket(data, length, channel, tag, sy, pkt_ctr, dropped_cycles, skipped); 
    360394        if (retval == RAW1394_ISO_OK) { 
    361395            if (m_dont_exit_iterate_loop) { 
     
    382416                      int cycle, unsigned int dropped, unsigned int skipped) { 
    383417 
     418    unsigned int pkt_ctr; 
     419    if (cycle < 0) { 
     420        pkt_ctr = 0xFFFFFFFF; 
     421    } else { 
     422        pkt_ctr = cycle << 12; 
     423    } 
     424 
    384425    debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, 
    385426                       "sending packet: length=%d, cycle=%d\n", 
    386427                       *length, cycle); 
     428 
    387429    #ifdef DEBUG 
    388430    m_packets++; 
     431    if(m_last_cycle == -1) { 
     432        debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %d)\n", getTypeString(), this, cycle); 
     433    } 
    389434    #endif 
     435 
     436    // keep track of dropped cycles 
     437    int dropped_cycles = 0; 
     438    if (m_last_cycle != cycle && m_last_cycle != -1) { 
     439        dropped_cycles = diffCycles(cycle, m_last_cycle) - 1; 
     440        // correct for skipped packets 
     441        // since those are not dropped, but only delayed 
     442        dropped_cycles -= skipped; 
     443 
     444        #ifdef DEBUG 
     445        if(skipped) { 
     446            debugWarning("(%p) skipped %d cycles, cycle: %d, last_cycle: %d, dropped: %d\n",  
     447                         this, skipped, cycle, m_last_cycle, dropped); 
     448        } 
     449        if (dropped_cycles < 0) {  
     450            debugWarning("(%p) dropped < 1 (%d), cycle: %d, last_cycle: %d, dropped: %d, skipped: %d\n",  
     451                         this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
     452        } 
     453        if (dropped_cycles > 0) { 
     454            debugWarning("(%p) dropped %d packets on cycle %u (last_cycle=%u, dropped=%d, skipped: %d)\n", 
     455                         this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
     456            m_dropped += dropped_cycles; 
     457        } 
     458        #endif 
     459    } 
     460    if (cycle >= 0) { 
     461        m_last_cycle = cycle; 
     462    } 
     463 
    390464    if(m_Client) { 
    391465        enum raw1394_iso_disposition retval; 
    392         retval = m_Client->getPacket(data, length, tag, sy, cycle, dropped, skipped, m_max_packet_size); 
     466        retval = m_Client->getPacket(data, length, tag, sy, pkt_ctr, dropped, skipped, m_max_packet_size); 
    393467        #ifdef DEBUG 
    394468        if (*length > m_max_packet_size) { 
     
    411485        } 
    412486    } 
     487 
    413488    *tag = 0; 
    414489    *sy = 0; 
  • trunk/libffado/src/libieee1394/IsoHandler.h

    r1005 r1031  
    138138    void allowIterateLoop() {m_dont_exit_iterate_loop = true;}; 
    139139 
     140 
     141    /** 
     142     * @brief get last cycle number seen by handler 
     143     * @return cycle number 
     144     */ 
     145    int getLastCycle() {return m_last_cycle;}; 
     146 
    140147private: 
    141148    IsoHandlerManager& m_manager; 
     
    145152    unsigned int    m_max_packet_size; 
    146153    int             m_irq_interval; 
     154    int             m_last_cycle; 
    147155 
    148156    Streaming::StreamProcessor *m_Client; // FIXME: implement with functors 
     
    167175 
    168176    #ifdef DEBUG 
    169     int             m_packets; 
     177    unsigned int    m_packets; 
     178    unsigned int    m_dropped; 
    170179    #endif 
    171180 
  • trunk/libffado/src/libieee1394/IsoHandlerManager.cpp

    r1027 r1031  
    453453        return false; 
    454454    } 
     455    m_IsoTaskTransmit->setVerboseLevel(getDebugLevel()); 
    455456    m_IsoThreadTransmit = new Util::PosixThread(m_IsoTaskTransmit, m_realtime, 
    456457                                                m_priority + ISOHANDLERMANAGER_ISO_PRIO_INCREASE 
     
    462463        return false; 
    463464    } 
     465    m_IsoThreadTransmit->setVerboseLevel(getDebugLevel()); 
    464466 
    465467    debugOutput( DEBUG_LEVEL_VERBOSE, "Create iso thread for %p receive...\n", this); 
     
    469471        return false; 
    470472    } 
     473    m_IsoTaskReceive->setVerboseLevel(getDebugLevel()); 
    471474    m_IsoThreadReceive = new Util::PosixThread(m_IsoTaskReceive, m_realtime, 
    472475                                               m_priority + ISOHANDLERMANAGER_ISO_PRIO_INCREASE 
     
    478481        return false; 
    479482    } 
     483    m_IsoThreadReceive->setVerboseLevel(getDebugLevel()); 
    480484    // register the thread with the RT watchdog 
    481485    Util::Watchdog *watchdog = m_service.getWatchdog(); 
  • trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp

    r1021 r1031  
    4848        , m_dimension( dimension ) 
    4949        , m_dbc( 0 ) 
    50         , m_nb_audio_ports( 0 ) 
    51         , m_nb_midi_ports( 0 ) 
    5250#if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT 
    5351        , m_send_nodata_payload ( AMDTP_SEND_PAYLOAD_IN_NODATA_XMIT_BY_DEFAULT ) 
    5452#endif 
     53        , m_nb_audio_ports( 0 ) 
     54        , m_nb_midi_ports( 0 ) 
    5555{} 
    5656 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp

    r1005 r1031  
    7070    , m_local_node_id ( 0 ) // local cache 
    7171    , m_channel( -1 ) 
    72     , m_dropped( 0 ) 
    7372    , m_last_timestamp( 0 ) 
    7473    , m_last_timestamp2( 0 ) 
     
    7776    , m_scratch_buffer_size_bytes( 0 ) 
    7877    , m_ticks_per_frame( 0 ) 
    79     , m_last_cycle( -1 ) 
    8078    , m_sync_delay( 0 ) 
    8179    , m_in_xrun( false ) 
     
    289287StreamProcessor::putPacket(unsigned char *data, unsigned int length, 
    290288                           unsigned char channel, unsigned char tag, unsigned char sy, 
    291                            unsigned int cycle, unsigned int dropped, 
    292                            unsigned int skipped) { 
    293 #ifdef DEBUG 
    294     if(m_last_cycle == -1) { 
    295         debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %u)\n", getTypeString(), this, cycle); 
    296     } 
    297 #endif 
    298  
    299     int dropped_cycles = 0; 
    300     if (m_last_cycle != (int)cycle && m_last_cycle != -1) { 
    301         dropped_cycles = diffCycles(cycle, m_last_cycle) - 1; 
    302         if (dropped_cycles < 0) { 
    303             debugWarning("(%p) dropped < 1 (%d), cycle: %d, last_cycle: %d, dropped: %d, 'skipped'=%u\n",  
    304                          this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
    305         } 
    306         if (dropped_cycles > 0) { 
    307             debugWarning("(%p) dropped %d packets on cycle %u, 'dropped'=%u, 'skipped'=%u, cycle=%d, m_last_cycle=%d\n", 
    308                 this, dropped_cycles, cycle, dropped, skipped, cycle, m_last_cycle); 
    309             m_dropped += dropped_cycles; 
    310             m_last_cycle = cycle; 
    311             dumpInfo(); 
    312         } 
    313     } 
    314     m_last_cycle = cycle; 
     289                           unsigned int pkt_ctr, 
     290                           unsigned int dropped_cycles, unsigned int skipped) { 
     291    unsigned int cycle = CYCLE_TIMER_GET_CYCLES(pkt_ctr); 
    315292 
    316293    // bypass based upon state 
     
    407384                          "RECV: CY=%04u TS=%011llu\n", 
    408385                          cycle, m_last_timestamp); 
    409         // update some accounting 
    410         m_last_good_cycle = cycle; 
    411         m_last_dropped = dropped_cycles; 
    412386 
    413387        if(m_correct_last_timestamp) { 
     
    502476StreamProcessor::getPacket(unsigned char *data, unsigned int *length, 
    503477                           unsigned char *tag, unsigned char *sy, 
    504                            int cycle, unsigned int dropped
     478                           unsigned int pkt_ctr, unsigned int dropped_cycles
    505479                           unsigned int skipped, unsigned int max_length) { 
    506     if (cycle<0) { 
     480    if (pkt_ctr == 0xFFFFFFFF) { 
    507481        *tag = 0; 
    508482        *sy = 0; 
     
    510484        return RAW1394_ISO_OK; 
    511485    } 
     486    unsigned int cycle = CYCLE_TIMER_GET_CYCLES(pkt_ctr); 
    512487 
    513488    unsigned int ctr; 
     
    516491    int cycle_diff; 
    517492 
    518 #ifdef DEBUG 
    519     if(m_last_cycle == -1) { 
    520         debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %d)\n", getTypeString(), this, cycle); 
    521     } 
    522 #endif 
    523  
    524     int dropped_cycles = 0; 
    525     if (m_last_cycle != cycle && m_last_cycle != -1) { 
    526         dropped_cycles = diffCycles(cycle, m_last_cycle) - 1; 
    527         // correct for skipped packets 
    528         // since those are not dropped, but only delayed 
    529         dropped_cycles =- skipped; 
    530         if(skipped) { 
    531             debugWarning("(%p) skipped %d cycles, cycle: %d, last_cycle: %d, dropped: %d\n",  
    532                          this, skipped, cycle, m_last_cycle, dropped); 
    533         } 
    534         if (dropped_cycles < 0) {  
    535             debugWarning("(%p) dropped < 1 (%d), cycle: %d, last_cycle: %d, dropped: %d, skipped: %d\n",  
    536                          this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
    537         } 
    538         if (dropped_cycles > 0) { 
    539             debugWarning("(%p) dropped %d packets on cycle %u (last_cycle=%u, dropped=%d, skipped: %d)\n", 
    540                          this, dropped_cycles, cycle, m_last_cycle, dropped, skipped); 
    541             m_dropped += dropped_cycles; 
    542             // HACK: this should not be necessary, since the header generation functions should trigger the xrun. 
    543             //       but apparently there are some issues with the 1394 stack 
    544             m_in_xrun = true; 
    545             if(m_state == ePS_Running) { 
    546                 debugShowBackLogLines(200); 
    547                 debugWarning("dropped packets xrun\n"); 
    548                 debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state to WaitingForStreamDisable due to dropped packets xrun\n"); 
    549                 m_cycle_to_switch_state = cycle + 1; 
    550                 m_next_state = ePS_WaitingForStreamDisable; 
    551                 // execute the requested change 
    552                 if (!updateState()) { // we are allowed to change the state directly 
    553                     debugError("Could not update state!\n"); 
    554                     return RAW1394_ISO_ERROR; 
    555                 } 
    556                 goto send_empty_packet; 
    557             } 
    558         } 
    559     } 
    560     if (cycle >= 0) { 
    561         m_last_cycle = cycle; 
     493    // note that we can ignore skipped cycles since 
     494    // the protocol will take care of that 
     495    if (dropped_cycles > 0) { 
     496        // HACK: this should not be necessary, since the header generation functions should trigger the xrun. 
     497        //       but apparently there are some issues with the 1394 stack 
     498        m_in_xrun = true; 
     499        if(m_state == ePS_Running) { 
     500            debugShowBackLogLines(200); 
     501            debugWarning("dropped packets xrun\n"); 
     502            debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state to WaitingForStreamDisable due to dropped packets xrun\n"); 
     503            m_cycle_to_switch_state = cycle + 1; 
     504            m_next_state = ePS_WaitingForStreamDisable; 
     505            // execute the requested change 
     506            if (!updateState()) { // we are allowed to change the state directly 
     507                debugError("Could not update state!\n"); 
     508                return RAW1394_ISO_ERROR; 
     509            } 
     510            goto send_empty_packet; 
     511        } 
    562512    } 
    563513 
     
    637587                               "XMIT SILENT: CY=%04u TS=%011llu\n", 
    638588                               cycle, m_last_timestamp); 
    639             // update some accounting 
    640             m_last_good_cycle = cycle; 
    641             m_last_dropped = dropped_cycles; 
    642589 
    643590            // assumed not to xrun 
     
    694641                               "XMIT: CY=%04u TS=%011llu NOW_CY=%04u AHEAD=%04d\n", 
    695642                               cycle, m_last_timestamp, now_cycles, ahead); 
    696             // update some accounting 
    697             m_last_good_cycle = cycle; 
    698             m_last_dropped = dropped_cycles; 
    699643 
    700644            // valid packet timestamp 
     
    14751419        case ePS_WaitingForStream: 
    14761420            // a running stream has been detected 
    1477             debugOutput(DEBUG_LEVEL_VERBOSE, "StreamProcessor %p started dry-running at cycle %d\n", this, m_last_cycle); 
     1421            debugOutput(DEBUG_LEVEL_VERBOSE, 
     1422                        "StreamProcessor %p started dry-running\n", 
     1423                        this); 
    14781424            m_local_node_id = m_1394service.getLocalNodeId() & 0x3f; 
    14791425            if (getType() == ePT_Receive) { 
     
    15741520        case ePS_WaitingForStreamEnable: 
    15751521            // a running stream has been detected 
    1576             debugOutput(DEBUG_LEVEL_VERBOSE, "StreamProcessor %p started running at cycle %d\n",  
    1577                                              this, m_last_cycle); 
     1522            debugOutput(DEBUG_LEVEL_VERBOSE, "StreamProcessor %p started running\n",  
     1523                                             this); 
    15781524            m_in_xrun = false; 
    15791525            m_min_ahead = 7999; 
  • trunk/libffado/src/libstreaming/generic/StreamProcessor.h

    r1005 r1031  
    153153        putPacket(unsigned char *data, unsigned int length, 
    154154                  unsigned char channel, unsigned char tag, unsigned char sy, 
    155                   unsigned int cycle, unsigned int dropped, unsigned int skipped); 
     155                  unsigned int pkt_ctr, unsigned int dropped, unsigned int skipped); 
    156156 
    157157    enum raw1394_iso_disposition 
    158158    getPacket(unsigned char *data, unsigned int *length, 
    159                 unsigned char *tag, unsigned char *sy, 
    160                 int cycle, unsigned int dropped, unsigned int skipped, unsigned int max_length); 
     159              unsigned char *tag, unsigned char *sy, 
     160              unsigned int pkt_ctr, unsigned int dropped, 
     161              unsigned int skipped, unsigned int max_length); 
    161162 
    162163    bool getFrames(unsigned int nbframes, int64_t ts); ///< transfer the buffer contents to the client 
     
    301302 
    302303protected: // FIXME: move to private 
    303     uint64_t m_dropped; /// FIXME:debug 
    304     uint64_t m_last_dropped; /// FIXME:debug 
    305     int m_last_good_cycle; /// FIXME:debug 
    306304    uint64_t m_last_timestamp; /// last timestamp (in ticks) 
    307305private: 
     
    415413        void setTicksPerFrame(float tpf); 
    416414 
    417         int getLastCycle() {return m_last_cycle;}; 
    418  
    419415        int getBufferFill(); 
    420416 
     
    463459    protected: 
    464460        float m_ticks_per_frame; 
    465         int m_last_cycle; 
    466461        unsigned int m_sync_delay; 
    467462    private: