Changeset 255

Show
Ignore:
Timestamp:
06/09/06 15:33:51 (16 years ago)
Author:
pieterpalmers
Message:

- the syt extraction is finally correct, handling all wraparounds correctly
- when receiving a stream the device's samplerate is estimated and this estimate

is used to calculate the timestamps for the transmitted packets
(needs some more work)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libfreebob-2.0/src/libstreaming/AmdtpStreamProcessor.cpp

    r253 r255  
    106106                *tag = IEC61883_TAG_WITH_CIP; 
    107107                *sy = 0; 
    108                 m_last_timestamp=9000.0 + cycle * 3072.0; 
     108                m_last_timestamp=4.0*9000.0 + cycle * 3072.0; 
    109109                return RAW1394_ISO_OK; 
    110110        } 
     
    196196         
    197197        unsigned int timestamp2=ntohs(timestamp); 
    198          debugOutput(DEBUG_LEVEL_VERBOSE,"XMIT %d EVENTS, SYT %04X (was: %04X) for cycle %2d: %5u ticks (%2u cycles + %04u ticks)\n", 
     198         debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"XMIT %d EVENTS, SYT %04X (was: %04X) for cycle %2d: %5u ticks (%2u cycles + %04u ticks)\n", 
    199199         nevents, timestamp, packet->syt, cycle, 
    200200         CYCLE_COUNTER_TO_TICKS(timestamp2), 
     
    878878            // actual presentation time later 
    879879            if (packet->syt != 0xFFFF) { 
     880 
     881                bool wraparound_occurred=false; 
    880882                 
    881883                m_last_timestamp2=m_last_timestamp; 
     
    887889                 
    888890                // if this is true, wraparound has occurred, undo this wraparound 
    889                 if(syt_cycle<now_cycle_masked) syt_cycle += 0xF
     891                if(syt_cycle<now_cycle_masked) syt_cycle += 0x10
    890892                 
    891893                unsigned int delta_cycles=syt_cycle-now_cycle_masked; 
     
    894896                unsigned int new_cycles=cycle + delta_cycles; 
    895897                 
    896                 if(new_cycles>7999) new_cycles-=8000; // wrap around 
     898                if(new_cycles>7999) { 
     899                    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Detected wraparound: %d + %d = %d\n",cycle,delta_cycles,new_cycles); 
     900                     
     901                    new_cycles-=8000; // wrap around 
     902                    wraparound_occurred=true; 
     903                } 
    897904                 
    898905                m_last_timestamp = (new_cycles) << 12; 
     
    901908                m_last_timestamp |= (syt_timestamp & 0xFFF); 
    902909                 
     910                // mask off the seconds field 
     911                 
    903912                // m_last_timestamp timestamp now contains all info, 
    904913                // including cycle number 
     
    906915                if (m_last_timestamp & m_last_timestamp2) { 
    907916                    // try and estimate the frame rate from the device: 
    908                     int timestamp_difference=CYCLE_COUNTER_TO_TICKS(m_last_timestamp
    909                                              -CYCLE_COUNTER_TO_TICKS(m_last_timestamp2); 
     917                    int timestamp_difference=((int)(CYCLE_COUNTER_TO_TICKS(m_last_timestamp))
     918                                             -((int)(CYCLE_COUNTER_TO_TICKS(m_last_timestamp2))); 
    910919                                              
    911                     // handle wrap around of the cycle variable 
    912                     if (new_cycles==0) timestamp_difference+=TICKS_PER_SECOND; 
     920                    // handle wrap around of the cycle variable if nescessary 
     921                    // it can be that two successive timestamps cause wraparound (if the difference between time 
     922                    // stamps is larger than 2 cycles), thus it isn't always nescessary 
     923                    if (wraparound_occurred & (m_last_timestamp<m_last_timestamp2)) { 
     924                        debugOutput(DEBUG_LEVEL_VERY_VERBOSE," => correcting for timestamp difference wraparound\n"); 
     925                        timestamp_difference+=TICKS_PER_SECOND; 
     926                    } 
    913927                     
    914928                    // implement a 1st order DLL to estimate the framerate 
     
    920934                    err=err-m_ticks_per_frame; 
    921935                     
     936                    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT: %08X | STMP: %08X | DLL: in=%5.0f, current=%f, err=%e\n",syt_timestamp, m_last_timestamp, f,m_ticks_per_frame,err); 
     937 
     938#ifdef DEBUG 
     939                    if(f > 1.5*((TICKS_PER_SECOND*1.0) / m_framerate)*m_syt_interval) { 
     940                        debugWarning("Timestamp diff more than 50%% of the nominal diff too large!\n"); 
     941                        debugWarning(" SYT: %08X | STMP: %08X,%08X | DLL: in=%5.0f, current=%f, err=%e\n",syt_timestamp, m_last_timestamp, m_last_timestamp2, f,m_ticks_per_frame,err); 
     942                    } 
     943                    if(f < 0.5*((TICKS_PER_SECOND*1.0) / m_framerate)*m_syt_interval) { 
     944                        debugWarning("Timestamp diff more than 50%% of the nominal diff too small!\n"); 
     945                        debugWarning(" SYT: %08X | STMP: %08X,%08X | DLL: in=%5.0f, current=%f, err=%e\n",syt_timestamp, m_last_timestamp, m_last_timestamp2, f,m_ticks_per_frame,err); 
     946                    } 
     947#endif 
     948 
     949                    const double coeff=0.0001; 
    922950                    // integrate the error 
    923                     m_ticks_per_frame += 0.000001*err; 
     951                    m_ticks_per_frame += coeff*err; 
     952                     
    924953                } 
    925954                 
     
    934963#ifdef DEBUG 
    935964                if(m_last_timestamp<m_last_timestamp2) { 
    936                     if(new_cycles==0) { 
    937                         debugWarning("timestamp not sequential, but it's wraparound. %08X %08X %08X\n",syt_timestamp, m_last_timestamp, m_last_timestamp2);                    
     965                    if(wraparound_occurred) { 
     966                        debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"timestamp not sequential for cycle %d, but it's wraparound. %08X %08X %08X\n",cycle,syt_timestamp, m_last_timestamp, m_last_timestamp2);                    
    938967                    } else { 
    939                         debugFatal("timestamp not sequential! %08X %08X %08X\n",syt_timestamp, m_last_timestamp, m_last_timestamp2); 
    940                         return RAW1394_ISO_STOP; 
     968                        debugWarning("timestamp not sequential for cycle %d! %08X %08X %08X\n", cycle, syt_timestamp, m_last_timestamp, m_last_timestamp2); 
     969                         
     970                        // the DLL will recover from this. 
     971                        m_last_timestamp2=m_last_timestamp; 
    941972                    } 
    942973                } 
     
    10631094         
    10641095        if(tmp<0) { 
    1065             debugOutput(DEBUG_LEVEL_VERBOSE,"SYT passed (%d ticks too late)\n",-tmp); 
    1066             debugOutput(DEBUG_LEVEL_VERBOSE,"Periods: %d, remote ticks/frame: %f, remote framerate = %f\n",m_PeriodStat.m_count, m_ticks_per_frame, 24576000.0/m_ticks_per_frame); 
     1096            debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT passed (%d ticks too late)\n",-tmp); 
     1097            debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Periods: %d, remote ticks/frame: %f, remote framerate = %f\n",m_PeriodStat.m_count, m_ticks_per_frame, 24576000.0/m_ticks_per_frame); 
    10671098            if (-tmp>1000000) debugWarning("SYT VERY LATE: %d!\n",-tmp); 
    10681099//                 return true; 
     
    10791110#endif 
    10801111} 
     1112 
     1113void AmdtpReceiveStreamProcessor::dumpInfo() 
     1114{ 
     1115 
     1116    StreamProcessor::dumpInfo(); 
     1117     
     1118        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Device framerate  : %f\n", 24576000.0/m_ticks_per_frame); 
     1119 
     1120} 
     1121 
    10811122 
    10821123void AmdtpReceiveStreamProcessor::setVerboseLevel(int l) { 
  • branches/libfreebob-2.0/src/libstreaming/AmdtpStreamProcessor.h

    r253 r255  
    182182    double getTicksPerFrame() {return m_ticks_per_frame;}; 
    183183     
     184    void dumpInfo(); 
     185     
    184186protected: 
    185187 
  • branches/libfreebob-2.0/src/libstreaming/StreamProcessor.cpp

    r250 r255  
    6363        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Iso stream info:\n"); 
    6464         
    65         ((IsoStream*)this)->dumpInfo(); 
     65        IsoStream::dumpInfo(); 
    6666        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Frame counter  : %d\n", m_framecounter); 
    6767        debugOutputShort( DEBUG_LEVEL_NORMAL, "  Xruns          : %d\n", m_xruns); 
     
    7474         
    7575         
    76 }; 
     76} 
    7777 
    7878bool StreamProcessor::init()