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

Unified Diff: remoting/test/counter_stubs.cc

Issue 1923573006: Implement a dummy host to do capturing and analysis only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android build break Created 4 years, 8 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: remoting/test/counter_stubs.cc
diff --git a/remoting/test/counter_stubs.cc b/remoting/test/counter_stubs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3731284fa9d71133b16ae754fc323870a00e3955
--- /dev/null
+++ b/remoting/test/counter_stubs.cc
@@ -0,0 +1,139 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/callback.h"
+#include "base/time/time.h"
+#include "remoting/proto/audio.pb.h"
+#include "remoting/proto/control.pb.h"
+#include "remoting/proto/video.pb.h"
+#include "remoting/protocol/fake_connection_to_client.h"
+#include "remoting/test/counter_stubs.h"
+
+namespace remoting {
+namespace test {
+
+#ifndef ARCH_CPU_64_BITS
+
+#include "base/synchronization/lock.h"
+
+using base::AutoLock;
+
+int64_t NoBarrierAtomicInt64::operator++() {
+ AutoLock l(lock_);
+ return i_++;
+}
+
+int64_t NoBarrierAtomicInt64::operator++(int) {
+ AutoLock l(lock_);
+ return ++i_;
+}
+
+int64_t NoBarrierAtomicInt64::operator--() {
+ AutoLock l(lock_);
+ return i_--;
+}
+
+int64_t NoBarrierAtomicInt64::operator--(int) {
+ AutoLock l(lock_);
+ return --i_;
+}
+
+int64_t NoBarrierAtomicInt64::operator+=(int64_t other) {
+ AutoLock l(lock_);
+ return (i_ += other);
+}
+
+int64_t NoBarrierAtomicInt64::operator-=(int64_t other) {
+ AutoLock l(lock_);
+ return (i_ -= other);
+}
+
+int64_t NoBarrierAtomicInt64::operator*() const {
+ AutoLock l(lock_);
+ return i_;
+}
+
+#endif
+
+MessageCounter::MessageCounter()
+ : count_(),
+ size_(),
+ last_size_(),
+ start_time_(base::Time::Now()) {}
+
+int MessageCounter::message_count() const {
+ return *count_;
+}
+
+int64_t MessageCounter::message_size() const {
+ return *size_;
+}
+
+int MessageCounter::last_message_size() const {
+ return last_size_;
+}
+
+double MessageCounter::DurationSeconds() const {
+ return (base::Time::Now() - start_time_).InSecondsF();
+}
+
+double MessageCounter::MessagesPerSecond() const {
+ return static_cast<double>(message_count()) / DurationSeconds();
+}
+double MessageCounter::SizePerSecond() const {
+ return static_cast<double>(message_size()) / DurationSeconds();
+}
+
+double MessageCounter::AverageMessageSize() const {
+ return static_cast<double>(message_size()) / message_count();
+}
+
+void MessageCounter::LogMessage(
+ const ::google::protobuf::MessageLite& message) {
+ count_++;
+ last_size_ = message.ByteSize();
+ size_ += message.ByteSize();
+}
+
+void CounterClientStub::DeliverHostMessage(
+ const protocol::ExtensionMessage& message) {
+ LogMessage(message);
+}
+
+void CounterHostStub::DeliverClientMessage(
+ const protocol::ExtensionMessage& message) {
+ LogMessage(message);
+}
+
+void CounterAudioStub::ProcessAudioPacket(
+ std::unique_ptr<AudioPacket> audio_packet,
+ const base::Closure& done) {
+ if (audio_packet) {
+ LogMessage(*audio_packet);
+ }
+ done.Run();
+}
+
+CounterVideoStub::CounterVideoStub(
+ protocol::FakeConnectionToClient* connection)
+ : connection_(connection) {}
+
+void CounterVideoStub::ProcessVideoPacket(
+ std::unique_ptr<VideoPacket> video_packet,
+ const base::Closure& done) {
+ if (video_packet && video_packet->has_capture_overhead_time_ms()) {
+ // Not a keepalive packet
+ if (connection_ &&
+ connection_->video_feedback_stub()) {
+ std::unique_ptr<VideoAck> ack(new VideoAck());
+ ack->set_frame_id(video_packet->frame_id());
+ connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack));
+ }
+ LogMessage(*video_packet);
+ }
+ done.Run();
+}
+
+} // namespace test
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698