@@ -193,21 +193,28 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
193
193
HLOGC(bslog.Debug,
194
194
log << "addBuffer: size=" << m_iCount << " reserved=" << m_iSize << " needs=" << size << " buffers for "
195
195
<< len << " bytes");
196
+
// Retrieve current time before locking the mutex to be closer to packet submission event.
197
+
const steady_clock::time_point tnow = steady_clock::now();
196
198
197
-
// dynamically increase sender buffer
199
+
ScopedLock bufferguard(m_BufLock);
200
+
// Dynamically increase sender buffer if there is not enough room.
198
201
while (size + m_iCount >= m_iSize)
199
202
{
200
203
HLOGC(bslog.Debug, log << "addBuffer: ... still lacking " << (size + m_iCount - m_iSize) << " buffers...");
201
204
increase();
202
205
}
203
206
204
-
const steady_clock::time_point time = steady_clock::now();
205
207
const int32_t inorder = w_mctrl.inorder ? MSGNO_PACKET_INORDER::mask : 0;
206
-
207
208
HLOGC(bslog.Debug,
208
209
log << CONID() << "addBuffer: adding " << size << " packets (" << len << " bytes) to send, msgno="
209
210
<< (w_msgno > 0 ? w_msgno : m_iNextMsgNo) << (inorder ? "" : " NOT") << " in order");
210
211
212
+
// Calculate origin time (same for all blocks of the message).
213
+
m_tsLastOriginTime = w_srctime ? time_point() + microseconds_from(w_srctime) : tnow;
214
+
// Rewrite back the actual value, even if it stays the same, so that the calling facilities can reuse it.
215
+
// May also be a subject to conversion error, thus the actual value is signalled back.
216
+
w_srctime = count_microseconds(m_tsLastOriginTime.time_since_epoch());
217
+
211
218
// The sequence number passed to this function is the sequence number
212
219
// that the very first packet from the packet series should get here.
213
220
// If there's more than one packet, this function must increase it by itself
@@ -253,33 +260,21 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
253
260
// [PB_FIRST] [PB_LAST] - 2 packets per message
254
261
// [PB_SOLO] - 1 packet per message
255
262
256
-
s->m_llSourceTime_us = w_srctime;
257
-
s->m_tsOriginTime = time;
258
-
s->m_tsRexmitTime = time_point();
259
263
s->m_iTTL = ttl;
260
-
// Rewrite the actual sending time back into w_srctime
261
-
// so that the calling facilities can reuse it
262
-
if (!w_srctime)
263
-
w_srctime = count_microseconds(s->m_tsOriginTime.time_since_epoch());
264
-
265
-
// XXX unchecked condition: s->m_pNext == NULL.
264
+
s->m_tsRexmitTime = time_point();
265
+
s->m_tsOriginTime = m_tsLastOriginTime;
266
+
266
267
// Should never happen, as the call to increase() should ensure enough buffers.
267
268
SRT_ASSERT(s->m_pNext);
268
269
s = s->m_pNext;
269
270
}
270
271
m_pLastBlock = s;
271
272
272
-
enterCS(m_BufLock);
273
273
m_iCount += size;
274
-
275
274
m_iBytesCount += len;
276
-
m_tsLastOriginTime = time;
277
275
278
-
updateInputRate(time, size, len);
279
-
280
-
updAvgBufSize(time);
281
-
282
-
leaveCS(m_BufLock);
276
+
updateInputRate(m_tsLastOriginTime, size, len);
277
+
updAvgBufSize(m_tsLastOriginTime);
283
278
284
279
// MSGNO_SEQ::mask has a form: 00000011111111...
285
280
// At least it's known that it's from some index inside til the end (to bit 0).
@@ -402,16 +397,6 @@ int CSndBuffer::addBufferFromFile(fstream& ifs, int len)
402
397
return total;
403
398
}
404
399
405
-
steady_clock::time_point CSndBuffer::getSourceTime(const CSndBuffer::Block& block)
406
-
{
407
-
if (block.m_llSourceTime_us)
408
-
{
409
-
return steady_clock::time_point() + microseconds_from(block.m_llSourceTime_us);
410
-
}
411
-
412
-
return block.m_tsOriginTime;
413
-
}
414
-
415
400
int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime, int kflgs)
416
401
{
417
402
// No data to read
@@ -459,7 +444,7 @@ int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime,
459
444
}
460
445
461
446
w_packet.m_iMsgNo = m_pCurrBlock->m_iMsgNoBitset;
462
-
w_srctime = getSourceTime(*m_pCurrBlock);
447
+
w_srctime = m_pCurrBlock->m_tsOriginTime;
463
448
m_pCurrBlock = m_pCurrBlock->m_pNext;
464
449
465
450
HLOGC(bslog.Debug, log << CONID() << "CSndBuffer: extracting packet size=" << readlen << " to send");
@@ -593,7 +578,7 @@ int CSndBuffer::readData(const int offset, CPacket& w_packet, steady_clock::time
593
578
// the packet originally (the other overload of this function) must set these
594
579
// flags.
595
580
w_packet.m_iMsgNo = p->m_iMsgNoBitset;
596
-
w_srctime = getSourceTime(*p);
581
+
w_srctime = p->m_tsOriginTime;
597
582
598
583
// This function is called when packet retransmission is triggered.
599
584
// Therefore we are setting the rexmit time.
@@ -683,11 +668,17 @@ int CSndBuffer::getCurrBufSize(int& w_bytes, int& w_timespan)
683
668
* Also, if there is only one pkt in buffer, the time difference will be 0.
684
669
* Therefore, always add 1 ms if not empty.
685
670
*/
686
-
w_timespan = 0 < m_iCount ? count_milliseconds(m_tsLastOriginTime - m_pFirstBlock->m_tsOriginTime) + 1 : 0;
671
+
w_timespan = 0 < m_iCount ? (int) count_milliseconds(m_tsLastOriginTime - m_pFirstBlock->m_tsOriginTime) + 1 : 0;
687
672
688
673
return m_iCount;
689
674
}
690
675
676
+
CSndBuffer::time_point CSndBuffer::getOldestTime() const
677
+
{
678
+
SRT_ASSERT(m_pFirstBlock);
679
+
return m_pFirstBlock->m_tsOriginTime;
680
+
}
681
+
691
682
int CSndBuffer::dropLateData(int& w_bytes, int32_t& w_first_msgno, const steady_clock::time_point& too_late_time)
692
683
{
693
684
int dpkts = 0;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4