Changeset 723

Show
Ignore:
Timestamp:
11/25/07 05:42:51 (16 years ago)
Author:
ppalmers
Message:

fix problem where receiving multiple streams doesn't work

Files:

Legend:

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

    r722 r723  
    448448DiceAvDevice::prepare() { 
    449449    // prepare receive SP's 
    450 //     for (unsigned int i=0;i<m_nb_tx;i++) { 
    451     for (unsigned int i=0;i<1;i++) { 
     450    for (unsigned int i=0;i<m_nb_tx;i++) { 
    452451        fb_quadlet_t nb_audio; 
    453452        fb_quadlet_t nb_midi; 
  • branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.cpp

    r722 r723  
    193193                           unsigned char channel, unsigned char tag, unsigned char sy, 
    194194                           unsigned int cycle, unsigned int dropped) { 
     195    if(m_last_cycle == -1) { 
     196        debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %u)\n", getTypeString(), this, cycle); 
     197    } 
     198 
    195199    int dropped_cycles = 0; 
    196200    if (m_last_cycle != (int)cycle && m_last_cycle != -1) { 
     
    201205            m_dropped += dropped_cycles; 
    202206        } 
    203         m_last_cycle = cycle; 
    204     } 
     207    } 
     208    m_last_cycle = cycle; 
    205209 
    206210    // bypass based upon state 
     
    303307            debugWarning("(%p) Correcting timestamp for dropped cycles, discarding packet...\n", this); 
    304308            m_data_buffer->setBufferTailTimestamp(m_last_timestamp); 
    305  
    306             // this is an xrun situation 
    307             m_in_xrun = true; 
    308             debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state to WaitingForStreamDisable due to dropped packet xrun\n"); 
    309             m_cycle_to_switch_state = cycle + 1; // switch in the next cycle 
    310             m_next_state = ePS_WaitingForStreamDisable; 
    311             // execute the requested change 
    312             if (!updateState()) { // we are allowed to change the state directly 
    313                 debugError("Could not update state!\n"); 
    314                 return RAW1394_ISO_ERROR; 
    315             } 
    316             return RAW1394_ISO_DEFER; 
     309            if (m_state == ePS_Running) { 
     310                // this is an xrun situation 
     311                m_in_xrun = true; 
     312                debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state to WaitingForStreamDisable due to dropped packet xrun\n"); 
     313                m_cycle_to_switch_state = cycle + 1; // switch in the next cycle 
     314                m_next_state = ePS_WaitingForStreamDisable; 
     315                // execute the requested change 
     316                if (!updateState()) { // we are allowed to change the state directly 
     317                    debugError("Could not update state!\n"); 
     318                    return RAW1394_ISO_ERROR; 
     319                } 
     320                return RAW1394_ISO_DEFER; 
     321            } 
    317322        } 
    318323 
     
    363368    } 
    364369 
     370    if(m_last_cycle == -1) { 
     371        debugOutput(DEBUG_LEVEL_VERBOSE, "Handler for %s SP %p is alive (cycle = %d)\n", getTypeString(), this, cycle); 
     372    } 
     373 
    365374    int dropped_cycles = 0; 
    366375    if (m_last_cycle != cycle && m_last_cycle != -1) { 
     
    371380            m_dropped += dropped_cycles; 
    372381        } 
     382    } 
     383    if (cycle > 0) { 
    373384        m_last_cycle = cycle; 
    374385    } 
     
    507518                return RAW1394_ISO_ERROR; 
    508519            } 
    509         } else if (result == eCRV_EmptyPacket) { 
     520        } else if ((result == eCRV_EmptyPacket) || (result == eCRV_Again)) { 
    510521            if(m_state != m_next_state) { 
    511522                debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state from %s to %s\n", 
     
    518529            } 
    519530            goto send_empty_packet; 
    520         } else if (result == eCRV_Again) { 
    521             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "have to retry cycle %d\n", cycle); 
    522             if(m_state != m_next_state) { 
    523                 debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state from %s to %s\n", 
    524                                                 ePSToString(m_state), ePSToString(m_next_state)); 
    525                 // execute the requested change 
    526                 if (!updateState()) { // we are allowed to change the state directly 
    527                     debugError("Could not update state!\n"); 
    528                     return RAW1394_ISO_ERROR; 
    529                 } 
    530             } 
    531             // force some delay 
    532             usleep(125); 
    533             return RAW1394_ISO_AGAIN; 
     531//         } else if (result == eCRV_Again) { 
     532//             debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "have to retry cycle %d\n", cycle); 
     533//             if(m_state != m_next_state) { 
     534//                 debugOutput(DEBUG_LEVEL_VERBOSE, "Should update state from %s to %s\n", 
     535//                                                 ePSToString(m_state), ePSToString(m_next_state)); 
     536//                 // execute the requested change 
     537//                 if (!updateState()) { // we are allowed to change the state directly 
     538//                     debugError("Could not update state!\n"); 
     539//                     return RAW1394_ISO_ERROR; 
     540//                 } 
     541//             } 
     542//             // force some delay 
     543//             usleep(125); 
     544//             return RAW1394_ISO_AGAIN; 
    534545        } else { 
    535546            debugError("Invalid return value: %d\n", result); 
     
    13611372StreamProcessor::dumpInfo() 
    13621373{ 
    1363     debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor information\n"); 
     1374    debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor %p information\n", this); 
    13641375    debugOutputShort( DEBUG_LEVEL_NORMAL, "  Iso stream info:\n"); 
    13651376 
  • branches/ppalmers-streaming/src/libstreaming/generic/StreamProcessor.h

    r722 r723  
    384384    virtual void dumpInfo(); 
    385385    virtual void setVerboseLevel(int l); 
     386    const char *getStateString() 
     387        {return ePSToString(getState());}; 
     388    const char *getTypeString() 
     389        {return ePTToString(getType());}; 
    386390    StreamStatistics m_PacketStat; 
    387391    StreamStatistics m_PeriodStat; 
  • branches/ppalmers-streaming/src/libstreaming/StreamProcessorManager.cpp

    r722 r723  
    241241 
    242242bool StreamProcessorManager::startDryRunning() { 
    243     debugOutput( DEBUG_LEVEL_VERBOSE, "Waiting for StreamProcessor streams to start dry-running...\n"); 
     243    debugOutput( DEBUG_LEVEL_VERBOSE, "Putting StreamProcessor streams into dry-running state...\n"); 
     244    debugOutput( DEBUG_LEVEL_VERBOSE, " Schedule start dry-running...\n"); 
    244245    for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    245246            it != m_ReceiveProcessors.end(); 
    246247            ++it ) { 
    247248        if (!(*it)->isDryRunning()) { 
    248             if(!(*it)->startDryRunning(-1)) { 
     249            if(!(*it)->scheduleStartDryRunning(-1)) { 
    249250                debugError("Could not put SP %p into the dry-running state\n", *it); 
    250251                return false; 
    251252            } 
     253        } else { 
     254            debugOutput( DEBUG_LEVEL_VERBOSE, " SP %p already dry-running...\n", *it); 
    252255        } 
    253256    } 
     
    256259            ++it ) { 
    257260        if (!(*it)->isDryRunning()) { 
    258             if(!(*it)->startDryRunning(-1)) { 
     261            if(!(*it)->scheduleStartDryRunning(-1)) { 
    259262                debugError("Could not put SP %p into the dry-running state\n", *it); 
    260263                return false; 
    261264            } 
    262         } 
     265        } else { 
     266            debugOutput( DEBUG_LEVEL_VERBOSE, " SP %p already dry-running...\n", *it); 
     267        } 
     268    } 
     269    debugOutput( DEBUG_LEVEL_VERBOSE, " Waiting for all SP's to be dry-running...\n"); 
     270    // wait for the syncsource to start running. 
     271    // that will block the waitForPeriod call until everyone has started (theoretically) 
     272    #define CYCLES_FOR_DRYRUN 40000 
     273    int cnt = CYCLES_FOR_DRYRUN; // by then it should have started 
     274    bool all_dry_running = false; 
     275    while (!all_dry_running && cnt) { 
     276        all_dry_running = true; 
     277        for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     278                it != m_ReceiveProcessors.end(); 
     279                ++it ) { 
     280            all_dry_running &= (*it)->isDryRunning(); 
     281        } 
     282        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     283                it != m_TransmitProcessors.end(); 
     284                ++it ) { 
     285            all_dry_running &= (*it)->isDryRunning(); 
     286        } 
     287 
     288        usleep(125); 
     289        cnt--; 
     290    } 
     291    if(cnt==0) { 
     292        debugOutput(DEBUG_LEVEL_VERBOSE, " Timeout waiting for the SP's to start dry-running\n"); 
     293        for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     294                it != m_ReceiveProcessors.end(); 
     295                ++it ) { 
     296            debugOutput( DEBUG_LEVEL_VERBOSE, " %s SP %p has state %s\n", 
     297                (*it)->getTypeString(), *it, (*it)->getStateString()); 
     298        } 
     299        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     300                it != m_TransmitProcessors.end(); 
     301                ++it ) { 
     302            debugOutput( DEBUG_LEVEL_VERBOSE, " %s SP %p has state %s\n", 
     303                (*it)->getTypeString(), *it, (*it)->getStateString()); 
     304        } 
     305        return false; 
    263306    } 
    264307    debugOutput( DEBUG_LEVEL_VERBOSE, " StreamProcessor streams dry-running...\n"); 
     
    330373        (unsigned int)TICKS_TO_OFFSET(time_of_first_sample)); 
    331374 
    332     #define CYCLES_FOR_STARTUP 200 
     375    #define CYCLES_FOR_STARTUP 2000 
    333376    // start wet-running in CYCLES_FOR_STARTUP cycles 
    334377    // this is the time window we have to setup all SP's such that they  
     
    399442        return false; 
    400443    } 
     444 
     445    // now align the received streams 
     446    debugOutput( DEBUG_LEVEL_VERBOSE, " Aligning incoming streams...\n"); 
     447     
     448     
    401449    debugOutput( DEBUG_LEVEL_VERBOSE, " StreamProcessor streams running...\n"); 
    402450    return true; 
  • branches/ppalmers-streaming/src/libstreaming/util/IsoHandlerManager.cpp

    r722 r723  
    4848IsoHandlerManager::IsoHandlerManager(bool run_rt, unsigned int rt_prio) : 
    4949   m_State(E_Created), 
    50    m_poll_timeout(1), m_poll_fds(0), m_poll_nfds(0), 
     50   m_poll_timeout(100), m_poll_fds(0), m_poll_nfds(0), 
    5151   m_realtime(run_rt), m_priority(rt_prio), m_xmit_nb_periods( 1 ) 
    5252{ 
     
    131131    int err; 
    132132    int i=0; 
    133     debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); 
     133    debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "poll %d fd's, timeout = %dms...\n", m_poll_nfds, m_poll_timeout); 
    134134 
    135135    err = poll (m_poll_fds, m_poll_nfds, m_poll_timeout); 
     
    143143    } 
    144144 
     145//     #ifdef DEBUG 
     146//     for (i = 0; i < m_poll_nfds; i++) { 
     147//         IsoHandler *s = m_IsoHandlers.at(i); 
     148//         assert(s); 
     149//         debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%d) handler %p: iterate? %d, revents: %08X\n",  
     150//             i, s, (m_poll_fds[i].revents & (POLLIN) == 1), m_poll_fds[i].revents); 
     151//     } 
     152//     #endif 
     153 
    145154    for (i = 0; i < m_poll_nfds; i++) { 
    146155        if (m_poll_fds[i].revents & POLLERR) { 
     
    153162 
    154163        if(m_poll_fds[i].revents & (POLLIN)) { 
    155             IsoHandler *s=m_IsoHandlers.at(i); 
     164            IsoHandler *s = m_IsoHandlers.at(i); 
    156165            assert(s); 
    157  
    158166            s->iterate(); 
    159167        } 
     
    306314    if (stream->getStreamType()==IsoStream::eST_Receive) { 
    307315        // setup the optimal parameters for the raw1394 ISO buffering 
    308         unsigned int packets_per_period=stream->getPacketsPerPeriod(); 
     316        unsigned int packets_per_period = stream->getPacketsPerPeriod(); 
    309317 
    310318#if 1 
     
    317325        unsigned int max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize()) / packets_per_period; 
    318326        if (max_packet_size < stream->getMaxPacketSize()) { 
    319             max_packet_size=stream->getMaxPacketSize(); 
     327            debugWarning("calculated max packet size (%u) < stream max packet size (%u)\n", 
     328                         max_packet_size ,(unsigned int)stream->getMaxPacketSize()); 
     329            max_packet_size = stream->getMaxPacketSize(); 
    320330        } 
    321331 
    322332        // Ensure we don't request a packet size bigger than the 
    323333        // kernel-enforced maximum which is currently 1 page. 
    324         if (max_packet_size > (unsigned int)getpagesize()) 
    325                     max_packet_size = getpagesize(); 
    326  
    327         unsigned int irq_interval=packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
     334        if (max_packet_size > (unsigned int)getpagesize()) { 
     335            debugWarning("max packet size (%u) > page size (%u)\n", max_packet_size ,(unsigned int)getpagesize()); 
     336            max_packet_size = getpagesize(); 
     337        } 
     338 
     339        unsigned int irq_interval = packets_per_period / MINIMUM_INTERRUPTS_PER_PERIOD; 
    328340        if(irq_interval <= 0) irq_interval=1; 
    329341        // FIXME: test 
    330         irq_interval=1; 
    331         #warning Using fixed irq_interval 
     342        //irq_interval=1; 
    332343 
    333344#else