- ongoing work to ease jitter & RTT calculation

This commit is contained in:
Dmytro Bogovych 2023-04-11 13:43:38 +03:00
parent d90940c907
commit 0607bd1c47
14 changed files with 1071 additions and 1037 deletions

View File

@ -1,4 +1,4 @@
/* Copyright(C) 2007-2016 VoIP objects (voipobjects.com) /* Copyright(C) 2007-2023 VoIP objects (voipobjects.com)
* This Source Code Form is subject to the terms of the Mozilla Public * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

View File

@ -22,9 +22,9 @@
using namespace MT; using namespace MT;
AudioStream::AudioStream(const CodecList::Settings& settings) AudioStream::AudioStream(const CodecList::Settings& settings)
:mPacketTime(0), mEncodedTime(0), mCodecSettings(settings), :mPacketTime(0), mEncodedTime(0), mCodecSettings(settings),
mRemoteTelephoneCodec(0), mRtpSession(), mTransmittingPayloadType(-1), mRemoteTelephoneCodec(0), mRtpSession(), mTransmittingPayloadType(-1),
mRtpSender(mStat) mRtpSender(mStat)
{ {
mOutputBuffer.setCapacity(16384); mOutputBuffer.setCapacity(16384);
mCapturedAudio.setCapacity(16384); mCapturedAudio.setCapacity(16384);
@ -296,9 +296,9 @@ void AudioStream::dataArrived(PDatagramSocket s, const void* buffer, int length,
assert(info); assert(info);
// Drop RTP packets if stream is not receiving now; let RTCP go // Drop RTP packets if stream is not receiving now; let RTCP go
if (!(state() & (int)StreamState::Receiving) && RtpHelper::isRtp(buffer, length)) if (!(state() & (int)StreamState::Receiving) && RtpHelper::isRtpOrRtcp(buffer, length))
{ {
ICELogMedia(<< "Stream is not allowed to receive RTP stream. Ignore the packet"); ICELogMedia(<< "Stream is not allowed to receive RTP stream. Ignore the RT(C)P packet");
return; return;
} }
@ -320,8 +320,6 @@ void AudioStream::dataArrived(PDatagramSocket s, const void* buffer, int length,
} }
} }
//ICELogDebug(<< "Packet no: " << RtpHelper::findPacketNo(mReceiveBuffer, receiveLength));
switch (source.family()) switch (source.family())
{ {
case AF_INET: case AF_INET:
@ -360,6 +358,7 @@ void AudioStream::dataArrived(PDatagramSocket s, const void* buffer, int length,
if (packet) if (packet)
{ {
ICELogMedia(<< "jrtplib returned packet"); ICELogMedia(<< "jrtplib returned packet");
// Find right handler for rtp stream // Find right handler for rtp stream
SingleAudioStream* rtpStream = nullptr; SingleAudioStream* rtpStream = nullptr;
AudioStreamMap::iterator streamIter = mStreamMap.find(packet->GetSSRC()); AudioStreamMap::iterator streamIter = mStreamMap.find(packet->GetSSRC());

View File

@ -26,9 +26,9 @@
namespace MT namespace MT
{ {
class AudioStream: public Stream class AudioStream: public Stream
{ {
public: public:
AudioStream(const CodecList::Settings& codecSettings); AudioStream(const CodecList::Settings& codecSettings);
~AudioStream(); ~AudioStream();
@ -59,7 +59,7 @@ namespace MT
void setFinalStatisticsOutput(Statistics* stats); void setFinalStatisticsOutput(Statistics* stats);
protected: protected:
Audio::DataWindow mCapturedAudio; // Data from microphone Audio::DataWindow mCapturedAudio; // Data from microphone
Audio::DataWindow mStereoCapturedAudio; Audio::DataWindow mStereoCapturedAudio;
char mIncomingPcmBuffer[AUDIO_MIC_BUFFER_SIZE]; // Temporary buffer to allow reading from file char mIncomingPcmBuffer[AUDIO_MIC_BUFFER_SIZE]; // Temporary buffer to allow reading from file
@ -106,7 +106,7 @@ namespace MT
Statistics* mFinalStatistics = nullptr; Statistics* mFinalStatistics = nullptr;
bool decryptSrtp(void* data, int* len); bool decryptSrtp(void* data, int* len);
}; };
}; };
#endif #endif

View File

@ -40,7 +40,7 @@ PStream Terminal::createStream(int type, VariantMap& /*config*/)
switch (type) switch (type)
{ {
case Stream::Audio: case Stream::Audio:
result = PStream(new AudioStream(MT::CodecList::Settings::DefaultSettings)); result = std::make_shared<AudioStream>(MT::CodecList::Settings::DefaultSettings);
mAudioList.add(result); mAudioList.add(result);
break; break;

View File

@ -100,6 +100,7 @@ RTCPScheduler::~RTCPScheduler()
void RTCPScheduler::Reset() void RTCPScheduler::Reset()
{ {
pmembers = 0;
headeroverhead = 0; // user has to set this to an appropriate value headeroverhead = 0; // user has to set this to an appropriate value
hassentrtcp = false; hassentrtcp = false;
firstcall = true; firstcall = true;

View File

@ -900,9 +900,26 @@ void RTPExternalTransmitter::InjectRTPorRTCP(const void *data, size_t len, const
AbortWaitInternal(); AbortWaitInternal();
MAINMUTEX_UNLOCK MAINMUTEX_UNLOCK
} }
void RTPExternalTransmitter::InjectRaw(RTPRawPacket* packet)
{
if (!init)
return;
MAINMUTEX_LOCK
if (!created)
{
MAINMUTEX_UNLOCK
return;
}
rawpacketlist.push_back(packet);
AbortWaitInternal();
MAINMUTEX_UNLOCK
}
#ifdef RTPDEBUG #ifdef RTPDEBUG
void RTPExternalTransmitter::Dump() void RTPExternalTransmitter::Dump()
{ {

View File

@ -96,6 +96,8 @@ public:
/** Use this function to inject an RTP or RTCP packet and the transmitter will try to figure out which type of packet it is. */ /** Use this function to inject an RTP or RTCP packet and the transmitter will try to figure out which type of packet it is. */
void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a); void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
void InjectRaw(RTPRawPacket* packet);
private: private:
RTPExternalTransmitter *transmitter; RTPExternalTransmitter *transmitter;
}; };
@ -186,6 +188,8 @@ public:
void InjectRTP(const void *data, size_t len, const RTPAddress &a); void InjectRTP(const void *data, size_t len, const RTPAddress &a);
void InjectRTCP(const void *data, size_t len, const RTPAddress &a); void InjectRTCP(const void *data, size_t len, const RTPAddress &a);
void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a); void InjectRTPorRTCP(const void *data, size_t len, const RTPAddress &a);
void InjectRaw(RTPRawPacket* packet);
private: private:
void FlushPackets(); void FlushPackets();
@ -233,6 +237,11 @@ inline void RTPExternalPacketInjecter::InjectRTPorRTCP(const void *data, size_t
transmitter->InjectRTPorRTCP(data, len, a); transmitter->InjectRTPorRTCP(data, len, a);
} }
inline void RTPExternalPacketInjecter::InjectRaw(RTPRawPacket* packet)
{
transmitter->InjectRaw(packet);
}
} // end namespace } // end namespace
#endif // RTPTCPSOCKETTRANSMITTER_H #endif // RTPTCPSOCKETTRANSMITTER_H

