Changeset 494 for trunk/libffado/src/libstreaming/AmdtpStreamProcessor.cpp
- Timestamp:
- 07/24/07 09:49:11 (17 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/libstreaming/AmdtpStreamProcessor.cpp
r445 r494 34 34 #define TRANSMIT_TRANSFER_DELAY 9000U 35 35 // the number of cycles to send a packet in advance of it's timestamp 36 #define TRANSMIT_ADVANCE_CYCLES 1U36 #define TRANSMIT_ADVANCE_CYCLES 4U 37 37 38 38 namespace Streaming { … … 141 141 } 142 142 143 uint64_t ts_head, fc; 143 uint64_t ts_head; 144 signed int fc; 144 145 if (!m_disabled && m_is_disabled) { // this means that we are trying to enable 145 146 // check if we are on or past the enable point … … 152 153 153 154 // initialize the buffer head & tail 154 m_SyncSource->m_data_buffer->getBufferHeadTimestamp(&ts_head, &fc); // thread safe 155 155 ffado_timestamp_t ts_head_tmp; 156 m_SyncSource->m_data_buffer->getBufferHeadTimestamp(&ts_head_tmp, &fc); // thread safe 157 ts_head=(uint64_t)ts_head_tmp; 158 156 159 // the number of cycles the sync source lags (> 0) 157 160 // or leads (< 0) … … 199 202 200 203 // the base timestamp is the one of the next sample in the buffer 201 m_data_buffer->getBufferHeadTimestamp(&ts_head, &fc); // thread safe 204 ffado_timestamp_t ts_head_tmp; 205 m_data_buffer->getBufferHeadTimestamp(&ts_head_tmp, &fc); // thread safe 206 ts_head=(uint64_t)ts_head_tmp; 202 207 203 208 // we send a packet some cycles in advance, to avoid the … … 371 376 // we have to make sure that the buffer HEAD timestamp 372 377 // lies in the future for every possible buffer fill case. 373 int offset=(int)(m_ringbuffer_size_frames* m_ticks_per_frame);378 int offset=(int)(m_ringbuffer_size_frames*getTicksPerFrame()); 374 379 375 380 m_data_buffer->setTickOffset(offset); … … 446 451 447 452 // prepare the framerate estimate 448 m_ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_framerate); 453 float ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_framerate); 454 m_ticks_per_frame=ticks_per_frame; 449 455 450 456 // initialize internal buffer … … 457 463 458 464 m_data_buffer->setUpdatePeriod(m_period); 459 m_data_buffer->setNominalRate( m_ticks_per_frame);465 m_data_buffer->setNominalRate(ticks_per_frame); 460 466 461 467 m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); … … 976 982 // later than expected (the real receive time) 977 983 debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"STMP: %lluticks | buff=%d, syt_interval=%d, tpf=%f\n", 978 m_last_timestamp, m_handler->getWakeupInterval(),m_syt_interval, m_ticks_per_frame);984 m_last_timestamp, m_handler->getWakeupInterval(),m_syt_interval,getTicksPerFrame()); 979 985 980 986 //=> signal that we're running (if we are) … … 995 1001 // SYT_INTERVAL * rate later 996 1002 uint64_t ts=addTicks(m_last_timestamp, 997 (uint64_t)((float)m_syt_interval * m_ticks_per_frame));1003 (uint64_t)((float)m_syt_interval * getTicksPerFrame())); 998 1004 999 1005 // set the timestamp as if there will be a sample put into … … 1059 1065 // ISO buffering 1060 1066 int AmdtpReceiveStreamProcessor::getMinimalSyncDelay() { 1061 return ((int)(m_handler->getWakeupInterval() * m_syt_interval * m_ticks_per_frame));1067 return ((int)(m_handler->getWakeupInterval() * m_syt_interval * getTicksPerFrame())); 1062 1068 } 1063 1069 … … 1131 1137 1132 1138 // prepare the framerate estimate 1133 m_ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_framerate); 1134 1135 debugOutput(DEBUG_LEVEL_VERBOSE,"Initializing remote ticks/frame to %f\n",m_ticks_per_frame); 1139 float ticks_per_frame = (TICKS_PER_SECOND*1.0) / ((float)m_framerate); 1140 m_ticks_per_frame=ticks_per_frame; 1141 1142 debugOutput(DEBUG_LEVEL_VERBOSE,"Initializing remote ticks/frame to %f\n",ticks_per_frame); 1136 1143 1137 1144 // initialize internal buffer … … 1145 1152 // the buffer is written every syt_interval 1146 1153 m_data_buffer->setUpdatePeriod(m_syt_interval); 1147 m_data_buffer->setNominalRate( m_ticks_per_frame);1154 m_data_buffer->setNominalRate(ticks_per_frame); 1148 1155 1149 1156 m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); … … 1245 1252 } 1246 1253 1247 bool AmdtpReceiveStreamProcessor::getFrames(unsigned int nbframes ) {1254 bool AmdtpReceiveStreamProcessor::getFrames(unsigned int nbframes, int64_t ts) { 1248 1255 1249 1256 m_PeriodStat.mark(m_data_buffer->getBufferFill()); 1250 1257 uint64_t ts_head; 1258 signed int fc; 1259 int32_t lag_ticks; 1260 float lag_frames; 1261 1262 // in order to sync up multiple received streams, we should 1263 // use the ts parameter. It specifies the time of the block's 1264 // first sample. 1265 1266 ffado_timestamp_t ts_head_tmp; 1267 m_data_buffer->getBufferHeadTimestamp(&ts_head_tmp, &fc); 1268 ts_head=(uint64_t)ts_head_tmp; 1269 lag_ticks=diffTicks(ts, ts_head); 1270 float rate=m_data_buffer->getRate(); 1271 1272 assert(rate!=0.0); 1273 1274 lag_frames=(((float)lag_ticks)/rate); 1275 1276 if (lag_frames>=1.0) { 1277 // the stream leads 1278 debugOutput( DEBUG_LEVEL_VERBOSE, "stream (%p): lags with %6d ticks = %10.5f frames (rate=%10.5f)\n",this,lag_ticks,lag_frames,rate); 1279 1280 if (lag_frames>=10.0) { 1281 debugOutput( DEBUG_LEVEL_VERBOSE, " %lld, %llu, %d\n", ts, ts_head, fc); 1282 } 1283 1284 // ditch the excess frames 1285 char dummy[m_data_buffer->getBytesPerFrame()]; // one frame of garbage 1286 int frames_to_ditch=(int)(lag_frames); 1287 debugOutput( DEBUG_LEVEL_VERBOSE, "stream (%p): ditching %d frames (@ ts=%lld)\n",this,frames_to_ditch,ts); 1288 1289 while (frames_to_ditch--) { 1290 // m_data_buffer->readFrames(1, dummy); 1291 } 1292 1293 } else if (lag_frames<=-1.0) { 1294 // the stream leads 1295 debugOutput( DEBUG_LEVEL_VERBOSE, "stream (%p): leads with %6d ticks = %10.5f frames (rate=%10.5f)\n",this,lag_ticks,lag_frames,rate); 1296 1297 if (lag_frames<=-10.0) { 1298 debugOutput( DEBUG_LEVEL_VERBOSE, " %lld, %llu, %d\n", ts, ts_head, fc); 1299 } 1300 1301 // add some padding frames 1302 int frames_to_add=(int)lag_frames; 1303 debugOutput( DEBUG_LEVEL_VERBOSE, "stream (%p): adding %d frames (@ ts=%lld)\n",this,-frames_to_add,ts); 1304 1305 while (frames_to_add++) { 1306 // m_data_buffer->writeDummyFrame(); 1307 } 1308 } 1309 1251 1310 // ask the buffer to process nbframes of frames 1252 1311 // using it's registered client's processReadBlock(),