hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
From 6608abd684dee8fb0f9e5d998f30df995049640c Mon Sep 17 00:00:00 2001
From: "jkand.huang" <jkand.huang@rock-chips.com>
Date: Fri, 8 May 2020 17:48:22 +0800
Subject: [PATCH] live555: The interval for sending MTU must more than 150us.
 
Signed-off-by: jkand.huang <jkand.huang@rock-chips.com>
---
 liveMedia/MultiFramedRTPSink.cpp        | 17 ++++++++++++++++-
 liveMedia/include/MultiFramedRTPSink.hh |  3 +++
 2 files changed, 19 insertions(+), 1 deletion(-)
 
diff --git a/liveMedia/MultiFramedRTPSink.cpp b/liveMedia/MultiFramedRTPSink.cpp
index 0554bf1..bf6f6af 100644
--- a/liveMedia/MultiFramedRTPSink.cpp
+++ b/liveMedia/MultiFramedRTPSink.cpp
@@ -53,6 +53,7 @@ MultiFramedRTPSink::MultiFramedRTPSink(UsageEnvironment& env,
         rtpPayloadFormatName, numChannels),
     fOutBuf(NULL), fCurFragmentationOffset(0), fPreviousFrameEndedFragmentation(False),
     fOnSendErrorFunc(NULL), fOnSendErrorData(NULL) {
+  clock_gettime(CLOCK_MONOTONIC, &fTimeLast);
   setPacketSizes((RTP_PAYLOAD_PREFERRED_SIZE), (RTP_PAYLOAD_MAX_SIZE));
 }
 
@@ -242,6 +243,7 @@ void MultiFramedRTPSink
   if (fIsFirstPacket) {
     // Record the fact that we're starting to play now:
     gettimeofday(&fNextSendTime, NULL);
+    clock_gettime(CLOCK_MONOTONIC, &fTimeLast);
   }
 
   fMostRecentPresentationTime = presentationTime;
@@ -371,6 +373,7 @@ void MultiFramedRTPSink::sendPacketIfNecessary() {
       if (!fRTPInterface.sendPacket(fOutBuf->packet(), fOutBuf->curPacketSize())) {
     // if failure handler has been specified, call it
     if (fOnSendErrorFunc != NULL) (*fOnSendErrorFunc)(fOnSendErrorData);
+    envir() << "=== sendPacketIfNecessary error ====.\n";
       }
     ++fPacketCount;
     fTotalOctetCount += fOutBuf->curPacketSize();
@@ -403,6 +406,7 @@ void MultiFramedRTPSink::sendPacketIfNecessary() {
     // We have more frames left to send.  Figure out when the next frame
     // is due to start playing, then make sure that we wait this long before
     // sending the next packet.
+  #if 0
     struct timeval timeNow;
     gettimeofday(&timeNow, NULL);
     int secsDiff = fNextSendTime.tv_sec - timeNow.tv_sec;
@@ -410,7 +414,18 @@ void MultiFramedRTPSink::sendPacketIfNecessary() {
     if (uSecondsToGo < 0 || secsDiff < 0) { // sanity check: Make sure that the time-to-delay is non-negative:
       uSecondsToGo = 0;
     }
-
+  #else
+    // 100Mbit/s == 10MBit/s == 10KBit/ms == 10Bit/us
+    // MTU == 1500Bit == 150us
+    struct timespec timeNow = {0, 0};
+    clock_gettime(CLOCK_MONOTONIC, &timeNow);
+    int64_t time_diff = (timeNow.tv_sec - fTimeLast.tv_sec)*1000000 + (timeNow.tv_nsec - fTimeLast.tv_nsec)/1000;
+    fTimeLast = timeNow;
+    int64_t uSecondsToGo =  (150 - time_diff);
+
+    if(uSecondsToGo < 0)
+        uSecondsToGo = 0;
+  #endif
     // Delay this amount of time:
     nextTask() = envir().taskScheduler().scheduleDelayedTask(uSecondsToGo, (TaskFunc*)sendNext, this);
   }
diff --git a/liveMedia/include/MultiFramedRTPSink.hh b/liveMedia/include/MultiFramedRTPSink.hh
index 63f1faa..ef8b7cc 100644
--- a/liveMedia/include/MultiFramedRTPSink.hh
+++ b/liveMedia/include/MultiFramedRTPSink.hh
@@ -26,6 +26,7 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
 #include "RTPSink.hh"
 #endif
 
+#include <time.h>
 class MultiFramedRTPSink: public RTPSink {
 public:
   void setPacketSizes(unsigned preferredPacketSize, unsigned maxPacketSize);
@@ -135,6 +136,8 @@ private:
 
   onSendErrorFunc* fOnSendErrorFunc;
   void* fOnSendErrorData;
+
+  struct timespec fTimeLast;
 };
 
 #endif
-- 
2.26.1