| 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
|
|
|