OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_VIDEO_SEND_DELAY_STATS_H_ |
| 12 #define WEBRTC_VIDEO_SEND_DELAY_STATS_H_ |
| 13 |
| 14 #include <map> |
| 15 #include <memory> |
| 16 #include <set> |
| 17 |
| 18 #include "webrtc/base/criticalsection.h" |
| 19 #include "webrtc/base/thread_annotations.h" |
| 20 #include "webrtc/common_types.h" |
| 21 #include "webrtc/modules/include/module_common_types.h" |
| 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 #include "webrtc/video_send_stream.h" |
| 24 |
| 25 namespace webrtc { |
| 26 |
| 27 class SendDelayStats : public SendPacketObserver { |
| 28 public: |
| 29 explicit SendDelayStats(Clock* clock); |
| 30 virtual ~SendDelayStats(); |
| 31 |
| 32 // Adds the configured ssrcs for the rtp streams. |
| 33 // Stats will be calculated for these streams. |
| 34 void AddSsrcs(const VideoSendStream::Config& config); |
| 35 |
| 36 // Called when a packet is sent (leaving socket). |
| 37 bool OnSentPacket(int packet_id, int64_t time_ms); |
| 38 |
| 39 protected: |
| 40 // From SendPacketObserver. |
| 41 // Called when a packet is sent to the transport. |
| 42 void OnSendPacket(uint16_t packet_id, |
| 43 int64_t capture_time_ms, |
| 44 uint32_t ssrc) override; |
| 45 |
| 46 private: |
| 47 // Map holding sent packets (mapped by sequence number). |
| 48 struct SequenceNumberOlderThan { |
| 49 bool operator()(uint16_t seq1, uint16_t seq2) const { |
| 50 return IsNewerSequenceNumber(seq2, seq1); |
| 51 } |
| 52 }; |
| 53 struct Packet { |
| 54 Packet(uint32_t ssrc, int64_t capture_time_ms, int64_t send_time_ms) |
| 55 : ssrc(ssrc), |
| 56 capture_time_ms(capture_time_ms), |
| 57 send_time_ms(send_time_ms) {} |
| 58 uint32_t ssrc; |
| 59 int64_t capture_time_ms; |
| 60 int64_t send_time_ms; |
| 61 }; |
| 62 typedef std::map<uint16_t, Packet, SequenceNumberOlderThan> PacketMap; |
| 63 |
| 64 class SampleCounter { |
| 65 public: |
| 66 SampleCounter() : sum(0), num_samples(0) {} |
| 67 ~SampleCounter() {} |
| 68 void Add(int sample); |
| 69 int Avg(int min_required_samples) const; |
| 70 |
| 71 private: |
| 72 int sum; |
| 73 int num_samples; |
| 74 }; |
| 75 |
| 76 void UpdateHistograms(); |
| 77 void RemoveOld(int64_t now, PacketMap* packets) |
| 78 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 79 |
| 80 Clock* const clock_; |
| 81 rtc::CriticalSection crit_; |
| 82 |
| 83 PacketMap packets_ GUARDED_BY(crit_); |
| 84 size_t num_old_packets_ GUARDED_BY(crit_); |
| 85 size_t num_skipped_packets_ GUARDED_BY(crit_); |
| 86 |
| 87 std::set<uint32_t> ssrcs_ GUARDED_BY(crit_); |
| 88 std::map<uint32_t, SampleCounter> send_delay_counters_ |
| 89 GUARDED_BY(crit_); // Mapped by SSRC. |
| 90 }; |
| 91 |
| 92 } // namespace webrtc |
| 93 #endif // WEBRTC_VIDEO_SEND_DELAY_STATS_H_ |
OLD | NEW |