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