/* * Copyright (c) 2012 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.
*/
// Disallow copy constructor and copy assignment (no deep copies of `data_`).
NetworkPacket(const NetworkPacket&) = delete;
~NetworkPacket();
NetworkPacket& operator=(const NetworkPacket&) = delete; // Allow move constructor/assignment, so that we can use in stl containers.
NetworkPacket(NetworkPacket&&);
NetworkPacket& operator=(NetworkPacket&&);
private:
rtc::CopyOnWriteBuffer packet_; // The time the packet was sent out on the network.
int64_t send_time_; // The time the packet should arrive at the receiver.
int64_t arrival_time_; // If using a Transport for outgoing degradation, populate with // PacketOptions (transport-wide sequence number) for RTP.
std::optional<PacketOptions> packet_options_; bool is_rtcp_; // If using a PacketReceiver for incoming degradation, populate with // appropriate MediaType and packet time. This type/timing will be kept and // forwarded. The packet time might be altered to reflect time spent in fake // network pipe.
MediaType media_type_;
std::optional<int64_t> packet_time_us_;
std::optional<RtpPacketReceived> packet_received_;
Transport* transport_;
};
// Class faking a network link, internally is uses an implementation of a // SimulatedNetworkInterface to simulate network behavior. class FakeNetworkPipe : public SimulatedPacketReceiverInterface { public: // Will keep `network_behavior` alive while pipe is alive itself.
FakeNetworkPipe(Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior);
FakeNetworkPipe(Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
PacketReceiver* receiver);
FakeNetworkPipe(Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
PacketReceiver* receiver,
uint64_t seed);
// Must not be called in parallel with DeliverPacket or Process. void SetReceiver(PacketReceiver* receiver) override;
// Adds/subtracts references to Transport instances. If a Transport is // destroyed we cannot use to forward a potential delayed packet, these // methods are used to maintain a map of which instances are live. void AddActiveTransport(Transport* transport); void RemoveActiveTransport(Transport* transport);
// Methods for use with Transport interface. When/if packets are delivered, // they will be passed to the instance specified by the `transport` parameter. // Note that that instance must be in the map of active transports. bool SendRtp(rtc::ArrayView<const uint8_t> packet, const PacketOptions& options,
Transport* transport); bool SendRtcp(rtc::ArrayView<const uint8_t> packet, Transport* transport);
// Implements the PacketReceiver interface. When/if packets are delivered, // they will be passed directly to the receiver instance given in // SetReceiver(). The receive time will be increased by the amount of time the // packet spent in the fake network pipe. void DeliverRtpPacket(
MediaType media_type,
RtpPacketReceived packet,
OnUndemuxablePacketHandler undemuxable_packet_handler) override; void DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) override;
// Processes the network queues and trigger PacketReceiver::IncomingPacket for // packets ready to be delivered. void Process() override;
std::optional<int64_t> TimeUntilNextProcess() override;
// Get statistics. float PercentageLoss(); int AverageDelay() override;
size_t DroppedPackets();
size_t SentPackets(); void ResetStats();
// Returns true if enqueued, or false if packet was dropped. Use this method // when enqueueing packets that should be received by PacketReceiver instance. bool EnqueuePacket(rtc::CopyOnWriteBuffer packet,
std::optional<PacketOptions> options, bool is_rtcp,
MediaType media_type,
std::optional<int64_t> packet_time_us);
// Returns true if enqueued, or false if packet was dropped. Use this method // when enqueueing packets that should be received by Transport instance. bool EnqueuePacket(rtc::CopyOnWriteBuffer packet,
std::optional<PacketOptions> options, bool is_rtcp,
Transport* transport);
Clock* const clock_; // `config_lock` guards the mostly constant things like the callbacks. mutable Mutex config_lock_; const std::unique_ptr<NetworkBehaviorInterface> network_behavior_;
PacketReceiver* receiver_ RTC_GUARDED_BY(config_lock_);
// `process_lock` guards the data structures involved in delay and loss // processes, such as the packet queues.
Mutex process_lock_; // Packets are added at the back of the deque, this makes the deque ordered // by increasing send time. The common case when removing packets from the // deque is removing early packets, which will be close to the front of the // deque. This makes finding the packets in the deque efficient in the common // case.
std::deque<StoredPacket> packets_in_flight_ RTC_GUARDED_BY(process_lock_);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.