asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_SEND_DELAY_STATS_H_ |
| 12 | #define VIDEO_SEND_DELAY_STATS_H_ |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 16 | |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 17 | #include <map> |
| 18 | #include <memory> |
| 19 | #include <set> |
| 20 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 21 | #include "call/video_send_stream.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "modules/include/module_common_types_public.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "rtc_base/critical_section.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "rtc_base/thread_annotations.h" |
| 25 | #include "system_wrappers/include/clock.h" |
| 26 | #include "video/stats_counter.h" |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
| 30 | class SendDelayStats : public SendPacketObserver { |
| 31 | public: |
| 32 | explicit SendDelayStats(Clock* clock); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 33 | ~SendDelayStats() override; |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 34 | |
| 35 | // Adds the configured ssrcs for the rtp streams. |
| 36 | // Stats will be calculated for these streams. |
| 37 | void AddSsrcs(const VideoSendStream::Config& config); |
| 38 | |
| 39 | // Called when a packet is sent (leaving socket). |
| 40 | bool OnSentPacket(int packet_id, int64_t time_ms); |
| 41 | |
| 42 | protected: |
| 43 | // From SendPacketObserver. |
| 44 | // Called when a packet is sent to the transport. |
| 45 | void OnSendPacket(uint16_t packet_id, |
| 46 | int64_t capture_time_ms, |
| 47 | uint32_t ssrc) override; |
| 48 | |
| 49 | private: |
| 50 | // Map holding sent packets (mapped by sequence number). |
| 51 | struct SequenceNumberOlderThan { |
| 52 | bool operator()(uint16_t seq1, uint16_t seq2) const { |
| 53 | return IsNewerSequenceNumber(seq2, seq1); |
| 54 | } |
| 55 | }; |
| 56 | struct Packet { |
| 57 | Packet(uint32_t ssrc, int64_t capture_time_ms, int64_t send_time_ms) |
| 58 | : ssrc(ssrc), |
| 59 | capture_time_ms(capture_time_ms), |
| 60 | send_time_ms(send_time_ms) {} |
| 61 | uint32_t ssrc; |
| 62 | int64_t capture_time_ms; |
| 63 | int64_t send_time_ms; |
| 64 | }; |
| 65 | typedef std::map<uint16_t, Packet, SequenceNumberOlderThan> PacketMap; |
| 66 | |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 67 | void UpdateHistograms(); |
| 68 | void RemoveOld(int64_t now, PacketMap* packets) |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 69 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
asapersson | 40f5400 | 2016-06-09 00:09:22 -0700 | [diff] [blame] | 70 | AvgCounter* GetSendDelayCounter(uint32_t ssrc) |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 71 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 72 | |
| 73 | Clock* const clock_; |
| 74 | rtc::CriticalSection crit_; |
| 75 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 76 | PacketMap packets_ RTC_GUARDED_BY(crit_); |
| 77 | size_t num_old_packets_ RTC_GUARDED_BY(crit_); |
| 78 | size_t num_skipped_packets_ RTC_GUARDED_BY(crit_); |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 79 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 80 | std::set<uint32_t> ssrcs_ RTC_GUARDED_BY(crit_); |
asapersson | 40f5400 | 2016-06-09 00:09:22 -0700 | [diff] [blame] | 81 | |
| 82 | // Mapped by SSRC. |
| 83 | std::map<uint32_t, std::unique_ptr<AvgCounter>> send_delay_counters_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 84 | RTC_GUARDED_BY(crit_); |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 88 | #endif // VIDEO_SEND_DELAY_STATS_H_ |