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

Unified Diff: webrtc/tools/network_tester/config_reader.cc

Issue 2779233002: Add first part of the network_tester functionality. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/tools/network_tester/config_reader.cc
diff --git a/webrtc/tools/network_tester/config_reader.cc b/webrtc/tools/network_tester/config_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21603e819f567f2c770bf164e63cd226ebe238c9
--- /dev/null
+++ b/webrtc/tools/network_tester/config_reader.cc
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "webrtc/tools/network_tester/config_reader.h"
+
+#include <string>
+#include <vector>
+
+#include "webrtc/base/ignore_wundef.h"
+#include "webrtc/base/logging.h"
+
+#ifdef WEBRTC_NETWORK_TESTER_PROTO
+RTC_PUSH_IGNORING_WUNDEF()
+#include "webrtc/tools/network_tester/network_tester_config.pb.h"
+RTC_POP_IGNORING_WUNDEF()
+#endif // WEBRTC_NETWORK_TESTER_PROTO
+
+namespace webrtc {
+
+namespace {
+rtc::Optional<int> ParseMessageSize(std::istream& config_stream) {
+ int byte = config_stream.get();
+ if (config_stream.eof()) {
+ return rtc::Optional<int>();
+ }
+ RTC_DCHECK(0 <= byte && byte <= 255);
+ return rtc::Optional<int>(byte);
+}
+}
+
+ConfigReader::ConfigReader(const std::string& config_file_path)
+ : config_stream_(config_file_path,
+ std::ios_base::in | std::ios_base::binary) {
+ RTC_DCHECK(config_stream_.is_open());
+ RTC_DCHECK(config_stream_.good());
+}
+
+ConfigReader::~ConfigReader() = default;
+
+rtc::Optional<ConfigReader::Config> ConfigReader::GetNextConfig() {
+#ifdef WEBRTC_NETWORK_TESTER_PROTO
+ auto message_size = ParseMessageSize(config_stream_);
+ if (!message_size)
+ return rtc::Optional<Config>();
+ constexpr size_t kMaxEventSize = (1u << 16) - 1;
+ std::vector<char> message_buffer(kMaxEventSize);
+ config_stream_.read(message_buffer.data(), *message_size);
+ RTC_DCHECK_EQ(config_stream_.gcount(), *message_size);
+ webrtc::network_tester::config::NetworkTesterConfig proto_config;
+ if (!proto_config.ParseFromArray(message_buffer.data(), *message_size))
+ return rtc::Optional<Config>();
+ RTC_DCHECK(proto_config.has_packet_send_interval_ms());
+ RTC_DCHECK(proto_config.has_packet_size());
+ RTC_DCHECK(proto_config.has_execution_time_ms());
+ Config config;
+ config.packet_send_interval_ms = proto_config.packet_send_interval_ms();
+ config.packet_size = proto_config.packet_size();
+ config.execution_time_ms = proto_config.execution_time_ms();
+ return rtc::Optional<Config>(config);
+#else
+ return rtc::Optional<Config>();
+#endif // WEBRTC_NETWORK_TESTER_PROTO
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698