mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 00:02:05 +02:00
Merge pull request #14163 from Atlante45/fix/bw-recorder
Fix crash with BandwidthRecorder
This commit is contained in:
commit
3c79a79487
5 changed files with 42 additions and 58 deletions
|
@ -52,7 +52,6 @@
|
|||
#include <RunningMarker.h>
|
||||
|
||||
#include "avatar/MyAvatar.h"
|
||||
#include "BandwidthRecorder.h"
|
||||
#include "FancyCamera.h"
|
||||
#include "ConnectionMonitor.h"
|
||||
#include "CursorManager.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
BandwidthRecorder::Channel::Channel() {
|
||||
}
|
||||
|
||||
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
|
||||
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() const {
|
||||
float averageTimeBetweenPackets = _input.getEventDeltaAverage();
|
||||
if (averageTimeBetweenPackets > 0.0f) {
|
||||
return (1.0f / averageTimeBetweenPackets);
|
||||
|
@ -26,7 +26,7 @@ float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
|
||||
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() const {
|
||||
float averageTimeBetweenPackets = _output.getEventDeltaAverage();
|
||||
if (averageTimeBetweenPackets > 0.0f) {
|
||||
return (1.0f / averageTimeBetweenPackets);
|
||||
|
@ -34,11 +34,11 @@ float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() {
|
||||
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() const {
|
||||
return (_input.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
||||
}
|
||||
|
||||
float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() {
|
||||
float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() const {
|
||||
return (_output.getAverageSampleValuePerSecond() * (8.0f / 1000));
|
||||
}
|
||||
|
||||
|
@ -77,35 +77,35 @@ void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int s
|
|||
_channels[channelType]->updateOutputAverage(sample);
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) {
|
||||
float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) const {
|
||||
if (! _channels[channelType]) {
|
||||
return 0.0f;
|
||||
}
|
||||
return _channels[channelType]->getAverageInputPacketsPerSecond();
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) {
|
||||
float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) const {
|
||||
if (! _channels[channelType]) {
|
||||
return 0.0f;
|
||||
}
|
||||
return _channels[channelType]->getAverageOutputPacketsPerSecond();
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) {
|
||||
float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) const {
|
||||
if (! _channels[channelType]) {
|
||||
return 0.0f;
|
||||
}
|
||||
return _channels[channelType]->getAverageInputKilobitsPerSecond();
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) {
|
||||
float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) const {
|
||||
if (! _channels[channelType]) {
|
||||
return 0.0f;
|
||||
}
|
||||
return _channels[channelType]->getAverageOutputKilobitsPerSecond();
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() {
|
||||
float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() const {
|
||||
float result = 0.0f;
|
||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||
if (_channels[i]) {
|
||||
|
@ -115,7 +115,7 @@ float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() {
|
|||
return result;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() {
|
||||
float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() const {
|
||||
float result = 0.0f;
|
||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||
if (_channels[i]) {
|
||||
|
@ -125,7 +125,7 @@ float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() {
|
|||
return result;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){
|
||||
float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond() const {
|
||||
float result = 0.0f;
|
||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||
if (_channels[i]) {
|
||||
|
@ -135,7 +135,7 @@ float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){
|
|||
return result;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){
|
||||
float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond() const {
|
||||
float result = 0.0f;
|
||||
for (uint i=0; i<CHANNEL_COUNT; i++) {
|
||||
if (_channels[i]) {
|
||||
|
@ -145,7 +145,7 @@ float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){
|
|||
return result;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
|
||||
float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() const {
|
||||
static qint64 lastCalculated = 0;
|
||||
static float cachedValue = 0.0f;
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
|
@ -156,7 +156,7 @@ float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
|
|||
return cachedValue;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
|
||||
float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() const {
|
||||
static qint64 lastCalculated = 0;
|
||||
static float cachedValue = 0.0f;
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
|
@ -167,7 +167,7 @@ float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
|
|||
return cachedValue;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
|
||||
float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() const {
|
||||
static qint64 lastCalculated = 0;
|
||||
static float cachedValue = 0.0f;
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
|
@ -178,7 +178,7 @@ float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
|
|||
return cachedValue;
|
||||
}
|
||||
|
||||
float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() {
|
||||
float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() const {
|
||||
static qint64 lastCalculated = 0;
|
||||
static float cachedValue = 0.0f;
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
|
|
|
@ -32,33 +32,33 @@ public:
|
|||
class Channel {
|
||||
public:
|
||||
Channel();
|
||||
float getAverageInputPacketsPerSecond();
|
||||
float getAverageOutputPacketsPerSecond();
|
||||
float getAverageInputKilobitsPerSecond();
|
||||
float getAverageOutputKilobitsPerSecond();
|
||||
float getAverageInputPacketsPerSecond() const;
|
||||
float getAverageOutputPacketsPerSecond() const;
|
||||
float getAverageInputKilobitsPerSecond() const;
|
||||
float getAverageOutputKilobitsPerSecond() const;
|
||||
|
||||
void updateInputAverage(const float sample);
|
||||
void updateOutputAverage(const float sample);
|
||||
|
||||
private:
|
||||
SimpleMovingAverage _input = SimpleMovingAverage();
|
||||
SimpleMovingAverage _output = SimpleMovingAverage();
|
||||
SimpleMovingAverage _input;
|
||||
SimpleMovingAverage _output;
|
||||
};
|
||||
|
||||
float getAverageInputPacketsPerSecond(const quint8 channelType);
|
||||
float getAverageOutputPacketsPerSecond(const quint8 channelType);
|
||||
float getAverageInputKilobitsPerSecond(const quint8 channelType);
|
||||
float getAverageOutputKilobitsPerSecond(const quint8 channelType);
|
||||
float getAverageInputPacketsPerSecond(const quint8 channelType) const;
|
||||
float getAverageOutputPacketsPerSecond(const quint8 channelType) const;
|
||||
float getAverageInputKilobitsPerSecond(const quint8 channelType) const;
|
||||
float getAverageOutputKilobitsPerSecond(const quint8 channelType) const;
|
||||
|
||||
float getTotalAverageInputPacketsPerSecond();
|
||||
float getTotalAverageOutputPacketsPerSecond();
|
||||
float getTotalAverageInputKilobitsPerSecond();
|
||||
float getTotalAverageOutputKilobitsPerSecond();
|
||||
float getTotalAverageInputPacketsPerSecond() const;
|
||||
float getTotalAverageOutputPacketsPerSecond() const;
|
||||
float getTotalAverageInputKilobitsPerSecond() const;
|
||||
float getTotalAverageOutputKilobitsPerSecond() const;
|
||||
|
||||
float getCachedTotalAverageInputPacketsPerSecond();
|
||||
float getCachedTotalAverageOutputPacketsPerSecond();
|
||||
float getCachedTotalAverageInputKilobitsPerSecond();
|
||||
float getCachedTotalAverageOutputKilobitsPerSecond();
|
||||
float getCachedTotalAverageInputPacketsPerSecond() const;
|
||||
float getCachedTotalAverageOutputPacketsPerSecond() const;
|
||||
float getCachedTotalAverageInputKilobitsPerSecond() const;
|
||||
float getCachedTotalAverageOutputKilobitsPerSecond() const;
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <SharedUtil.h>
|
||||
#include <UUID.h>
|
||||
|
||||
#include "BandwidthRecorder.h"
|
||||
#include "NetworkLogging.h"
|
||||
#include <Trace.h>
|
||||
#include "NodeType.h"
|
||||
|
@ -230,35 +229,18 @@ QDebug operator<<(QDebug debug, const NetworkPeer &peer) {
|
|||
return debug;
|
||||
}
|
||||
|
||||
|
||||
// FIXME this is a temporary implementation to determine if this is the right approach.
|
||||
// If so, migrate the BandwidthRecorder into the NetworkPeer class
|
||||
using BandwidthRecorderPtr = QSharedPointer<BandwidthRecorder>;
|
||||
static QHash<QUuid, BandwidthRecorderPtr> PEER_BANDWIDTH;
|
||||
|
||||
BandwidthRecorder& getBandwidthRecorder(const QUuid & uuid) {
|
||||
if (!PEER_BANDWIDTH.count(uuid)) {
|
||||
PEER_BANDWIDTH.insert(uuid, QSharedPointer<BandwidthRecorder>::create());
|
||||
}
|
||||
return *PEER_BANDWIDTH[uuid].data();
|
||||
}
|
||||
|
||||
void NetworkPeer::recordBytesSent(int count) const {
|
||||
auto& bw = getBandwidthRecorder(_uuid);
|
||||
bw.updateOutboundData(0, count);
|
||||
_bandwidthRecorder.updateOutboundData(0, count);
|
||||
}
|
||||
|
||||
void NetworkPeer::recordBytesReceived(int count) const {
|
||||
auto& bw = getBandwidthRecorder(_uuid);
|
||||
bw.updateInboundData(0, count);
|
||||
_bandwidthRecorder.updateInboundData(0, count);
|
||||
}
|
||||
|
||||
float NetworkPeer::getOutboundBandwidth() const {
|
||||
auto& bw = getBandwidthRecorder(_uuid);
|
||||
return bw.getAverageOutputKilobitsPerSecond(0);
|
||||
return _bandwidthRecorder.getAverageOutputKilobitsPerSecond(0);
|
||||
}
|
||||
|
||||
float NetworkPeer::getInboundBandwidth() const {
|
||||
auto& bw = getBandwidthRecorder(_uuid);
|
||||
return bw.getAverageInputKilobitsPerSecond(0);
|
||||
return _bandwidthRecorder.getAverageInputKilobitsPerSecond(0);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#include "UUID.h"
|
||||
#include "BandwidthRecorder.h"
|
||||
#include "HifiSockAddr.h"
|
||||
#include "UUID.h"
|
||||
|
||||
const QString ICE_SERVER_HOSTNAME = "localhost";
|
||||
const quint16 ICE_SERVER_DEFAULT_PORT = 7337;
|
||||
|
@ -113,6 +114,8 @@ protected:
|
|||
HifiSockAddr _symmetricSocket;
|
||||
HifiSockAddr* _activeSocket;
|
||||
|
||||
mutable BandwidthRecorder _bandwidthRecorder;
|
||||
|
||||
quint64 _wakeTimestamp;
|
||||
std::atomic_ullong _lastHeardMicrostamp;
|
||||
|
||||
|
|
Loading…
Reference in a new issue