Chromium Code Reviews| Index: webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc |
| diff --git a/webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc b/webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc |
| index c13f14437a5239be926acfeb7d6b7a772d35f239..942ceca5d4ba2b3a76fe68f991d1cf7191e2c1ad 100644 |
| --- a/webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc |
| +++ b/webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc |
| @@ -10,7 +10,6 @@ |
| #include "webrtc/modules/remote_bitrate_estimator/test/packet_receiver.h" |
| -#include <math.h> |
| #include <vector> |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -29,35 +28,52 @@ PacketReceiver::PacketReceiver(PacketProcessorListener* listener, |
| int flow_id, |
| BandwidthEstimatorType bwe_type, |
| bool plot_delay, |
| - bool plot_bwe) |
| + bool plot_bwe, |
| + MetricRecorder* metric_recorder) |
| : PacketProcessor(listener, flow_id, kReceiver), |
| - delay_log_prefix_(), |
| - metric_log_prefix_(), |
| - packet_loss_log_prefix_(), |
| - last_delay_plot_ms_(0), |
| - last_metric_plot_ms_(0), |
| - last_packet_loss_plot_ms_(0), |
| - plot_delay_(plot_delay), |
| - // TODO(magalhaesc) Add separated plot_objective_function and |
| - // plot_packet_loss parameters to the constructor. |
| - plot_objective_function_(plot_delay), |
| - plot_packet_loss_(plot_delay), |
| bwe_receiver_(CreateBweReceiver(bwe_type, flow_id, plot_bwe)), |
| - total_delay_ms_(0), |
| - total_throughput_(0), |
| - number_packets_(0) { |
| - // Setup the prefix ststd::rings used when logging. |
| - std::stringstream ss1; |
| - ss1 << "Delay_" << flow_id << "#2"; |
| - delay_log_prefix_ = ss1.str(); |
| - |
| - std::stringstream ss2; |
| - ss2 << "Objective_function_" << flow_id << "#2"; |
| - metric_log_prefix_ = ss2.str(); |
| - |
| - std::stringstream ss3; |
| - ss3 << "Packet_Loss_" << flow_id << "#2"; |
| - packet_loss_log_prefix_ = ss3.str(); |
| + metric_recorder_(metric_recorder) { |
| + if (metric_recorder_ != nullptr) { |
| + // Setup the prefix ststd::rings used when logging. |
| + std::vector<std::string> prefixs; |
|
stefan-webrtc
2015/07/06 08:24:51
prefixes
magalhaesc
2015/07/06 09:28:07
Done.
|
| + |
| + std::stringstream ss1; |
| + ss1 << "Throughput_kbps_" << flow_id << "#2"; |
| + prefixs.push_back(ss1.str()); // Throughput. |
| + |
| + std::stringstream ss2; |
| + ss2 << "Delay_ms_" << flow_id << "#2"; |
| + prefixs.push_back(ss2.str()); // Delay. |
| + |
| + std::stringstream ss3; |
| + ss3 << "Packet_Loss_" << flow_id << "#2"; |
| + prefixs.push_back(ss3.str()); // Loss. |
| + |
| + std::stringstream ss4; |
| + ss4 << "Objective_function_" << flow_id << "#2"; |
| + prefixs.push_back(ss4.str()); // Objective. |
| + |
| + // Plot Total/PerFlow Available capacity together with throughputs. |
| + std::stringstream ss5; |
| + ss5 << "Throughput_kbps" << flow_id << "#1"; |
| + prefixs.push_back(ss5.str()); // Total Available. |
| + prefixs.push_back(ss5.str()); // Available per flow. |
| + |
| + metric_recorder_->SetPlotInformation(prefixs); |
| + } |
| +} |
| + |
| +PacketReceiver::PacketReceiver(PacketProcessorListener* listener, |
| + int flow_id, |
| + BandwidthEstimatorType bwe_type, |
| + bool plot_delay, |
| + bool plot_bwe) |
| + : PacketReceiver(listener, |
| + flow_id, |
| + bwe_type, |
| + plot_delay, |
| + plot_bwe, |
| + nullptr) { |
| } |
| PacketReceiver::~PacketReceiver() { |
| @@ -80,13 +96,13 @@ void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) { |
| int64_t arrival_time_ms = (media_packet->send_time_us() + 500) / 1000; |
| int64_t send_time_ms = (media_packet->creation_time_us() + 500) / 1000; |
| delay_stats_.Push(arrival_time_ms - send_time_ms); |
| - PlotDelay(arrival_time_ms, send_time_ms); |
| - PlotObjectiveFunction(arrival_time_ms); |
| - PlotPacketLoss(arrival_time_ms); |
| - total_delay_ms_ += arrival_time_ms - send_time_ms; |
| - total_throughput_ += media_packet->payload_size(); |
| - ++number_packets_; |
| + if (metric_recorder_ != nullptr) { |
| + metric_recorder_->UpdateTime(arrival_time_ms); |
| + UpdateMetrics(arrival_time_ms, send_time_ms, |
| + media_packet->payload_size()); |
| + metric_recorder_->PlotAllDynamics(); |
| + } |
| bwe_receiver_->ReceivePacket(arrival_time_ms, *media_packet); |
| FeedbackPacket* fb = bwe_receiver_->GetFeedback(arrival_time_ms); |
| @@ -102,46 +118,17 @@ void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) { |
| in_out->merge(feedback, DereferencingComparator<Packet>); |
| } |
| -void PacketReceiver::PlotDelay(int64_t arrival_time_ms, int64_t send_time_ms) { |
| - static const int kDelayPlotIntervalMs = 100; |
| - if (!plot_delay_) |
| - return; |
| - if (arrival_time_ms - last_delay_plot_ms_ > kDelayPlotIntervalMs) { |
| - BWE_TEST_LOGGING_PLOT(0, delay_log_prefix_, arrival_time_ms, |
| - arrival_time_ms - send_time_ms); |
| - last_delay_plot_ms_ = arrival_time_ms; |
| - } |
| -} |
| - |
| -double PacketReceiver::ObjectiveFunction() { |
| - const double kDelta = 1.0; // Delay penalty factor. |
| - double throughput_metric = log(static_cast<double>(total_throughput_)); |
| - double delay_penalty = kDelta * log(static_cast<double>(total_delay_ms_)); |
| - return throughput_metric - delay_penalty; |
| +void PacketReceiver::UpdateMetrics(int64_t arrival_time_ms, |
| + int64_t send_time_ms, |
| + size_t payload_size) { |
| + metric_recorder_->UpdateThroughput(bwe_receiver_->RecentKbps(), payload_size); |
| + metric_recorder_->UpdateDelay(arrival_time_ms - send_time_ms); |
| + metric_recorder_->UpdateLoss(bwe_receiver_->RecentPacketLossRatio()); |
| + metric_recorder_->UpdateObjective(); |
| } |
| -void PacketReceiver::PlotObjectiveFunction(int64_t arrival_time_ms) { |
| - static const int kMetricPlotIntervalMs = 1000; |
| - if (!plot_objective_function_) { |
| - return; |
| - } |
| - if (arrival_time_ms - last_metric_plot_ms_ > kMetricPlotIntervalMs) { |
| - BWE_TEST_LOGGING_PLOT(1, metric_log_prefix_, arrival_time_ms, |
| - ObjectiveFunction()); |
| - last_metric_plot_ms_ = arrival_time_ms; |
| - } |
| -} |
| - |
| -void PacketReceiver::PlotPacketLoss(int64_t arrival_time_ms) { |
| - static const int kPacketLossPlotIntervalMs = 500; |
| - if (!plot_packet_loss_) { |
| - return; |
| - } |
| - if (arrival_time_ms - last_packet_loss_plot_ms_ > kPacketLossPlotIntervalMs) { |
| - BWE_TEST_LOGGING_PLOT(2, packet_loss_log_prefix_, arrival_time_ms, |
| - bwe_receiver_->RecentPacketLossRatio()); |
| - last_packet_loss_plot_ms_ = arrival_time_ms; |
| - } |
| +float PacketReceiver::GlobalPacketLoss() { |
| + return bwe_receiver_->GlobalReceiverPacketLossRatio(); |
| } |
| Stats<double> PacketReceiver::GetDelayStats() const { |