forked from roc-streaming/roc-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roc-streaminggh-674 Refine packet_count and fract_loss calculations
- packet_count: On receiver, derive it from packet_count in SR, and handle 32-bit wraps. On sender, derive it from ext_first_sn and ext_last_sn, and also handle 32-bit wraps - fract_loss: automatically calculate loss ratio since last report based on packet_count and cum_loss
- Loading branch information
Showing
19 changed files
with
370 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 Roc Streaming authors | ||
* | ||
* 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 | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "roc_rtcp/loss_estimator.h" | ||
|
||
namespace roc { | ||
namespace rtcp { | ||
|
||
LossEstimator::LossEstimator() | ||
: prev_total_(0) | ||
, prev_lost_(0) { | ||
} | ||
|
||
float LossEstimator::update(const uint64_t total_packets, const int64_t lost_packets) { | ||
float fract_loss = 0; | ||
|
||
if (total_packets > prev_total_) { | ||
fract_loss = | ||
float(lost_packets - prev_lost_) / float(total_packets - prev_total_); | ||
} | ||
|
||
if (fract_loss < 0) { | ||
fract_loss = 0; | ||
} | ||
|
||
prev_total_ = total_packets; | ||
prev_lost_ = lost_packets; | ||
|
||
return fract_loss; | ||
} | ||
|
||
} // namespace rtcp | ||
} // namespace roc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 Roc Streaming authors | ||
* | ||
* 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 | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
//! @file roc_rtcp/loss_estimator.h | ||
//! @brief Loss estimator. | ||
|
||
#ifndef ROC_RTCP_LOSS_ESTIMATOR_H_ | ||
#define ROC_RTCP_LOSS_ESTIMATOR_H_ | ||
|
||
#include "roc_core/stddefs.h" | ||
|
||
namespace roc { | ||
namespace rtcp { | ||
|
||
//! Computes fractions loss ration since last report. | ||
class LossEstimator { | ||
public: | ||
//! Initialize. | ||
LossEstimator(); | ||
|
||
//! Update and return fractional loss ration since previous update. | ||
//! @p total_packets defines total count of packets expected. | ||
//! @p lost_packets defines count of packets not received, | ||
//! probably negative dues to duplicates. | ||
float update(uint64_t total_packets, int64_t lost_packets); | ||
|
||
private: | ||
uint64_t prev_total_; | ||
int64_t prev_lost_; | ||
}; | ||
|
||
} // namespace rtcp | ||
} // namespace roc | ||
|
||
#endif // ROC_RTCP_LOSS_ESTIMATOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Roc Streaming authors | ||
* | ||
* 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 | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "roc_rtcp/packet_counter.h" | ||
|
||
namespace roc { | ||
namespace rtcp { | ||
|
||
PacketCounter::PacketCounter() | ||
: first_update_(true) | ||
, begin64_(0) | ||
, end64_hi_(0) | ||
, end64_lo_(0) | ||
, counter_(0) { | ||
} | ||
|
||
uint64_t PacketCounter::update(const uint32_t begin, const uint32_t end) { | ||
// If this is first update, or begin was changed, reset state. | ||
if (first_update_ || begin != begin64_) { | ||
begin64_ = begin; | ||
end64_hi_ = 0; | ||
end64_lo_ = end; | ||
first_update_ = false; | ||
} | ||
|
||
// Update end. | ||
if (int32_t(end - end64_lo_) > 0) { | ||
if (end < end64_lo_) { | ||
end64_hi_ += (uint32_t)-1; | ||
} | ||
end64_lo_ = end; | ||
} | ||
|
||
// Update counter. | ||
if (begin64_ <= (end64_hi_ + end64_lo_)) { | ||
counter_ = (end64_hi_ + end64_lo_) - begin64_; | ||
} | ||
|
||
return counter_; | ||
} | ||
|
||
} // namespace rtcp | ||
} // namespace roc |
Oops, something went wrong.