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

Side by Side Diff: webrtc/tools/network_tester/test_controller.cc

Issue 2894673004: increase bitrate precision of the network tester. (Closed)
Patch Set: Fix for bug in SendData. Created 3 years, 7 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
« no previous file with comments | « webrtc/tools/network_tester/packet_sender.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 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/tools/network_tester/test_controller.h" 11 #include "webrtc/tools/network_tester/test_controller.h"
12 12
13 namespace webrtc { 13 namespace webrtc {
14 14
15 TestController::TestController(int min_port, 15 TestController::TestController(int min_port,
16 int max_port, 16 int max_port,
17 const std::string& config_file_path, 17 const std::string& config_file_path,
18 const std::string& log_file_path) 18 const std::string& log_file_path)
19 : socket_factory_(rtc::ThreadManager::Instance()->WrapCurrentThread()), 19 : socket_factory_(rtc::ThreadManager::Instance()->WrapCurrentThread()),
20 config_file_path_(config_file_path), 20 config_file_path_(config_file_path),
21 packet_logger_(log_file_path), 21 packet_logger_(log_file_path),
22 local_test_done_(false), 22 local_test_done_(false),
23 remote_test_done_(false) { 23 remote_test_done_(false) {
24 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_); 24 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_);
25 packet_sender_checker_.Detach();
25 send_data_.fill(42); 26 send_data_.fill(42);
26 packet_sender_checker_.Detach();
27 auto socket = 27 auto socket =
28 std::unique_ptr<rtc::AsyncPacketSocket>(socket_factory_.CreateUdpSocket( 28 std::unique_ptr<rtc::AsyncPacketSocket>(socket_factory_.CreateUdpSocket(
29 rtc::SocketAddress(rtc::GetAnyIP(AF_INET), 0), min_port, max_port)); 29 rtc::SocketAddress(rtc::GetAnyIP(AF_INET), 0), min_port, max_port));
30 socket->SignalReadPacket.connect(this, &TestController::OnReadPacket); 30 socket->SignalReadPacket.connect(this, &TestController::OnReadPacket);
31 udp_transport_.reset( 31 udp_transport_.reset(
32 new cricket::UdpTransport("network tester transport", std::move(socket))); 32 new cricket::UdpTransport("network tester transport", std::move(socket)));
33 } 33 }
34 34
35 void TestController::SendConnectTo(const std::string& hostname, int port) { 35 void TestController::SendConnectTo(const std::string& hostname, int port) {
36 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_); 36 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_);
37 udp_transport_->SetRemoteAddress(rtc::SocketAddress(hostname, port)); 37 udp_transport_->SetRemoteAddress(rtc::SocketAddress(hostname, port));
38 NetworkTesterPacket packet; 38 NetworkTesterPacket packet;
39 packet.set_type(NetworkTesterPacket::HAND_SHAKING); 39 packet.set_type(NetworkTesterPacket::HAND_SHAKING);
40 SendData(packet, rtc::Optional<size_t>()); 40 SendData(packet, rtc::Optional<size_t>());
41 rtc::CritScope scoped_lock(&local_test_done_lock_); 41 rtc::CritScope scoped_lock(&local_test_done_lock_);
42 local_test_done_ = false; 42 local_test_done_ = false;
43 remote_test_done_ = false; 43 remote_test_done_ = false;
44 } 44 }
45 45
46 void TestController::Run() { 46 void TestController::Run() {
47 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_); 47 RTC_DCHECK_RUN_ON(&test_controller_thread_checker_);
48 rtc::Thread::Current()->ProcessMessages(0); 48 rtc::Thread::Current()->ProcessMessages(0);
49 } 49 }
50 50
51 void TestController::SendData(const NetworkTesterPacket& packet, 51 void TestController::SendData(const NetworkTesterPacket& packet,
52 rtc::Optional<size_t> data_size) { 52 rtc::Optional<size_t> data_size) {
53 // Can be call from packet_sender or from test_controller thread. 53 // Can be call from packet_sender or from test_controller thread.
54 size_t packet_size = packet.ByteSize(); 54 size_t packet_size = packet.ByteSize();
55 send_data_[0] = packet_size; 55 send_data_[0] = packet_size;
56 packet_size++;
56 packet.SerializeToArray(&send_data_[1], std::numeric_limits<char>::max()); 57 packet.SerializeToArray(&send_data_[1], std::numeric_limits<char>::max());
57 if (data_size && *data_size > packet_size) 58 if (data_size && *data_size > packet_size)
58 packet_size = *data_size; 59 packet_size = *data_size;
59 udp_transport_->SendPacket(send_data_.data(), packet_size + 1, 60 udp_transport_->SendPacket(send_data_.data(), packet_size,
60 rtc::PacketOptions(), 0); 61 rtc::PacketOptions(), 0);
61 } 62 }
62 63
63 void TestController::OnTestDone() { 64 void TestController::OnTestDone() {
64 RTC_DCHECK_CALLED_SEQUENTIALLY(&packet_sender_checker_); 65 RTC_DCHECK_CALLED_SEQUENTIALLY(&packet_sender_checker_);
65 NetworkTesterPacket packet; 66 NetworkTesterPacket packet;
66 packet.set_type(NetworkTesterPacket::TEST_DONE); 67 packet.set_type(NetworkTesterPacket::TEST_DONE);
67 SendData(packet, rtc::Optional<size_t>()); 68 SendData(packet, rtc::Optional<size_t>());
68 rtc::CritScope scoped_lock(&local_test_done_lock_); 69 rtc::CritScope scoped_lock(&local_test_done_lock_);
69 local_test_done_ = true; 70 local_test_done_ = true;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 116 }
116 case NetworkTesterPacket::TEST_DONE: { 117 case NetworkTesterPacket::TEST_DONE: {
117 remote_test_done_ = true; 118 remote_test_done_ = true;
118 break; 119 break;
119 } 120 }
120 default: { RTC_NOTREACHED(); } 121 default: { RTC_NOTREACHED(); }
121 } 122 }
122 } 123 }
123 124
124 } // namespace webrtc 125 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/tools/network_tester/packet_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698