diff --git a/call/fake_network_pipe.cc b/call/fake_network_pipe.cc index 7fc935df42..492eae2eb5 100644 --- a/call/fake_network_pipe.cc +++ b/call/fake_network_pipe.cc @@ -416,4 +416,52 @@ bool FakeNetworkPipe::HasDemuxer() const { return demuxer_ != nullptr; } +void FakeNetworkPipe::DeliverPacketWithLock(NetworkPacket* packet) { + rtc::CritScope crit(&config_lock_); + DeliverPacket(packet); +} + +void FakeNetworkPipe::ResetStats() { + rtc::CritScope crit(&process_lock_); + dropped_packets_ = 0; + sent_packets_ = 0; + total_packet_delay_ = 0; +} + +int FakeNetworkPipe::GetConfigCapacityKbps() const { + rtc::CritScope crit(&config_lock_); + return config_.link_capacity_kbps; +} + +void FakeNetworkPipe::AddToPacketDropCount() { + rtc::CritScope crit(&process_lock_); + ++dropped_packets_; +} + +void FakeNetworkPipe::AddToPacketSentCount(int count) { + rtc::CritScope crit(&process_lock_); + sent_packets_ += count; +} + +void FakeNetworkPipe::AddToTotalDelay(int delay_ms) { + rtc::CritScope crit(&process_lock_); + total_packet_delay_ += delay_ms; +} + +int64_t FakeNetworkPipe::GetTimeInMilliseconds() const { + return clock_->TimeInMilliseconds(); +} + +bool FakeNetworkPipe::IsRandomLoss(double prob_loss) { + return random_.Rand() < prob_loss; +} + +bool FakeNetworkPipe::ShouldProcess(int64_t time_now) const { + return time_now >= next_process_time_; +} + +void FakeNetworkPipe::SetTimeToNextProcess(int64_t skip_ms) { + next_process_time_ += skip_ms; +} + } // namespace webrtc diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h index b4cf70b760..bd3a79c8d7 100644 --- a/call/fake_network_pipe.h +++ b/call/fake_network_pipe.h @@ -42,8 +42,9 @@ class NetworkPacket { bool is_rtcp, MediaType media_type_, rtc::Optional packet_time_); - // Disallow copy constructor (no deep copies of |data_|). + // Disallow copy constructor and copy assignment (no deep copies of |data_|). NetworkPacket(const NetworkPacket&) = delete; + NetworkPacket& operator=(const NetworkPacket&) = delete; // Allow move constructor/assignment, so that we can use in stl containers. NetworkPacket(NetworkPacket&&); NetworkPacket& operator=(NetworkPacket&&); @@ -90,7 +91,7 @@ class Demuxer { }; // This class doesn't have any internal thread safety, so caller must make sure -// SetReceiver and and DeliverPacket aren't called in a racy manner. +// SetReceiver and DeliverPacket aren't called in a racy manner. class DemuxerImpl final : public Demuxer { public: explicit DemuxerImpl(const std::map& payload_type_map); @@ -154,7 +155,7 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { // Sends a new packet to the link. When/if packets are delivered, they will // be passed to the receiver instance given in SetReceiver(). This method // should only be used if a Demuxer was provided in the constructor. - virtual void SendPacket(const uint8_t* packet, size_t packet_length); + void SendPacket(const uint8_t* packet, size_t packet_length); // Must not be called in parallel with SendPacket or Process. void SetReceiver(PacketReceiver* receiver); @@ -188,10 +189,22 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { int AverageDelay(); size_t DroppedPackets(); size_t SentPackets(); + void ResetStats(); + + protected: + void DeliverPacketWithLock(NetworkPacket* packet); + int GetConfigCapacityKbps() const; + void AddToPacketDropCount(); + void AddToPacketSentCount(int count); + void AddToTotalDelay(int delay_ms); + int64_t GetTimeInMilliseconds() const; + bool IsRandomLoss(double prob_loss); + bool ShouldProcess(int64_t time_now) const; + void SetTimeToNextProcess(int64_t skip_ms); private: // Returns true if enqueued, or false if packet was dropped. - bool EnqueuePacket(rtc::CopyOnWriteBuffer packet, + virtual bool EnqueuePacket(rtc::CopyOnWriteBuffer packet, rtc::Optional options, bool is_rtcp, MediaType media_type,