Changeset 1511

Show
Ignore:
Timestamp:
12/21/08 08:12:38 (15 years ago)
Author:
ppalmers
Message:

fix stream alignment

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r1498 r1511  
    732732        int diff_between_streams_frames[nb_rcv_sp]; 
    733733        aligned = true; 
     734 
     735        // first find whether the streams are aligned and what their offset is 
    734736        for ( i = 0; i < nb_rcv_sp; i++) { 
    735737            StreamProcessor *s = m_ReceiveProcessors.at(i); 
     
    741743 
    742744            aligned &= (diff_between_streams_frames[i] == 0); 
    743  
    744             // reposition the stream 
    745             if(!s->shiftStream(diff_between_streams_frames[i])) { 
    746                 debugError("Could not shift SP %p %d frames\n", s, diff_between_streams_frames[i]); 
    747                 return false; 
    748             } 
    749         } 
     745        } 
     746 
     747        // if required, align the streams 
     748        int frames_to_shift_stream[nb_rcv_sp]; 
     749        int min_shift = 9999; 
     750        if (!aligned) { 
     751            // find the minimum value (= earliest stream) 
     752            for ( i = 0; i < nb_rcv_sp; i++) { 
     753                if (diff_between_streams_frames[i] < min_shift) { 
     754                    min_shift = diff_between_streams_frames[i]; 
     755                } 
     756            } 
     757            debugOutput( DEBUG_LEVEL_VERBOSE, " correcting shift with %d frames\n", min_shift); 
     758            // ensure that the streams are shifted only in the 'positive' direction 
     759            // i.e. that frames are only dropped, not added since that results 
     760            // in multiple writers for the data ringbuffer 
     761            // this also results in 'minimal shift' (not that it's required since the 
     762            // sync SP is part of the SP set) 
     763            for ( i = 0; i < nb_rcv_sp; i++) { 
     764                frames_to_shift_stream[i] = diff_between_streams_frames[i] - min_shift; 
     765                debugOutput(DEBUG_LEVEL_VERBOSE, 
     766                            "  going to drop %03d frames from stream %d\n", 
     767                            frames_to_shift_stream[i], i); 
     768            } 
     769            // perform the actual shift 
     770            for ( i = 0; i < nb_rcv_sp; i++) { 
     771                StreamProcessor *s = m_ReceiveProcessors.at(i); 
     772                // reposition the stream 
     773                if(!s->shiftStream(frames_to_shift_stream[i])) { 
     774                    debugError("Could not shift SP %p %d frames\n", s, frames_to_shift_stream[i]); 
     775                    return false; 
     776                } 
     777            } 
     778        } 
     779 
    750780        if (!aligned) { 
    751781            debugOutput(DEBUG_LEVEL_VERBOSE, "Streams not aligned, doing new round...\n");