View File

@ -1444,8 +1444,8 @@ int RTPSession::ProcessPolledData()
RTPTime colltimeout = RTPTime(Td*collisionmultiplier); RTPTime colltimeout = RTPTime(Td*collisionmultiplier);
RTPTime notetimeout = RTPTime(Td*notemultiplier); RTPTime notetimeout = RTPTime(Td*notemultiplier);
sources.MultipleTimeouts(t,sendertimeout,byetimeout,generaltimeout,notetimeout); // sources.MultipleTimeouts(t,sendertimeout,byetimeout,generaltimeout,notetimeout);
collisionlist.Timeout(t,colltimeout); // collisionlist.Timeout(t,colltimeout);
// We'll check if it's time for RTCP stuff // We'll check if it's time for RTCP stuff

View File

@ -55,6 +55,8 @@
#include <jthread/jmutex.h> #include <jthread/jmutex.h>
#endif // RTP_SUPPORT_THREAD #endif // RTP_SUPPORT_THREAD
#include <iostream>
namespace jrtplib namespace jrtplib
{ {
@ -474,7 +476,11 @@ protected:
const uint8_t *cname,size_t cnamelength) { } const uint8_t *cname,size_t cnamelength) { }
/** Is called when a new entry \c srcdat is added to the source table. */ /** Is called when a new entry \c srcdat is added to the source table. */
virtual void OnNewSource(RTPSourceData *srcdat) { } virtual void OnNewSource(RTPSourceData *srcdat)
{
// Sync timestamp unit
srcdat->SetTimestampUnit(timestampunit);
}
/** Is called when the entry \c srcdat is about to be deleted from the source table. */ /** Is called when the entry \c srcdat is about to be deleted from the source table. */
virtual void OnRemoveSource(RTPSourceData *srcdat) { } virtual void OnRemoveSource(RTPSourceData *srcdat) { }

View File

