Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1144)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/packet_receiver.cc

Issue 1202253003: More Simulation Framework features (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Using rtc::scoped_ptr on nada_unittest.cc Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/remote_bitrate_estimator/test/packet_receiver.h" 11 #include "webrtc/modules/remote_bitrate_estimator/test/packet_receiver.h"
12 12
13 #include <math.h>
14 #include <vector> 13 #include <vector>
15 14
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/base/common.h" 16 #include "webrtc/base/common.h"
18 #include "webrtc/modules/interface/module_common_types.h" 17 #include "webrtc/modules/interface/module_common_types.h"
19 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h" 18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe.h"
20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" 19 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h"
21 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" 20 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
22 #include "webrtc/system_wrappers/interface/clock.h" 21 #include "webrtc/system_wrappers/interface/clock.h"
23 22
24 namespace webrtc { 23 namespace webrtc {
25 namespace testing { 24 namespace testing {
26 namespace bwe { 25 namespace bwe {
27 26
28 PacketReceiver::PacketReceiver(PacketProcessorListener* listener, 27 PacketReceiver::PacketReceiver(PacketProcessorListener* listener,
29 int flow_id, 28 int flow_id,
30 BandwidthEstimatorType bwe_type, 29 BandwidthEstimatorType bwe_type,
31 bool plot_delay, 30 bool plot_delay,
31 bool plot_bwe,
32 MetricRecorder* metric_recorder)
33 : PacketProcessor(listener, flow_id, kReceiver),
34 bwe_receiver_(CreateBweReceiver(bwe_type, flow_id, plot_bwe)),
35 metric_recorder_(metric_recorder) {
36 if (metric_recorder_ != nullptr) {
37 // Setup the prefix ststd::rings used when logging.
38 std::vector<std::string> prefixes;
39
40 std::stringstream ss1;
41 ss1 << "Throughput_kbps_" << flow_id << "#2";
42 prefixes.push_back(ss1.str()); // Throughput.
43
44 std::stringstream ss2;
45 ss2 << "Delay_ms_" << flow_id << "#2";
46 prefixes.push_back(ss2.str()); // Delay.
47
48 std::stringstream ss3;
49 ss3 << "Packet_Loss_" << flow_id << "#2";
50 prefixes.push_back(ss3.str()); // Loss.
51
52 std::stringstream ss4;
53 ss4 << "Objective_function_" << flow_id << "#2";
54 prefixes.push_back(ss4.str()); // Objective.
55
56 // Plot Total/PerFlow Available capacity together with throughputs.
57 std::stringstream ss5;
58 ss5 << "Throughput_kbps" << flow_id << "#1";
59 prefixes.push_back(ss5.str()); // Total Available.
60 prefixes.push_back(ss5.str()); // Available per flow.
61
62 metric_recorder_->SetPlotInformation(prefixes);
63 }
64 }
65
66 PacketReceiver::PacketReceiver(PacketProcessorListener* listener,
67 int flow_id,
68 BandwidthEstimatorType bwe_type,
69 bool plot_delay,
32 bool plot_bwe) 70 bool plot_bwe)
33 : PacketProcessor(listener, flow_id, kReceiver), 71 : PacketReceiver(listener,
34 delay_log_prefix_(), 72 flow_id,
35 metric_log_prefix_(), 73 bwe_type,
36 packet_loss_log_prefix_(), 74 plot_delay,
37 last_delay_plot_ms_(0), 75 plot_bwe,
38 last_metric_plot_ms_(0), 76 nullptr) {
39 last_packet_loss_plot_ms_(0),
40 plot_delay_(plot_delay),
41 // TODO(magalhaesc) Add separated plot_objective_function and
42 // plot_packet_loss parameters to the constructor.
43 plot_objective_function_(plot_delay),
44 plot_packet_loss_(plot_delay),
45 bwe_receiver_(CreateBweReceiver(bwe_type, flow_id, plot_bwe)),
46 total_delay_ms_(0),
47 total_throughput_(0),
48 number_packets_(0) {
49 // Setup the prefix ststd::rings used when logging.
50 std::stringstream ss1;
51 ss1 << "Delay_" << flow_id << "#2";
52 delay_log_prefix_ = ss1.str();
53
54 std::stringstream ss2;
55 ss2 << "Objective_function_" << flow_id << "#2";
56 metric_log_prefix_ = ss2.str();
57
58 std::stringstream ss3;
59 ss3 << "Packet_Loss_" << flow_id << "#2";
60 packet_loss_log_prefix_ = ss3.str();
61 } 77 }
62 78
63 PacketReceiver::~PacketReceiver() { 79 PacketReceiver::~PacketReceiver() {
64 } 80 }
65 81
66 void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) { 82 void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) {
67 Packets feedback; 83 Packets feedback;
68 for (auto it = in_out->begin(); it != in_out->end();) { 84 for (auto it = in_out->begin(); it != in_out->end();) {
69 // PacketReceivers are only associated with a single stream, and therefore 85 // PacketReceivers are only associated with a single stream, and therefore
70 // should only process a single flow id. 86 // should only process a single flow id.
71 // TODO(holmer): Break this out into a Demuxer which implements both 87 // TODO(holmer): Break this out into a Demuxer which implements both
72 // PacketProcessorListener and PacketProcessor. 88 // PacketProcessorListener and PacketProcessor.
73 BWE_TEST_LOGGING_CONTEXT("Receiver"); 89 BWE_TEST_LOGGING_CONTEXT("Receiver");
74 if ((*it)->GetPacketType() == Packet::kMedia && 90 if ((*it)->GetPacketType() == Packet::kMedia &&
75 (*it)->flow_id() == *flow_ids().begin()) { 91 (*it)->flow_id() == *flow_ids().begin()) {
76 BWE_TEST_LOGGING_CONTEXT(*flow_ids().begin()); 92 BWE_TEST_LOGGING_CONTEXT(*flow_ids().begin());
77 const MediaPacket* media_packet = static_cast<const MediaPacket*>(*it); 93 const MediaPacket* media_packet = static_cast<const MediaPacket*>(*it);
78 // We're treating the send time (from previous filter) as the arrival 94 // We're treating the send time (from previous filter) as the arrival
79 // time once packet reaches the estimator. 95 // time once packet reaches the estimator.
80 int64_t arrival_time_ms = (media_packet->send_time_us() + 500) / 1000; 96 int64_t arrival_time_ms = media_packet->send_time_ms();
81 int64_t send_time_ms = (media_packet->creation_time_us() + 500) / 1000; 97 int64_t send_time_ms = media_packet->creation_time_ms();
82 delay_stats_.Push(arrival_time_ms - send_time_ms); 98 delay_stats_.Push(arrival_time_ms - send_time_ms);
83 PlotDelay(arrival_time_ms, send_time_ms);
84 PlotObjectiveFunction(arrival_time_ms);
85 PlotPacketLoss(arrival_time_ms);
86 99
87 total_delay_ms_ += arrival_time_ms - send_time_ms; 100 if (metric_recorder_ != nullptr) {
88 total_throughput_ += media_packet->payload_size(); 101 metric_recorder_->UpdateTime(arrival_time_ms);
89 ++number_packets_; 102 UpdateMetrics(arrival_time_ms, send_time_ms,
103 media_packet->payload_size());
104 metric_recorder_->PlotAllDynamics();
105 }
90 106
91 bwe_receiver_->ReceivePacket(arrival_time_ms, *media_packet); 107 bwe_receiver_->ReceivePacket(arrival_time_ms, *media_packet);
92 FeedbackPacket* fb = bwe_receiver_->GetFeedback(arrival_time_ms); 108 FeedbackPacket* fb = bwe_receiver_->GetFeedback(arrival_time_ms);
93 if (fb) 109 if (fb)
94 feedback.push_back(fb); 110 feedback.push_back(fb);
95 delete media_packet; 111 delete media_packet;
96 it = in_out->erase(it); 112 it = in_out->erase(it);
97 } else { 113 } else {
98 ++it; 114 ++it;
99 } 115 }
100 } 116 }
101 // Insert feedback packets to be sent back to the sender. 117 // Insert feedback packets to be sent back to the sender.
102 in_out->merge(feedback, DereferencingComparator<Packet>); 118 in_out->merge(feedback, DereferencingComparator<Packet>);
103 } 119 }
104 120
105 void PacketReceiver::PlotDelay(int64_t arrival_time_ms, int64_t send_time_ms) { 121 void PacketReceiver::UpdateMetrics(int64_t arrival_time_ms,
106 static const int kDelayPlotIntervalMs = 100; 122 int64_t send_time_ms,
107 if (!plot_delay_) 123 size_t payload_size) {
108 return; 124 metric_recorder_->UpdateThroughput(bwe_receiver_->RecentKbps(), payload_size);
109 if (arrival_time_ms - last_delay_plot_ms_ > kDelayPlotIntervalMs) { 125 metric_recorder_->UpdateDelay(arrival_time_ms - send_time_ms);
110 BWE_TEST_LOGGING_PLOT(0, delay_log_prefix_, arrival_time_ms, 126 metric_recorder_->UpdateLoss(bwe_receiver_->RecentPacketLossRatio());
111 arrival_time_ms - send_time_ms); 127 metric_recorder_->UpdateObjective();
112 last_delay_plot_ms_ = arrival_time_ms;
113 }
114 } 128 }
115 129
116 double PacketReceiver::ObjectiveFunction() { 130 float PacketReceiver::GlobalPacketLoss() {
117 const double kDelta = 1.0; // Delay penalty factor. 131 return bwe_receiver_->GlobalReceiverPacketLossRatio();
118 double throughput_metric = log(static_cast<double>(total_throughput_));
119 double delay_penalty = kDelta * log(static_cast<double>(total_delay_ms_));
120 return throughput_metric - delay_penalty;
121 }
122
123 void PacketReceiver::PlotObjectiveFunction(int64_t arrival_time_ms) {
124 static const int kMetricPlotIntervalMs = 1000;
125 if (!plot_objective_function_) {
126 return;
127 }
128 if (arrival_time_ms - last_metric_plot_ms_ > kMetricPlotIntervalMs) {
129 BWE_TEST_LOGGING_PLOT(1, metric_log_prefix_, arrival_time_ms,
130 ObjectiveFunction());
131 last_metric_plot_ms_ = arrival_time_ms;
132 }
133 }
134
135 void PacketReceiver::PlotPacketLoss(int64_t arrival_time_ms) {
136 static const int kPacketLossPlotIntervalMs = 500;
137 if (!plot_packet_loss_) {
138 return;
139 }
140 if (arrival_time_ms - last_packet_loss_plot_ms_ > kPacketLossPlotIntervalMs) {
141 BWE_TEST_LOGGING_PLOT(2, packet_loss_log_prefix_, arrival_time_ms,
142 bwe_receiver_->RecentPacketLossRatio());
143 last_packet_loss_plot_ms_ = arrival_time_ms;
144 }
145 } 132 }
146 133
147 Stats<double> PacketReceiver::GetDelayStats() const { 134 Stats<double> PacketReceiver::GetDelayStats() const {
148 return delay_stats_; 135 return delay_stats_;
149 } 136 }
150 } // namespace bwe 137 } // namespace bwe
151 } // namespace testing 138 } // namespace testing
152 } // namespace webrtc 139 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698