Browse Source

Merge pull request #1429 from petersomers/find-ntp

Add getter for sync NTPTS and RTPTS values in RtcpReceivingSession
Paul-Louis Ageneau 4 weeks ago
parent
commit
de793370c4
2 changed files with 23 additions and 5 deletions
  1. 10 1
      include/rtc/rtcpreceivingsession.hpp
  2. 13 4
      src/rtcpreceivingsession.cpp

+ 10 - 1
include/rtc/rtcpreceivingsession.hpp

@@ -18,6 +18,7 @@
 #include "rtp.hpp"
 
 #include <atomic>
+#include <mutex>
 
 #define RTP_SEQ_MOD (1<<16)
 
@@ -37,6 +38,13 @@ public:
 	[[deprecated("Use Track::requestKeyframe()")]] inline bool requestKeyframe() { return false; };
 	[[deprecated("Use Track::requestBitrate()")]] inline void requestBitrate(unsigned int) {};
 
+	struct SyncTimestamps {
+		uint64_t rtpTimestamp;
+		uint64_t ntpTimestamp;
+	};
+
+	SyncTimestamps getSyncTimestamps();
+
 protected:
 	void pushREMB(const message_callback &send, unsigned int bitrate);
 	void pushRR(const message_callback &send,unsigned int lastSrDelay);
@@ -58,9 +66,10 @@ protected:
 	uint32_t mTransit = 0;			// relative trans time for prev pkt
 	uint32_t mJitter = 0;	
 	
-	uint64_t mSyncRTPTS, mSyncNTPTS;
+	SyncTimestamps mSyncTimestamps{0,0};
 
 	std::atomic<unsigned int> mRequestedBitrate = 0;
+	std::mutex mSyncMutex;
 };
 
 } // namespace rtc

+ 13 - 4
src/rtcpreceivingsession.cpp

@@ -15,6 +15,7 @@
 #include "impl/logcounter.hpp"
 
 #include <cmath>
+#include <mutex>
 #include <utility>
 
 #ifdef _WIN32
@@ -32,6 +33,11 @@ static impl::LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning,
 static impl::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning,
                                                 "Number of unknown SCTP_STATUS errors");
 
+RtcpReceivingSession::SyncTimestamps RtcpReceivingSession::getSyncTimestamps(){
+	std::lock_guard lock(mSyncMutex);
+	return mSyncTimestamps;
+}
+
 void RtcpReceivingSession::incoming(message_vector &messages, const message_callback &send) {
 	message_vector result;
 	for (auto message : messages) {
@@ -74,8 +80,11 @@ void RtcpReceivingSession::incoming(message_vector &messages, const message_call
 			} else if (rr->header.payloadType() == 200) { // SR
 				mSsrc = rr->senderSSRC();
 				auto sr = reinterpret_cast<const RtcpSr *>(message->data());
-				mSyncRTPTS = sr->rtpTimestamp();
-				mSyncNTPTS = sr->ntpTimestamp();
+				{
+					std::lock_guard lock(mSyncMutex);
+					mSyncTimestamps.rtpTimestamp = sr->rtpTimestamp();
+					mSyncTimestamps.ntpTimestamp = sr->ntpTimestamp();
+				}
 				sr->log();
 
 				// TODO For the time being, we will send RR's/REMB's when we get an SR
@@ -136,8 +145,8 @@ void RtcpReceivingSession::pushRR(const message_callback &send, unsigned int las
 	else { 
 		fraction = (lost_interval << 8) / expected_interval;
 	}
-
-	rr->getReportBlock(0)->preparePacket(mSsrc, fraction, lost, uint16_t(mGreatestSeqNo), mMaxSeq, 0, mSyncNTPTS,
+	auto syncTimestamps = getSyncTimestamps();
+	rr->getReportBlock(0)->preparePacket(mSsrc, fraction, lost, uint16_t(mGreatestSeqNo), mMaxSeq, 0, syncTimestamps.ntpTimestamp,
 	                                     lastSrDelay);
 	rr->log();
 	send(message);