OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/callback.h" |
| 6 #include "base/time/time.h" |
| 7 #include "remoting/proto/audio.pb.h" |
| 8 #include "remoting/proto/control.pb.h" |
| 9 #include "remoting/proto/video.pb.h" |
| 10 #include "remoting/protocol/fake_connection_to_client.h" |
| 11 #include "remoting/test/counter_stubs.h" |
| 12 |
| 13 namespace remoting { |
| 14 namespace test { |
| 15 |
| 16 #ifndef ARCH_CPU_64_BITS |
| 17 |
| 18 #include "base/synchronization/lock.h" |
| 19 |
| 20 using base::AutoLock; |
| 21 |
| 22 int64_t NoBarrierAtomicInt64::operator++() { |
| 23 AutoLock l(lock_); |
| 24 return i_++; |
| 25 } |
| 26 |
| 27 int64_t NoBarrierAtomicInt64::operator++(int) { |
| 28 AutoLock l(lock_); |
| 29 return ++i_; |
| 30 } |
| 31 |
| 32 int64_t NoBarrierAtomicInt64::operator--() { |
| 33 AutoLock l(lock_); |
| 34 return i_--; |
| 35 } |
| 36 |
| 37 int64_t NoBarrierAtomicInt64::operator--(int) { |
| 38 AutoLock l(lock_); |
| 39 return --i_; |
| 40 } |
| 41 |
| 42 int64_t NoBarrierAtomicInt64::operator+=(int64_t other) { |
| 43 AutoLock l(lock_); |
| 44 return (i_ += other); |
| 45 } |
| 46 |
| 47 int64_t NoBarrierAtomicInt64::operator-=(int64_t other) { |
| 48 AutoLock l(lock_); |
| 49 return (i_ -= other); |
| 50 } |
| 51 |
| 52 int64_t NoBarrierAtomicInt64::operator*() const { |
| 53 AutoLock l(lock_); |
| 54 return i_; |
| 55 } |
| 56 |
| 57 #endif |
| 58 |
| 59 MessageCounter::MessageCounter() |
| 60 : count_(), |
| 61 size_(), |
| 62 last_size_(), |
| 63 start_time_(base::Time::Now()) {} |
| 64 |
| 65 int MessageCounter::message_count() const { |
| 66 return *count_; |
| 67 } |
| 68 |
| 69 int64_t MessageCounter::message_size() const { |
| 70 return *size_; |
| 71 } |
| 72 |
| 73 int MessageCounter::last_message_size() const { |
| 74 return last_size_; |
| 75 } |
| 76 |
| 77 double MessageCounter::DurationSeconds() const { |
| 78 return (base::Time::Now() - start_time_).InSecondsF(); |
| 79 } |
| 80 |
| 81 double MessageCounter::MessagesPerSecond() const { |
| 82 return static_cast<double>(message_count()) / DurationSeconds(); |
| 83 } |
| 84 double MessageCounter::SizePerSecond() const { |
| 85 return static_cast<double>(message_size()) / DurationSeconds(); |
| 86 } |
| 87 |
| 88 double MessageCounter::AverageMessageSize() const { |
| 89 return static_cast<double>(message_size()) / message_count(); |
| 90 } |
| 91 |
| 92 void MessageCounter::LogMessage( |
| 93 const ::google::protobuf::MessageLite& message) { |
| 94 count_++; |
| 95 last_size_ = message.ByteSize(); |
| 96 size_ += message.ByteSize(); |
| 97 } |
| 98 |
| 99 void CounterClientStub::DeliverHostMessage( |
| 100 const protocol::ExtensionMessage& message) { |
| 101 LogMessage(message); |
| 102 } |
| 103 |
| 104 void CounterHostStub::DeliverClientMessage( |
| 105 const protocol::ExtensionMessage& message) { |
| 106 LogMessage(message); |
| 107 } |
| 108 |
| 109 void CounterAudioStub::ProcessAudioPacket( |
| 110 std::unique_ptr<AudioPacket> audio_packet, |
| 111 const base::Closure& done) { |
| 112 if (audio_packet) { |
| 113 LogMessage(*audio_packet); |
| 114 } |
| 115 done.Run(); |
| 116 } |
| 117 |
| 118 CounterVideoStub::CounterVideoStub( |
| 119 protocol::FakeConnectionToClient* connection) |
| 120 : connection_(connection) {} |
| 121 |
| 122 void CounterVideoStub::ProcessVideoPacket( |
| 123 std::unique_ptr<VideoPacket> video_packet, |
| 124 const base::Closure& done) { |
| 125 if (video_packet && video_packet->has_capture_overhead_time_ms()) { |
| 126 // Not a keepalive packet |
| 127 if (connection_ && |
| 128 connection_->video_feedback_stub()) { |
| 129 std::unique_ptr<VideoAck> ack(new VideoAck()); |
| 130 ack->set_frame_id(video_packet->frame_id()); |
| 131 connection_->video_feedback_stub()->ProcessVideoAck(std::move(ack)); |
| 132 } |
| 133 LogMessage(*video_packet); |
| 134 } |
| 135 done.Run(); |
| 136 } |
| 137 |
| 138 } // namespace test |
| 139 } // namespace remoting |
OLD | NEW |