@ -35,12 +35,12 @@
#include "rtpaddress.h" #include "rtpaddress.h"
#include "rtpmemorymanager.h" #include "rtpmemorymanager.h"
#if ! (defined(WIN32) || defined(_WIN32_WCE)) #if ! (defined(WIN32) || defined(_WIN32_WCE))
#include <netinet/in.h> #include <netinet/in.h>
#endif // WIN32 #endif // WIN32
#ifdef RTPDEBUG #ifdef RTPDEBUG
#include <iostream> #include <iostream>
#include <string> #include <string>
#endif // RTPDEBUG #endif // RTPDEBUG
#include "rtpdebug.h" #include "rtpdebug.h"
@ -53,7 +53,7 @@
numnewpackets++; \ numnewpackets++; \
\ \
if (pack->GetExtendedSequenceNumber() == 0) \ if (pack->GetExtendedSequenceNumber() == 0) \
{ \ { \
baseseqnr = 0x0000FFFF; \ baseseqnr = 0x0000FFFF; \
numcycles = 0x00010000; \ numcycles = 0x00010000; \
} \ } \
@ -76,7 +76,7 @@ namespace jrtplib
{ {
void RTPSourceStats::ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,double tsunit, void RTPSourceStats::ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,double tsunit,
bool ownpacket,bool *accept,bool applyprobation,bool *onprobation) bool ownpacket, bool *accept, bool applyprobation, bool *onprobation)
{ {
// Note that the sequence number in the RTP packet is still just the // Note that the sequence number in the RTP packet is still just the
// 16 bit number contained in the RTP header // 16 bit number contained in the RTP header
@ -139,7 +139,7 @@ void RTPSourceStats::ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,do
ACCEPTPACKETCODE ACCEPTPACKETCODE
#endif // RTP_SUPPORT_PROBATION #endif // RTP_SUPPORT_PROBATION
} }
else // already got packets else // already got packets
{ {
@ -197,15 +197,15 @@ void RTPSourceStats::ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,do
djitter += diff; djitter += diff;
jitter = (uint32_t)djitter; jitter = (uint32_t)djitter;
#else #else
RTPTime curtime = receivetime; RTPTime curtime = receivetime;
double diffts1,diffts2,diff; double diffts1,diffts2,diff;
uint32_t curts = pack->GetTimestamp(); uint32_t curts = pack->GetTimestamp();
curtime -= prevpacktime; curtime -= prevpacktime;
diffts1 = curtime.GetDouble()/tsunit; diffts1 = curtime.GetDouble() / tsunit;
if (curts > prevtimestamp) if (curts > prevtimestamp)
{ {
uint32_t unsigneddiff = curts - prevtimestamp; uint32_t unsigneddiff = curts - prevtimestamp;
if (unsigneddiff < 0x10000000) // okay, curts realy is larger than prevtimestamp if (unsigneddiff < 0x10000000) // okay, curts realy is larger than prevtimestamp
@ -217,9 +217,9 @@ if (curts > prevtimestamp)
unsigneddiff = -unsigneddiff; // to get the actual difference (in absolute value) unsigneddiff = -unsigneddiff; // to get the actual difference (in absolute value)
diffts2 = -((double)unsigneddiff); diffts2 = -((double)unsigneddiff);
} }
} }
else if (curts < prevtimestamp) else if (curts < prevtimestamp)
{ {
uint32_t unsigneddiff = prevtimestamp - curts; uint32_t unsigneddiff = prevtimestamp - curts;
if (unsigneddiff < 0x10000000) // okay, curts really is smaller than prevtimestamp if (unsigneddiff < 0x10000000) // okay, curts really is smaller than prevtimestamp
@ -231,17 +231,17 @@ else if (curts < prevtimestamp)
unsigneddiff = -unsigneddiff; // to get the actual difference (in absolute value) unsigneddiff = -unsigneddiff; // to get the actual difference (in absolute value)
diffts2 = (double)unsigneddiff; diffts2 = (double)unsigneddiff;
} }
} }
else else
diffts2 = 0; diffts2 = 0;
diff = diffts1 - diffts2; diff = diffts1 - diffts2;
if (diff < 0) if (diff < 0)
diff = -diff; diff = -diff;
diff -= djitter; diff -= djitter;
diff /= 16.0; diff /= 16.0;
djitter += diff; djitter += diff;
jitter = (uint32_t)djitter; jitter = (uint32_t)djitter;
#endif #endif
} }
else else

View File

@ -809,6 +809,8 @@ int RTPSources::ObtainSourceDataInstance(uint32_t ssrc,RTPInternalSourceData **s
#endif // RTP_SUPPORT_PROBATION #endif // RTP_SUPPORT_PROBATION
if (srcdat2 == 0) if (srcdat2 == 0)
return ERR_RTP_OUTOFMEM; return ERR_RTP_OUTOFMEM;
// Add new source item
if ((status = sourcelist.AddElement(ssrc,srcdat2)) < 0) if ((status = sourcelist.AddElement(ssrc,srcdat2)) < 0)
{ {
RTPDelete(srcdat2,GetMemoryManager()); RTPDelete(srcdat2,GetMemoryManager());