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

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: Comments addressed 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,
32 bool plot_bwe) 31 bool plot_bwe)
33 : PacketProcessor(listener, flow_id, kReceiver), 32 : PacketProcessor(listener, flow_id, kReceiver),
34 delay_log_prefix_(), 33 delay_log_prefix_(),
35 metric_log_prefix_(), 34 metric_log_prefix_(),
36 packet_loss_log_prefix_(), 35 packet_loss_log_prefix_(),
37 last_delay_plot_ms_(0), 36 available_capacity_log_prefix_(),
38 last_metric_plot_ms_(0), 37 throughput_log_prefix_(),
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)), 38 bwe_receiver_(CreateBweReceiver(bwe_type, flow_id, plot_bwe)),
46 total_delay_ms_(0), 39 metric_recorder_(NULL) {
47 total_throughput_(0),
48 number_packets_(0) {
49 // Setup the prefix ststd::rings used when logging. 40 // Setup the prefix ststd::rings used when logging.
50 std::stringstream ss1; 41 std::stringstream ss1;
51 ss1 << "Delay_" << flow_id << "#2"; 42 ss1 << "Delay_ms_" << flow_id << "#2";
52 delay_log_prefix_ = ss1.str(); 43 delay_log_prefix_ = ss1.str();
53 44
54 std::stringstream ss2; 45 std::stringstream ss2;
55 ss2 << "Objective_function_" << flow_id << "#2"; 46 ss2 << "Objective_function_" << flow_id << "#2";
56 metric_log_prefix_ = ss2.str(); 47 metric_log_prefix_ = ss2.str();
57 48
58 std::stringstream ss3; 49 std::stringstream ss3;
59 ss3 << "Packet_Loss_" << flow_id << "#2"; 50 ss3 << "Packet_Loss_" << flow_id << "#2";
60 packet_loss_log_prefix_ = ss3.str(); 51 packet_loss_log_prefix_ = ss3.str();
52
53 // Plot Available capacity together with throughputs.
54 std::stringstream ss4;
55 ss4 << "Throughput_kbps" << flow_id << "#1";
56 available_capacity_log_prefix_ = ss4.str();
57
58 std::stringstream ss5;
59 ss5 << "Throughput_kbps_" << flow_id << "#2";
60 throughput_log_prefix_ = ss5.str();
61 }
62
63 PacketReceiver::PacketReceiver(PacketProcessorListener* listener,
64 int flow_id,
65 BandwidthEstimatorType bwe_type,
66 bool plot_delay,
67 bool plot_bwe,
68 MetricRecorder* metric_recorder)
69 : PacketReceiver(listener, flow_id, bwe_type, plot_delay, plot_bwe) {
70 metric_recorder_ = metric_recorder;
stefan-webrtc 2015/07/02 11:03:42 Set this in the initializer list.
magalhaesc 2015/07/02 17:06:19 Done.
61 } 71 }
62 72
63 PacketReceiver::~PacketReceiver() { 73 PacketReceiver::~PacketReceiver() {
64 } 74 }
65 75
66 void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) { 76 void PacketReceiver::RunFor(int64_t time_ms, Packets* in_out) {
67 Packets feedback; 77 Packets feedback;
68 for (auto it = in_out->begin(); it != in_out->end();) { 78 for (auto it = in_out->begin(); it != in_out->end();) {
69 // PacketReceivers are only associated with a single stream, and therefore 79 // PacketReceivers are only associated with a single stream, and therefore
70 // should only process a single flow id. 80 // should only process a single flow id.
71 // TODO(holmer): Break this out into a Demuxer which implements both 81 // TODO(holmer): Break this out into a Demuxer which implements both
72 // PacketProcessorListener and PacketProcessor. 82 // PacketProcessorListener and PacketProcessor.
73 BWE_TEST_LOGGING_CONTEXT("Receiver"); 83 BWE_TEST_LOGGING_CONTEXT("Receiver");
74 if ((*it)->GetPacketType() == Packet::kMedia && 84 if ((*it)->GetPacketType() == Packet::kMedia &&
75 (*it)->flow_id() == *flow_ids().begin()) { 85 (*it)->flow_id() == *flow_ids().begin()) {
76 BWE_TEST_LOGGING_CONTEXT(*flow_ids().begin()); 86 BWE_TEST_LOGGING_CONTEXT(*flow_ids().begin());
77 const MediaPacket* media_packet = static_cast<const MediaPacket*>(*it); 87 const MediaPacket* media_packet = static_cast<const MediaPacket*>(*it);
78 // We're treating the send time (from previous filter) as the arrival 88 // We're treating the send time (from previous filter) as the arrival
79 // time once packet reaches the estimator. 89 // time once packet reaches the estimator.
80 int64_t arrival_time_ms = (media_packet->send_time_us() + 500) / 1000; 90 int64_t arrival_time_ms = (media_packet->send_time_us() + 500) / 1000;
81 int64_t send_time_ms = (media_packet->creation_time_us() + 500) / 1000; 91 int64_t send_time_ms = (media_packet->creation_time_us() + 500) / 1000;
82 delay_stats_.Push(arrival_time_ms - send_time_ms); 92 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 93
87 total_delay_ms_ += arrival_time_ms - send_time_ms; 94 if (metric_recorder_ != NULL) {
stefan-webrtc 2015/07/02 11:03:41 nullptr
magalhaesc 2015/07/02 17:06:19 Done.
88 total_throughput_ += media_packet->payload_size(); 95 PlotDelay(arrival_time_ms, send_time_ms);
89 ++number_packets_; 96 PlotThroughput(arrival_time_ms);
97 PlotTotalAvailableCapacity(arrival_time_ms);
98 PlotAvailableCapacityPerFlow(arrival_time_ms);
99 PlotObjectiveFunction(arrival_time_ms);
100 PlotPacketLoss(arrival_time_ms);
stefan-webrtc 2015/07/02 11:03:42 Just replace these with a single function called P
magalhaesc 2015/07/02 17:06:19 Done.
101
102 metric_recorder_->PushDelayMs(arrival_time_ms - send_time_ms,
103 arrival_time_ms);
104 metric_recorder_->PushThroughputBytes(media_packet->payload_size(),
105 arrival_time_ms);
stefan-webrtc 2015/07/02 11:03:42 Should we plot prior to adding new data? Maybe swi
magalhaesc 2015/07/02 17:06:19 The plots above are dynamics while the added date
106 metric_recorder_->Update(arrival_time_ms);
107 }
90 108
91 bwe_receiver_->ReceivePacket(arrival_time_ms, *media_packet); 109 bwe_receiver_->ReceivePacket(arrival_time_ms, *media_packet);
92 FeedbackPacket* fb = bwe_receiver_->GetFeedback(arrival_time_ms); 110 FeedbackPacket* fb = bwe_receiver_->GetFeedback(arrival_time_ms);
93 if (fb) 111 if (fb)
94 feedback.push_back(fb); 112 feedback.push_back(fb);
95 delete media_packet; 113 delete media_packet;
96 it = in_out->erase(it); 114 it = in_out->erase(it);
97 } else { 115 } else {
98 ++it; 116 ++it;
99 } 117 }
100 } 118 }
101 // Insert feedback packets to be sent back to the sender. 119 // Insert feedback packets to be sent back to the sender.
102 in_out->merge(feedback, DereferencingComparator<Packet>); 120 in_out->merge(feedback, DereferencingComparator<Packet>);
103 } 121 }
104 122
105 void PacketReceiver::PlotDelay(int64_t arrival_time_ms, int64_t send_time_ms) { 123 void PacketReceiver::PlotDelay(int64_t arrival_time_ms, int64_t send_time_ms) {
106 static const int kDelayPlotIntervalMs = 100; 124 metric_recorder_->PlotDelay(delay_log_prefix_, arrival_time_ms,
107 if (!plot_delay_) 125 arrival_time_ms - send_time_ms);
108 return;
109 if (arrival_time_ms - last_delay_plot_ms_ > kDelayPlotIntervalMs) {
110 BWE_TEST_LOGGING_PLOT(0, delay_log_prefix_, arrival_time_ms,
111 arrival_time_ms - send_time_ms);
112 last_delay_plot_ms_ = arrival_time_ms;
113 }
114 } 126 }
115 127
116 double PacketReceiver::ObjectiveFunction() { 128 void PacketReceiver::PlotThroughput(int64_t arrival_time_ms) {
117 const double kDelta = 1.0; // Delay penalty factor. 129 metric_recorder_->PlotThroughput(throughput_log_prefix_, arrival_time_ms,
118 double throughput_metric = log(static_cast<double>(total_throughput_)); 130 bwe_receiver_->RecentKbps());
119 double delay_penalty = kDelta * log(static_cast<double>(total_delay_ms_)); 131 }
120 return throughput_metric - delay_penalty; 132
133 void PacketReceiver::PlotTotalAvailableCapacity(int64_t arrival_time_ms) {
134 metric_recorder_->PlotTotalAvailableCapacity(available_capacity_log_prefix_,
135 arrival_time_ms);
136 }
137
138 void PacketReceiver::PlotAvailableCapacityPerFlow(int64_t arrival_time_ms) {
139 metric_recorder_->PlotAvailableCapacityPerFlow(available_capacity_log_prefix_,
140 arrival_time_ms);
121 } 141 }
122 142
123 void PacketReceiver::PlotObjectiveFunction(int64_t arrival_time_ms) { 143 void PacketReceiver::PlotObjectiveFunction(int64_t arrival_time_ms) {
124 static const int kMetricPlotIntervalMs = 1000; 144 metric_recorder_->PlotObjective(metric_log_prefix_, arrival_time_ms);
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 } 145 }
134 146
135 void PacketReceiver::PlotPacketLoss(int64_t arrival_time_ms) { 147 void PacketReceiver::PlotPacketLoss(int64_t arrival_time_ms) {
136 static const int kPacketLossPlotIntervalMs = 500; 148 metric_recorder_->PlotLoss("Recent_" + packet_loss_log_prefix_,
137 if (!plot_packet_loss_) { 149 arrival_time_ms,
138 return; 150 bwe_receiver_->RecentPacketLossRatio());
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 } 151 }
146 152
147 Stats<double> PacketReceiver::GetDelayStats() const { 153 Stats<double> PacketReceiver::GetDelayStats() const {
148 return delay_stats_; 154 return delay_stats_;
149 } 155 }
150 } // namespace bwe 156 } // namespace bwe
151 } // namespace testing 157 } // namespace testing
152 } // namespace webrtc 158 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698