diff --git a/src/engine/agent/Agent_Impl.cpp b/src/engine/agent/Agent_Impl.cpp index 85c43267..27cb4240 100644 --- a/src/engine/agent/Agent_Impl.cpp +++ b/src/engine/agent/Agent_Impl.cpp @@ -481,41 +481,6 @@ void AgentImpl::processWaitForEvent(JsonCpp::Value &request, JsonCpp::Value &ans answer["status"] = Status_Ok; } -#if defined(USE_PVQA_LIBRARY) -/*static JsonCpp::Value CsvReportToJson(const std::string& report) -{ - JsonCpp::Value detectorValues; - std::istringstream iss(report); - CsvReader reader(iss); - std::vector cells; - if (reader.readLine(cells)) - { - JsonCpp::Value detectorNames; - for (size_t nameIndex = 0; nameIndex < cells.size(); nameIndex++) - detectorNames[static_cast(nameIndex)] = strx::trim(cells[nameIndex]); - // Put first line name of columns - detectorValues[0] = detectorNames; - - int rowIndex = 1; - while (reader.readLine(cells)) - { - // Skip last column for now - JsonCpp::Value row; - for (size_t valueIndex = 0; valueIndex < cells.size(); valueIndex++) - { - bool isFloat = true; - float v = strx::toFloat(cells[valueIndex], 0.0, &isFloat); - if (isFloat) - row[static_cast(valueIndex)] = static_cast(v); - else - row[static_cast(valueIndex)] = cells[valueIndex]; - } - detectorValues[rowIndex++] = row; - } - } - return detectorValues; -}*/ -#endif void AgentImpl::processGetMediaStats(JsonCpp::Value& request, JsonCpp::Value& answer) { diff --git a/src/engine/endpoint/EP_Session.cpp b/src/engine/endpoint/EP_Session.cpp index d58b8b37..ac676ccd 100644 --- a/src/engine/endpoint/EP_Session.cpp +++ b/src/engine/endpoint/EP_Session.cpp @@ -445,7 +445,6 @@ void Session::getSessionInfo(Session::InfoOptions options, VariantMap& info) MT::Statistics stat; // Iterate all session providers - stat.reset(); Stream* media = nullptr; for (Stream& stream: mStreamList) { @@ -469,7 +468,7 @@ void Session::getSessionInfo(Session::InfoOptions options, VariantMap& info) info[SessionInfo_SentRtp] = static_cast(stat.mSentRtp); info[SessionInfo_SentRtcp] = static_cast(stat.mSentRtcp); if (stat.mFirstRtpTime) - info[SessionInfo_Duration] = static_cast(std::chrono::duration_cast(std::chrono::system_clock::now() - *(stat.mFirstRtpTime)).count()); + info[SessionInfo_Duration] = static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - *(stat.mFirstRtpTime)).count()); else info[SessionInfo_Duration] = 0; diff --git a/src/engine/helper/HL_Types.h b/src/engine/helper/HL_Types.h index 58cd4d83..d9ceeb26 100644 --- a/src/engine/helper/HL_Types.h +++ b/src/engine/helper/HL_Types.h @@ -157,4 +157,8 @@ private: std::unordered_map reverse_; }; +#include +typedef std::chrono::steady_clock::time_point timepoint_t; +typedef std::chrono::steady_clock monoclock_t; + #endif diff --git a/src/engine/media/MT_AudioStream.cpp b/src/engine/media/MT_AudioStream.cpp index 707ab922..3916c0ef 100644 --- a/src/engine/media/MT_AudioStream.cpp +++ b/src/engine/media/MT_AudioStream.cpp @@ -347,8 +347,8 @@ void AudioStream::dataArrived(PDatagramSocket s, const void* buffer, int length, mStat.mReceived += length; if (RtpHelper::isRtp(mReceiveBuffer, receiveLength)) { - if (!mStat.mFirstRtpTime.is_initialized()) - mStat.mFirstRtpTime = std::chrono::system_clock::now(); + if (!mStat.mFirstRtpTime) + mStat.mFirstRtpTime = std::chrono::steady_clock::now(); mStat.mReceivedRtp++; } else diff --git a/src/engine/media/MT_Statistics.cpp b/src/engine/media/MT_Statistics.cpp index 0afb9aa5..a0a7931e 100644 --- a/src/engine/media/MT_Statistics.cpp +++ b/src/engine/media/MT_Statistics.cpp @@ -1,9 +1,7 @@ -#include +#include #include #include "MT_Statistics.h" -#include "audio/Audio_Interface.h" -#include "helper/HL_Log.h" #define LOG_SUBSYSTEM "Statistics" using namespace MT; @@ -14,7 +12,7 @@ void JitterStatistics::process(jrtplib::RTPPacket* packet, int rate) uint32_t timestamp = packet->GetTimestamp(); jrtplib::RTPTime receiveTime = packet->GetReceiveTime(); - if (!mLastJitter.is_initialized()) + if (!mLastJitter) { // First packet mReceiveTime = receiveTime; @@ -69,40 +67,10 @@ void JitterStatistics::process(jrtplib::RTPPacket* packet, int rate) Statistics::Statistics() - :mReceived(0), mSent(0), mReceivedRtp(0), mSentRtp(0), - mReceivedRtcp(0), mSentRtcp(0), mDuplicatedRtp(0), mOldRtp(0), mIllegalRtp(0), - mPacketLoss(0), mJitter(0.0), mAudioTime(0), mDecodedSize(0), mSsrc(0), mPacketDropped(0) -{ - mBitrateSwitchCounter = 0; - memset(mLoss, 0, sizeof mLoss); - - // It is to keep track of statistics instance via grep | wc -l - //ICELogDebug(<< "Create statistics instance."); -} +{} Statistics::~Statistics() -{ -} - -void Statistics::reset() -{ - mReceived = 0; - mSent = 0; - mReceivedRtp = 0; - mSentRtp = 0; - mReceivedRtcp = 0; - mSentRtcp = 0; - mDuplicatedRtp = 0; - mOldRtp = 0; - mPacketLoss = 0; - mIllegalRtp = 0; - mJitter = 0.0; - mAudioTime = 0; - mPacketDropped = 0; - mDecodedSize = 0; - - memset(mLoss, 0, sizeof mLoss); -} +{} void Statistics::calculateBurstr(double* burstr, double* lossr) const { @@ -131,7 +99,7 @@ void Statistics::calculateBurstr(double* burstr, double* lossr) const } else *burstr = 0; - //printf("total loss: %d\n", lost); + if (mReceivedRtp > 0) *lossr = (double)((double)lost / (double)mReceivedRtp); else @@ -173,17 +141,17 @@ double Statistics::calculateMos(double maximalMos) const Statistics& Statistics::operator += (const Statistics& src) { - mReceived += src.mReceived; - mSent += src.mSent; - mReceivedRtp += src.mReceivedRtp; - mSentRtp += src.mSentRtp; - mReceivedRtcp += src.mReceivedRtcp; - mSentRtcp += src.mSentRtcp; - mDuplicatedRtp += src.mDuplicatedRtp; - mOldRtp += src.mOldRtp; - mPacketLoss += src.mPacketLoss; - mPacketDropped += src.mPacketDropped; - mAudioTime += src.mAudioTime; + mReceived += src.mReceived; + mSent += src.mSent; + mReceivedRtp += src.mReceivedRtp; + mSentRtp += src.mSentRtp; + mReceivedRtcp += src.mReceivedRtcp; + mSentRtcp += src.mSentRtcp; + mDuplicatedRtp += src.mDuplicatedRtp; + mOldRtp += src.mOldRtp; + mPacketLoss += src.mPacketLoss; + mPacketDropped += src.mPacketDropped; + mAudioTime += src.mAudioTime; for (auto codecStat: src.mCodecCount) @@ -194,49 +162,49 @@ Statistics& Statistics::operator += (const Statistics& src) mCodecCount[codecStat.first] += codecStat.second; } - mJitter = src.mJitter; - mRttDelay = src.mRttDelay; - mDecodingInterval = src.mDecodingInterval; - mDecodeRequested = src.mDecodeRequested; + mJitter = src.mJitter; + mRttDelay = src.mRttDelay; + mDecodingInterval = src.mDecodingInterval; + mDecodeRequested = src.mDecodeRequested; if (!src.mCodecName.empty()) mCodecName = src.mCodecName; // Find minimal - if (mFirstRtpTime.is_initialized()) + if (mFirstRtpTime) { - if (src.mFirstRtpTime.is_initialized()) + if (src.mFirstRtpTime) { if (mFirstRtpTime.value() > src.mFirstRtpTime.value()) mFirstRtpTime = src.mFirstRtpTime; } } else - if (src.mFirstRtpTime.is_initialized()) - mFirstRtpTime = src.mFirstRtpTime; + if (src.mFirstRtpTime) + mFirstRtpTime = src.mFirstRtpTime; - mBitrateSwitchCounter += src.mBitrateSwitchCounter; - mRemotePeer = src.mRemotePeer; - mSsrc = src.mSsrc; + mBitrateSwitchCounter += src.mBitrateSwitchCounter; + mRemotePeer = src.mRemotePeer; + mSsrc = src.mSsrc; return *this; } Statistics& Statistics::operator -= (const Statistics& src) { - mReceived -= src.mReceived; - mSent -= src.mSent; - mReceivedRtp -= src.mReceivedRtp; - mIllegalRtp -= src.mIllegalRtp; - mSentRtp -= src.mSentRtp; - mReceivedRtcp -= src.mReceivedRtcp; - mSentRtcp -= src.mSentRtcp; - mDuplicatedRtp -= src.mDuplicatedRtp; - mOldRtp -= src.mOldRtp; - mPacketLoss -= src.mPacketLoss; - mPacketDropped -= src.mPacketDropped; + mReceived -= src.mReceived; + mSent -= src.mSent; + mReceivedRtp -= src.mReceivedRtp; + mIllegalRtp -= src.mIllegalRtp; + mSentRtp -= src.mSentRtp; + mReceivedRtcp -= src.mReceivedRtcp; + mSentRtcp -= src.mSentRtcp; + mDuplicatedRtp -= src.mDuplicatedRtp; + mOldRtp -= src.mOldRtp; + mPacketLoss -= src.mPacketLoss; + mPacketDropped -= src.mPacketDropped; + mAudioTime -= src.mAudioTime; - mAudioTime -= src.mAudioTime; for (auto codecStat: src.mCodecCount) { if (mCodecCount.find(codecStat.first) != mCodecCount.end()) @@ -250,13 +218,13 @@ Statistics& Statistics::operator -= (const Statistics& src) std::string Statistics::toString() const { std::ostringstream oss; - oss << "Received: " << mReceivedRtp - << ", lost: " << mPacketLoss - << ", dropped: " << mPacketDropped - << ", sent: " << mSentRtp - << ", decoding interval: " << mDecodingInterval.average() - << ", decode requested: " << mDecodeRequested.average() - << ", packet interval: " << mPacketInterval.average(); + oss << "Received: " << mReceivedRtp + << ", lost: " << mPacketLoss + << ", dropped: " << mPacketDropped + << ", sent: " << mSentRtp + << ", decoding interval: " << mDecodingInterval.average() + << ", decode requested: " << mDecodeRequested.average() + << ", packet interval: " << mPacketInterval.average(); return oss.str(); } diff --git a/src/engine/media/MT_Statistics.h b/src/engine/media/MT_Statistics.h index f479d30f..b5d1c6ac 100644 --- a/src/engine/media/MT_Statistics.h +++ b/src/engine/media/MT_Statistics.h @@ -3,15 +3,17 @@ #include #include +#include +#include #include "audio/Audio_DataWindow.h" #include "helper/HL_Optional.hpp" #include "helper/HL_Statistics.h" +#include "helper/HL_Types.h" #include "jrtplib/src/rtptimeutilities.h" #include "jrtplib/src/rtppacket.h" -using std::experimental::optional; namespace MT { @@ -33,59 +35,56 @@ public: protected: // Jitter calculation - jrtplib::RTPTime mReceiveTime = jrtplib::RTPTime(0,0); + jrtplib::RTPTime mReceiveTime = jrtplib::RTPTime(0,0); // Last timestamp from packet in units - uint32_t mReceiveTimestamp = 0; + uint32_t mReceiveTimestamp = 0; // It is classic jitter value in units - optional mLastJitter; + std::optional mLastJitter; // Some statistics for jitter value in seconds - TestResult mJitter; + TestResult mJitter; // Maximal delta in seconds - float mMaxDelta = 0.0f; + float mMaxDelta = 0.0f; }; class Statistics { public: - size_t mReceived = 0, // Received traffic in bytes - mSent = 0, // Sent traffic in bytes - mReceivedRtp = 0, // Number of received rtp packets - mSentRtp = 0, // Number of sent rtp packets - mReceivedRtcp = 0, // Number of received rtcp packets - mSentRtcp = 0, // Number of sent rtcp packets - mDuplicatedRtp = 0, // Number of received duplicated rtp packets - mOldRtp = 0, // Number of late rtp packets - mPacketLoss = 0, // Number of lost packets - mPacketDropped = 0, // Number of dropped packets (due to time unsync when playing)б - mIllegalRtp = 0; // Number of rtp packets with bad payload type + size_t mReceived = 0, // Received traffic in bytes + mSent = 0, // Sent traffic in bytes + mReceivedRtp = 0, // Number of received rtp packets + mSentRtp = 0, // Number of sent rtp packets + mReceivedRtcp = 0, // Number of received rtcp packets + mSentRtcp = 0, // Number of sent rtcp packets + mDuplicatedRtp = 0, // Number of received duplicated rtp packets + mOldRtp = 0, // Number of late rtp packets + mPacketLoss = 0, // Number of lost packets + mPacketDropped = 0, // Number of dropped packets (due to time unsync when playing)б + mIllegalRtp = 0; // Number of rtp packets with bad payload type - TestResult mDecodingInterval, // Average interval on call to packet decode - mDecodeRequested, // Average amount of requested audio frames to play - mPacketInterval; // Average interval between packet adding to jitter buffer + TestResult mDecodingInterval, // Average interval on call to packet decode + mDecodeRequested, // Average amount of requested audio frames to play + mPacketInterval; // Average interval between packet adding to jitter buffer - int mLoss[128] = {0}; // Every item is number of loss of corresping length - size_t mAudioTime = 0; // Decoded/found time in milliseconds - size_t mDecodedSize = 0; // Number of decoded bytes - uint16_t mSsrc = 0; // Last known SSRC ID in a RTP stream - ice::NetworkAddress mRemotePeer; // Last known remote RTP address + std::array mLoss = {0}; // Every item is number of loss of corresping length + size_t mAudioTime = 0; // Decoded/found time in milliseconds + size_t mDecodedSize = 0; // Number of decoded bytes + uint16_t mSsrc = 0; // Last known SSRC ID in a RTP stream + ice::NetworkAddress mRemotePeer; // Last known remote RTP address // AMR codec bitrate switch counter - int mBitrateSwitchCounter = 0; - - std::string mCodecName; - - float mJitter = 0.0f; // Jitter - - TestResult mRttDelay; // RTT delay + int mBitrateSwitchCounter = 0; + std::string mCodecName; + float mJitter = 0.0f; // Jitter + TestResult mRttDelay; // RTT delay // Timestamp when first RTP packet has arrived - optional mFirstRtpTime; + std::optional mFirstRtpTime; - std::map mCodecCount; // Stats on used codecs + std::map mCodecCount; // Stats on used codecs // It is to calculate network MOS void calculateBurstr(double* burstr, double* loss) const; @@ -98,11 +97,7 @@ public: Statistics& operator += (const Statistics& src); Statistics& operator -= (const Statistics& src); - float mNetworkMos = 0.0; -#if defined(USE_PVQA_LIBRARY) && !defined(PVQA_SERVER) - float mPvqaMos = 0.0; - std::string mPvqaReport; -#endif + float mNetworkMos = 0.0f; std::string toString() const; };