Changeset 907
- Timestamp:
- 03/06/08 11:18:43 (13 years ago)
- Files:
-
- trunk/libffado/config.h.in (modified) (1 diff)
- trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp (modified) (1 diff)
- trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (modified) (1 diff)
- trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp (modified) (3 diffs)
- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (modified) (1 diff)
- trunk/libffado/src/libutil/TimestampedBuffer.cpp (modified) (14 diffs)
- trunk/libffado/src/libutil/TimestampedBuffer.h (modified) (2 diffs)
- trunk/libffado/tests/dumpiso_mod.cpp (added)
- trunk/libffado/tests/SConscript (modified) (1 diff)
- trunk/libffado/tests/test-timestampedbuffer.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/config.h.in
r906 r907 39 39 #define DEBUG_EXTREME_ENABLE 0 40 40 41 #define IEEE1394SERVICE_USE_CYCLETIMER_DLL 041 #define IEEE1394SERVICE_USE_CYCLETIMER_DLL 1 42 42 #define IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC 200000 43 43 #define IEEE1394SERVICE_MAX_FIREWIRE_PORTS 16 trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp
r893 r907 174 174 m_last_timestamp, m_syt_interval, getTicksPerFrame()); 175 175 } 176 177 // check whether nevents is a multiple of 8. 178 if (nevents & 0x7) { 179 debugError("Invalid nevents value for AMDTP (%u)\n", nevents); 180 } 176 181 #endif 177 182 trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp
r892 r907 350 350 packet->syt = ntohs ( timestamp_SYT ); 351 351 352 // FIXME: use a precomputed value here 352 353 *length = m_syt_interval*sizeof ( quadlet_t ) *m_dimension + 8; 353 354 trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp
r906 r907 199 199 { 200 200 if (getType() == ePT_Receive) { 201 ffado_timestamp_t next_period_boundary =m_data_buffer->getTimestampFromHead(m_StreamProcessorManager.getPeriodSize());201 ffado_timestamp_t next_period_boundary = m_data_buffer->getTimestampFromHead(m_StreamProcessorManager.getPeriodSize()); 202 202 203 203 #ifdef DEBUG … … 212 212 return (uint64_t)next_period_boundary; 213 213 } else { 214 ffado_timestamp_t next_period_boundary =m_data_buffer->getTimestampFromTail((m_StreamProcessorManager.getNbBuffers()-1) * m_StreamProcessorManager.getPeriodSize());214 ffado_timestamp_t next_period_boundary = m_data_buffer->getTimestampFromTail((m_StreamProcessorManager.getNbBuffers()-1) * m_StreamProcessorManager.getPeriodSize()); 215 215 216 216 #ifdef DEBUG … … 363 363 364 364 if (result == eCRV_OK) { 365 #ifdef DEBUG 366 int ticks_per_packet = getTicksPerFrame() * getNominalFramesPerPacket(); 367 int diff=diffTicks(m_last_timestamp, m_last_timestamp2); 368 // display message if the difference between two successive tick 369 // values is more than 50 ticks. 1 sample at 48k is 512 ticks 370 // so 50 ticks = 10%, which is a rather large jitter value. 371 if(diff-ticks_per_packet > 50 || diff-ticks_per_packet < -50) { 372 debugOutput(DEBUG_LEVEL_VERBOSE, "rather large TSP difference TS=%011llu => TS=%011llu (%d, nom %d)\n", 373 m_last_timestamp2, m_last_timestamp, diff, ticks_per_packet); 374 } 375 #endif 376 365 377 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 366 378 "RECV: CY=%04u TS=%011llu\n", trunk/libffado/src/libstreaming/StreamProcessorManager.cpp
r883 r907 772 772 // and the receive processors should have done their transfer. 773 773 m_time_of_transfer = m_SyncSource->getTimeAtPeriod(); 774 775 #ifdef DEBUG 776 static uint64_t m_time_of_transfer2 = m_time_of_transfer; 777 778 int ticks_per_period = m_SyncSource->getTicksPerFrame() * m_period; 779 int diff=diffTicks(m_time_of_transfer, m_time_of_transfer2); 780 // display message if the difference between two successive tick 781 // values is more than 50 ticks. 1 sample at 48k is 512 ticks 782 // so 50 ticks = 10%, which is a rather large jitter value. 783 if(diff-ticks_per_period > 50 || diff-ticks_per_period < -50) { 784 debugOutput(DEBUG_LEVEL_VERBOSE, "rather large TSP difference TS=%011llu => TS=%011llu (%d, nom %d)\n", 785 m_time_of_transfer2, m_time_of_transfer, diff, ticks_per_period); 786 } 787 m_time_of_transfer2 = m_time_of_transfer; 788 #endif 789 774 790 debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, 775 791 "transfer at %llu ticks...\n", trunk/libffado/src/libutil/TimestampedBuffer.cpp
r866 r907 66 66 m_wrap_at(0xFFFFFFFFFFFFFFFFLLU), 67 67 m_Client(c), m_framecounter(0), 68 m_tick_offset(0.0),69 68 m_buffer_tail_timestamp(0.0), 70 69 m_buffer_next_tail_timestamp(0.0), … … 224 223 m_bytes_per_frame=m_event_size*m_events_per_frame; 225 224 m_bytes_per_buffer=m_bytes_per_frame*m_buffer_size; 226 227 return true;228 }229 230 /**231 * Sets the buffer offset in ticks.232 *233 * A positive value means that the buffer is 'delayed' for nticks ticks.234 *235 * @note These offsets are only used when reading timestamps. Any function236 * that returns a timestamp will incorporate this offset.237 * @param nframes the number of ticks (positive = delay buffer)238 * @return true if successful239 */240 bool TimestampedBuffer::setTickOffset(ffado_timestamp_t nticks) {241 debugOutput(DEBUG_LEVEL_VERBOSE,"Setting ticks offset to "TIMESTAMP_FORMAT_SPEC"\n",nticks);242 243 // JMW: I think we need to update the internal DLL state to take account244 // of the new offset. Doing so certainly makes for a smoother MOTU245 // startup.246 ENTER_CRITICAL_SECTION;247 m_buffer_tail_timestamp = m_buffer_tail_timestamp - m_tick_offset + nticks;248 m_buffer_next_tail_timestamp = (ffado_timestamp_t)((double)m_buffer_tail_timestamp + m_dll_e2);249 m_tick_offset=nticks;250 EXIT_CRITICAL_SECTION;251 225 252 226 return true; … … 427 401 return false; 428 402 } 429 incrementFrameCounter(nframes, ts);403 incrementFrameCounter(nframes, ts); 430 404 } 431 405 return true; … … 752 726 // add the offsets 753 727 ffado_timestamp_t ts=new_timestamp; 754 ts += m_tick_offset;755 728 756 729 if (ts >= m_wrap_at) { … … 842 815 */ 843 816 void TimestampedBuffer::getBufferHeadTimestamp(ffado_timestamp_t *ts, signed int *fc) { 844 // NOTE: this is still ok with threads, because we use *fc to compute 845 // the timestamp 817 ENTER_CRITICAL_SECTION; 846 818 *fc = m_framecounter; 847 819 *ts = getTimestampFromTail(*fc); 820 EXIT_CRITICAL_SECTION; 848 821 } 849 822 … … 859 832 */ 860 833 void TimestampedBuffer::getBufferTailTimestamp(ffado_timestamp_t *ts, signed int *fc) { 861 // NOTE: this is still ok with threads, because we use *fc to compute 862 // the timestamp 834 ENTER_CRITICAL_SECTION; 863 835 *fc = m_framecounter; 864 836 *ts = getTimestampFromTail(0); 837 EXIT_CRITICAL_SECTION; 865 838 } 866 839 … … 903 876 ffado_timestamp_t TimestampedBuffer::getTimestampFromHead(int nframes) 904 877 { 905 return getTimestampFromTail(m_framecounter-nframes); 878 ffado_timestamp_t retval; 879 ENTER_CRITICAL_SECTION; 880 retval = getTimestampFromTail(m_framecounter-nframes); 881 EXIT_CRITICAL_SECTION; 882 return retval; 906 883 } 907 884 … … 939 916 void TimestampedBuffer::incrementFrameCounter(unsigned int nbframes, ffado_timestamp_t new_timestamp) { 940 917 941 // add the offsets 942 ffado_timestamp_t diff; 943 944 ENTER_CRITICAL_SECTION; 945 diff = m_buffer_next_tail_timestamp - m_buffer_tail_timestamp; 946 EXIT_CRITICAL_SECTION; 947 948 if (diff < 0) diff += m_wrap_at; 949 950 ffado_timestamp_t ts = new_timestamp; 951 ts += m_tick_offset; 952 953 if (ts >= m_wrap_at) { 954 ts -= m_wrap_at; 955 } else if (ts < 0) { 956 ts += m_wrap_at; 957 } 958 959 #ifdef DEBUG 960 if (new_timestamp >= m_wrap_at) { 961 debugWarning("timestamp not wrapped: "TIMESTAMP_FORMAT_SPEC"\n", new_timestamp); 962 } 963 if ((ts >= m_wrap_at) || (ts < 0 )) { 964 debugWarning("ts not wrapped correctly: "TIMESTAMP_FORMAT_SPEC"\n",ts); 965 } 966 #endif 967 // FIXME: JMW: at some points during startup the timestamp doesn't change. 968 // This still needs to be verified in more detail. 969 // if (ts>m_buffer_tail_timestamp-1 && ts<m_buffer_tail_timestamp+1) { 970 // ENTER_CRITICAL_SECTION; 971 // m_framecounter += nbframes; 972 // EXIT_CRITICAL_SECTION; 973 // return; 974 // } 975 ffado_timestamp_t pred_buffer_next_tail_timestamp; 976 if(nbframes == m_update_period) { 977 pred_buffer_next_tail_timestamp = m_buffer_next_tail_timestamp; 978 } else { 979 debugOutput( DEBUG_LEVEL_VERBOSE, 980 "Number of frames (%u) != update period (%u)\n", 981 nbframes, m_update_period ); 982 // calculate the predicted timestamp for nframes (instead of m_update_period) 983 // after the previous update. 984 float rel_step = ((float)nbframes)/((float)m_update_period); 985 ENTER_CRITICAL_SECTION; // FIXME: do we need these? 986 ffado_timestamp_t corrected_step = (m_buffer_next_tail_timestamp - m_buffer_tail_timestamp) * rel_step; 987 pred_buffer_next_tail_timestamp = m_buffer_tail_timestamp + corrected_step; 988 EXIT_CRITICAL_SECTION; 989 990 debugOutput( DEBUG_LEVEL_VERBOSE, 991 "Updated ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC") " 992 "to ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC")\n", 993 m_buffer_tail_timestamp, m_buffer_next_tail_timestamp, 994 m_buffer_tail_timestamp, pred_buffer_next_tail_timestamp); 995 } 996 918 // require the timestamps to be in the correct range 919 assert(new_timestamp < m_wrap_at); 920 assert(new_timestamp >= 0); 921 // if this is not true the timestamps have to be corrected 922 // to account for the non-uniform update period 923 assert(nbframes == m_update_period); 924 997 925 // the difference between the given TS and the one predicted for this time instant 998 926 // this is the error for the DLL 999 diff = ts - pred_buffer_next_tail_timestamp; 1000 927 ffado_timestamp_t diff = new_timestamp - m_buffer_next_tail_timestamp; 928 929 #ifdef DEBUG 1001 930 // check whether the update is within the allowed bounds 1002 const float max_deviation = (50.0/100.0); // maximal relative difference considered normal931 /* const float max_deviation = (50.0/100.0); // maximal relative difference considered normal 1003 932 ffado_timestamp_t one_update_step = nbframes * getRate(); 1004 ffado_timestamp_t max_abs_diff = one_update_step * (1.0 + max_deviation); 933 ffado_timestamp_t max_abs_diff = one_update_step * (1.0 + max_deviation);*/ 934 ffado_timestamp_t max_abs_diff = 200; 1005 935 1006 936 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, … … 1012 942 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 1013 943 " new TS: "TIMESTAMP_FORMAT_SPEC", wrapped new TS: "TIMESTAMP_FORMAT_SPEC"\n", 1014 new_timestamp, ts);944 new_timestamp, new_timestamp); 1015 945 1016 946 if (diff > max_abs_diff) { 1017 //debugShowBackLogLines(100);947 //debugShowBackLogLines(100); 1018 948 debugWarning("(%p) difference rather large (+): diff="TIMESTAMP_FORMAT_SPEC", max="TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC"\n", 1019 this, diff, max_abs_diff, ts, pred_buffer_next_tail_timestamp);949 this, diff, max_abs_diff, new_timestamp, m_buffer_next_tail_timestamp); 1020 950 } else if (diff < -max_abs_diff) { 1021 //debugShowBackLogLines(100);951 //debugShowBackLogLines(100); 1022 952 debugWarning("(%p) difference rather large (-): diff="TIMESTAMP_FORMAT_SPEC", max="TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC", "TIMESTAMP_FORMAT_SPEC"\n", 1023 this, diff, -max_abs_diff, ts, pred_buffer_next_tail_timestamp);953 this, diff, -max_abs_diff, new_timestamp, m_buffer_next_tail_timestamp); 1024 954 } 1025 955 … … 1027 957 "(%p): diff="TIMESTAMP_FORMAT_SPEC" ", 1028 958 this, diff); 959 #endif 1029 960 1030 961 double err = diff; … … 1038 969 ENTER_CRITICAL_SECTION; 1039 970 m_framecounter += nbframes; 1040 m_buffer_tail_timestamp = pred_buffer_next_tail_timestamp;1041 m_buffer_next_tail_timestamp = pred_buffer_next_tail_timestamp + (ffado_timestamp_t)(m_dll_b * err + m_dll_e2);971 m_buffer_tail_timestamp = m_buffer_next_tail_timestamp; 972 m_buffer_next_tail_timestamp = m_buffer_next_tail_timestamp + (ffado_timestamp_t)(m_dll_b * err + m_dll_e2); 1042 973 m_dll_e2 += m_dll_c*err; 1043 974 … … 1065 996 debugError("Wrapping failed for m_buffer_tail_timestamp! "TIMESTAMP_FORMAT_SPEC"\n",m_buffer_tail_timestamp); 1066 997 debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " IN="TIMESTAMP_FORMAT_SPEC", TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", 1067 ts, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp);998 new_timestamp, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 1068 999 1069 1000 } … … 1071 1002 debugError("Wrapping failed for m_buffer_next_tail_timestamp! "TIMESTAMP_FORMAT_SPEC"\n",m_buffer_next_tail_timestamp); 1072 1003 debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " IN="TIMESTAMP_FORMAT_SPEC", TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", 1073 ts, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp);1004 new_timestamp, m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); 1074 1005 } 1075 1006 … … 1077 1008 debugError("Current and next timestamps are equal: "TIMESTAMP_FORMAT_SPEC" "TIMESTAMP_FORMAT_SPEC"\n", 1078 1009 m_buffer_tail_timestamp,m_buffer_next_tail_timestamp); 1079 1080 1010 } 1081 1011 trunk/libffado/src/libutil/TimestampedBuffer.h
r866 r907 135 135 ffado_timestamp_t getTimestampFromHead ( int nframes ); 136 136 137 // buffer offset stuff138 /// return the tick offset value139 ffado_timestamp_t getTickOffset() {return m_tick_offset;};140 141 bool setFrameOffset ( int nframes );142 bool setTickOffset ( ffado_timestamp_t );143 144 137 // dll stuff 145 138 bool setNominalRate ( float r ); … … 183 176 // the framecounter gives the number of frames in the buffer 184 177 signed int m_framecounter; 185 186 // the offset that define the timing of the buffer187 ffado_timestamp_t m_tick_offset;188 178 189 179 // the buffer tail timestamp gives the timestamp of the last frame trunk/libffado/tests/SConscript
r864 r907 52 52 "test-streamdump" : "test-streamdump.cpp", 53 53 "test-bufferops" : "test-bufferops.cpp", 54 "dumpiso_mod" : "dumpiso_mod.cpp" 54 55 } 55 56 trunk/libffado/tests/test-timestampedbuffer.cpp
r864 r907 292 292 t->setWrapValue(arguments.wrap_at); 293 293 294 t->setTickOffset(10000);295 296 294 t->prepare(); 297 295 … … 314 312 // and that setBufferHeadTimestamp doesn't take offset 315 313 // into account 316 uint64_t timestamp2=timestamp +t->getTickOffset();314 uint64_t timestamp2=timestamp; 317 315 if (timestamp2>=arguments.wrap_at) { 318 316 timestamp2-=arguments.wrap_at;