Unverified 提交 394d092e authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Issue 357 (#380)

* libwebrtc dep: always provide positive time values in int64_t type
* libwebrtc dep: replace assert() with MS_ASSERT()
* Fixes #357
上级 ae3674b8
......@@ -36,7 +36,7 @@ TargetRateConstraints ConvertConstraints(int min_bitrate_bps,
int max_bitrate_bps,
int start_bitrate_bps) {
TargetRateConstraints msg;
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMs());
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
msg.min_data_rate =
min_bitrate_bps >= 0 ? DataRate::bps(min_bitrate_bps) : DataRate::Zero();
msg.max_data_rate = max_bitrate_bps > 0 ? DataRate::bps(max_bitrate_bps)
......@@ -63,7 +63,7 @@ RtpTransportControllerSend::RtpTransportControllerSend(
observer_(nullptr),
controller_factory_override_(controller_factory),
process_interval_(controller_factory_override_->GetProcessInterval()),
last_report_block_time_(Timestamp::ms(DepLibUV::GetTimeMs())),
last_report_block_time_(Timestamp::ms(DepLibUV::GetTimeMsInt64())),
send_side_bwe_with_overhead_(
webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")),
transport_overhead_bytes_per_packet_(0),
......@@ -147,7 +147,7 @@ void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) {
MS_DEBUG_DEV("SignalNetworkState:%s", network_available ? "Up" : "Down");
NetworkAvailability msg;
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMs());
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
msg.network_available = network_available;
if (network_available_ == msg.network_available)
......@@ -194,7 +194,7 @@ void RtpTransportControllerSend::OnTransportOverheadChanged(
void RtpTransportControllerSend::OnReceivedEstimatedBitrate(uint32_t bitrate) {
RemoteBitrateReport msg;
msg.receive_time = Timestamp::ms(DepLibUV::GetTimeMs());
msg.receive_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
msg.bandwidth = DataRate::bps(bitrate);
PostUpdates(controller_->OnRemoteBitrateReport(msg));
......@@ -220,14 +220,14 @@ void RtpTransportControllerSend::OnAddPacket(
packet_info,
send_side_bwe_with_overhead_ ? transport_overhead_bytes_per_packet_.load()
: 0,
Timestamp::ms(DepLibUV::GetTimeMs()));
Timestamp::ms(DepLibUV::GetTimeMsInt64()));
}
void RtpTransportControllerSend::OnTransportFeedback(
const RTC::RTCP::FeedbackRtpTransportPacket& feedback) {
absl::optional<TransportPacketsFeedback> feedback_msg =
transport_feedback_adapter_.ProcessTransportFeedback(
feedback, Timestamp::ms(DepLibUV::GetTimeMs()));
feedback, Timestamp::ms(DepLibUV::GetTimeMsInt64()));
if (feedback_msg)
PostUpdates(controller_->OnTransportPacketsFeedback(*feedback_msg));
pacer_.UpdateOutstandingData(
......@@ -236,7 +236,7 @@ void RtpTransportControllerSend::OnTransportFeedback(
void RtpTransportControllerSend::OnRemoteNetworkEstimate(
NetworkStateEstimate estimate) {
estimate.update_time = Timestamp::ms(DepLibUV::GetTimeMs());
estimate.update_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
controller_->OnNetworkStateEstimate(estimate);
}
......@@ -258,7 +258,7 @@ void RtpTransportControllerSend::MaybeCreateControllers() {
control_handler_ = absl::make_unique<CongestionControlHandler>();
initial_config_.constraints.at_time =
Timestamp::ms(DepLibUV::GetTimeMs());
Timestamp::ms(DepLibUV::GetTimeMsInt64());
controller_ = controller_factory_override_->Create(initial_config_);
process_interval_ = controller_factory_override_->GetProcessInterval();
......@@ -271,13 +271,13 @@ void RtpTransportControllerSend::UpdateControllerWithTimeInterval() {
MS_ASSERT(controller_, "controller not set");
ProcessInterval msg;
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMs());
msg.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
PostUpdates(controller_->OnProcessInterval(msg));
}
void RtpTransportControllerSend::UpdateStreamsConfig() {
streams_config_.at_time = Timestamp::ms(DepLibUV::GetTimeMs());
streams_config_.at_time = Timestamp::ms(DepLibUV::GetTimeMsInt64());
if (controller_)
PostUpdates(controller_->OnStreamsConfig(streams_config_));
}
......
......@@ -85,7 +85,7 @@ void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t send_time_ms) {
bool state_changed = false;
if (alr_budget_.budget_ratio() > start_budget_level_ratio_ &&
!alr_started_time_ms_) {
alr_started_time_ms_.emplace(DepLibUV::GetTimeMs());
alr_started_time_ms_.emplace(DepLibUV::GetTimeMsInt64());
state_changed = true;
} else if (alr_budget_.budget_ratio() < stop_budget_level_ratio_ &&
alr_started_time_ms_) {
......
......@@ -53,7 +53,7 @@ PacedSender::PacedSender(PacketRouter* packet_router,
prober_(*field_trials_),
probing_send_failure_(false),
pacing_bitrate_kbps_(0),
time_last_process_us_(DepLibUV::GetTimeUs()),
time_last_process_us_(DepLibUV::GetTimeUsInt64()),
first_sent_packet_ms_(-1),
packet_counter_(0),
account_for_audio_(false) {
......@@ -66,7 +66,7 @@ void PacedSender::CreateProbeCluster(int bitrate_bps, int cluster_id) {
// TODO: REMOVE
// MS_DEBUG_DEV("---- bitrate_bps:%d, cluster_id:%d", bitrate_bps, cluster_id);
prober_.CreateProbeCluster(bitrate_bps, DepLibUV::GetTimeMs(), cluster_id);
prober_.CreateProbeCluster(bitrate_bps, DepLibUV::GetTimeMsInt64(), cluster_id);
}
void PacedSender::Pause() {
......@@ -138,7 +138,7 @@ void PacedSender::SetAccountForAudioPackets(bool account_for_audio) {
int64_t PacedSender::TimeUntilNextProcess() {
int64_t elapsed_time_us =
DepLibUV::GetTimeUs() - time_last_process_us_;
DepLibUV::GetTimeUsInt64() - time_last_process_us_;
int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
// When paused we wake up every 500 ms to send a padding packet to ensure
// we won't get stuck in the paused state due to no feedback being received.
......@@ -146,7 +146,7 @@ int64_t PacedSender::TimeUntilNextProcess() {
return std::max<int64_t>(kPausedProcessIntervalMs - elapsed_time_ms, 0);
if (prober_.IsProbing()) {
int64_t ret = prober_.TimeUntilNextProbe(DepLibUV::GetTimeMs());
int64_t ret = prober_.TimeUntilNextProbe(DepLibUV::GetTimeMsInt64());
if (ret > 0 || (ret == 0 && !probing_send_failure_))
return ret;
}
......@@ -167,7 +167,7 @@ int64_t PacedSender::UpdateTimeAndGetElapsedMs(int64_t now_us) {
}
void PacedSender::Process() {
int64_t now_us = DepLibUV::GetTimeUs();
int64_t now_us = DepLibUV::GetTimeUsInt64();
int64_t elapsed_time_ms = UpdateTimeAndGetElapsedMs(now_us);
if (paused_)
......@@ -221,7 +221,7 @@ void PacedSender::Process() {
if (bytes_sent != 0)
{
auto now = DepLibUV::GetTimeUs();
auto now = DepLibUV::GetTimeUsInt64();
OnPaddingSent(now, bytes_sent);
prober_.ProbeSent((now + 500) / 1000, bytes_sent);
......@@ -256,7 +256,7 @@ size_t PacedSender::PaddingBytesToAdd(
void PacedSender::OnPacketSent(size_t size) {
if (first_sent_packet_ms_ == -1)
first_sent_packet_ms_ = DepLibUV::GetTimeMs();
first_sent_packet_ms_ = DepLibUV::GetTimeMsInt64();
// Update media bytes sent.
UpdateBudgetWithBytesSent(size);
......
......@@ -20,10 +20,10 @@
#include "rtc_base/numerics/safe_minmax.h"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include <inttypes.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <string>
......@@ -365,7 +365,7 @@ DataRate AimdRateControl::ChangeBitrate(DataRate new_bitrate,
break;
default:
assert(false);
MS_THROW_ERROR("unknown rate control state");
}
return ClampBitrate(new_bitrate, estimated_throughput);
}
......@@ -436,7 +436,7 @@ void AimdRateControl::ChangeState(const RateControlInput& input,
rate_control_state_ = kRcHold;
break;
default:
assert(false);
MS_THROW_ERROR("unknown input.bw_state");
}
}
......
......@@ -16,8 +16,6 @@
#include "Logger.hpp"
#include <cassert>
namespace webrtc {
static const int kBurstDeltaThresholdMs = 5;
......@@ -40,9 +38,9 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
uint32_t* timestamp_delta,
int64_t* arrival_time_delta_ms,
int* packet_size_delta) {
assert(timestamp_delta != NULL);
assert(arrival_time_delta_ms != NULL);
assert(packet_size_delta != NULL);
MS_ASSERT(timestamp_delta != nullptr, "timestamp_delta is null");
MS_ASSERT(arrival_time_delta_ms != nullptr, "arrival_time_delta_ms is null");
MS_ASSERT(packet_size_delta != nullptr, "packet_size_delta is null");
bool calculated_deltas = false;
if (current_timestamp_group_.IsFirstPacket()) {
// We don't have enough data to update the filter, so we store it until we
......@@ -87,7 +85,9 @@ bool InterArrival::ComputeDeltas(uint32_t timestamp,
} else {
num_consecutive_reordered_packets_ = 0;
}
assert(*arrival_time_delta_ms >= 0);
MS_ASSERT(*arrival_time_delta_ms >= 0, "arrival_time_delta_ms is < 0");
*packet_size_delta = static_cast<int>(current_timestamp_group_.size) -
static_cast<int>(prev_timestamp_group_.size);
calculated_deltas = true;
......@@ -143,7 +143,11 @@ bool InterArrival::BelongsToBurst(int64_t arrival_time_ms,
if (!burst_grouping_) {
return false;
}
assert(current_timestamp_group_.complete_time_ms >= 0);
MS_ASSERT(
current_timestamp_group_.complete_time_ms >= 0,
"current_timestamp_group_.complete_time_ms < 0");
int64_t arrival_time_delta_ms =
arrival_time_ms - current_timestamp_group_.complete_time_ms;
uint32_t timestamp_diff = timestamp - current_timestamp_group_.timestamp;
......
......@@ -16,7 +16,6 @@
#include "Logger.hpp"
#include <assert.h>
#include <math.h>
#include <string.h>
#include <algorithm>
......@@ -108,7 +107,9 @@ void OveruseEstimator::Update(int64_t t_delta,
bool positive_semi_definite =
E_[0][0] + E_[1][1] >= 0 &&
E_[0][0] * E_[1][1] - E_[0][1] * E_[1][0] >= 0 && E_[0][0] >= 0;
assert(positive_semi_definite);
MS_ASSERT(positive_semi_definite, "positive_semi_definite is not true");
if (!positive_semi_definite) {
MS_ERROR("The over-use estimator's covariance matrix is no longer "
"semi-definite.");
......
......@@ -247,7 +247,7 @@ void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo(
uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift;
int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs;
int64_t now_ms = DepLibUV::GetTimeMs();
int64_t now_ms = DepLibUV::GetTimeMsInt64();
// TODO(holmer): SSRCs are only needed for REMB, should be broken out from
// here.
......
......@@ -3,6 +3,7 @@
#include "common.hpp"
#include <uv.h>
#include <limits>
class DepLibUV
{
......@@ -27,6 +28,36 @@ public:
{
return uv_hrtime();
}
// Used within libwebrtc dependency which uses int64_t possitive values for
// time representation.
static int64_t GetTimeMsInt64()
{
static constexpr uint64_t MaxInt64{ std::numeric_limits<int64_t>::max() };
uint64_t time = DepLibUV::GetTimeMs();
if (time > MaxInt64 )
{
time -= MaxInt64 - 1;
}
return static_cast<int64_t>(time);
}
// Used within libwebrtc dependency which uses int64_t possitive values for
// time representation.
static int64_t GetTimeUsInt64()
{
static constexpr uint64_t MaxInt64{ std::numeric_limits<int64_t>::max() };
uint64_t time = DepLibUV::GetTimeUs();
if (time > MaxInt64 )
{
time -= MaxInt64 - 1;
}
return static_cast<int64_t>(time);
}
private:
static uv_loop_t* loop;
......
......@@ -61,9 +61,9 @@ namespace RTC
void TransportDisconnected();
void InsertPacket(webrtc::RtpPacketSendInfo& packetInfo);
webrtc::PacedPacketInfo GetPacingInfo();
void PacketSent(webrtc::RtpPacketSendInfo& packetInfo, uint64_t nowMs);
void PacketSent(webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs);
void ReceiveEstimatedBitrate(uint32_t bitrate);
void ReceiveRtcpReceiverReport(const webrtc::RTCPReportBlock& report, float rtt, uint64_t nowMs);
void ReceiveRtcpReceiverReport(const webrtc::RTCPReportBlock& report, float rtt, int64_t nowMs);
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
void SetDesiredBitrate(uint32_t desiredBitrate, bool force);
const Bitrates& GetBitrates() const
......
......@@ -1632,7 +1632,7 @@ namespace RTC
// if (this->tccClient)
// {
// this->tccClient->ReceiveRtcpReceiverReport(report, consumer->GetRtt(),
// DepLibUV::GetTimeMs());
// DepLibUV::GetTimeMsInt64());
// }
continue;
......@@ -2255,7 +2255,7 @@ namespace RTC
auto* cb = new onSendCallback([tccClient, &packetInfo, senderBwe, &sentInfo](bool sent) {
if (sent)
{
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMs());
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
sentInfo.sentAtMs = DepLibUV::GetTimeMs();
......@@ -2267,7 +2267,7 @@ namespace RTC
#else
auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
if (sent)
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMs());
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
});
SendRtpPacket(packet, cb);
......
......@@ -87,7 +87,7 @@ namespace RTC
{
MS_TRACE();
auto nowMs = DepLibUV::GetTimeMs();
auto nowMs = DepLibUV::GetTimeMsInt64();
this->bitrates.desiredBitrate = 0u;
this->bitrates.effectiveDesiredBitrate = 0u;
......@@ -111,7 +111,7 @@ namespace RTC
return this->rtpTransportControllerSend->packet_sender()->GetPacingInfo();
}
void TransportCongestionControlClient::PacketSent(webrtc::RtpPacketSendInfo& packetInfo, uint64_t nowMs)
void TransportCongestionControlClient::PacketSent(webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs)
{
MS_TRACE();
......@@ -128,12 +128,12 @@ namespace RTC
}
void TransportCongestionControlClient::ReceiveRtcpReceiverReport(
const webrtc::RTCPReportBlock& report, float rtt, uint64_t nowMs)
const webrtc::RTCPReportBlock& report, float rtt, int64_t nowMs)
{
MS_TRACE();
this->rtpTransportControllerSend->OnReceivedRtcpReceiverReport(
{ report }, static_cast<int64_t>(rtt), static_cast<int64_t>(nowMs));
{ report }, static_cast<int64_t>(rtt), nowMs);
}
void TransportCongestionControlClient::ReceiveRtcpTransportFeedback(
......@@ -148,7 +148,7 @@ namespace RTC
{
MS_TRACE();
auto nowMs = DepLibUV::GetTimeMs();
auto nowMs = DepLibUV::GetTimeMsInt64();
// Manage it via trending and increase it a bit to avoid immediate oscillations.
if (!force)
......@@ -217,7 +217,7 @@ namespace RTC
{
MS_TRACE();
uint64_t nowMs = DepLibUV::GetTimeMs();
uint64_t nowMs = DepLibUV::GetTimeMsInt64();
bool notify{ false };
// Ignore if first event.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论