| 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 VIDEO_SEND_DELAY_STATS_H_ |
| 12 | #define VIDEO_SEND_DELAY_STATS_H_ |
| 13 |
| 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 |
| 17 | #include <map> |
| 18 |
| 19 | #include "api/units/timestamp.h" |
| 20 | #include "call/video_send_stream.h" |
| 21 | #include "modules/include/module_common_types_public.h" |
| 22 | #include "rtc_base/synchronization/mutex.h" |
| 23 | #include "rtc_base/thread_annotations.h" |
| 24 | #include "system_wrappers/include/clock.h" |
| 25 | #include "video/stats_counter.h" |
| 26 |
| 27 | namespace webrtc { |
| 28 |
| 29 | // Used to collect delay stats for video streams. The class gets callbacks |
| 30 | // from more than one threads and internally uses a mutex for data access |
| 31 | // synchronization. |
| 32 | // TODO(bugs.webrtc.org/11993): OnSendPacket and OnSentPacket will eventually |
| 33 | // be called consistently on the same thread. Once we're there, we should be |
| 34 | // able to avoid locking (at least for the fast path). |
| 35 | class SendDelayStats { |
| 36 | public: |
| 37 | explicit SendDelayStats(Clock* clock); |
| 38 | ~SendDelayStats(); |
| 39 |
| 40 | // Adds the configured ssrcs for the rtp streams. |
| 41 | // Stats will be calculated for these streams. |
| 42 | void AddSsrcs(const VideoSendStream::Config& config); |
| 43 |
| 44 | // Called when a packet is sent (leaving socket). |
| 45 | bool OnSentPacket(int packet_id, Timestamp time); |
| 46 |
| 47 | // Called when a packet is sent to the transport. |
| 48 | void OnSendPacket(uint16_t packet_id, Timestamp capture_time, uint32_t ssrc); |
| 49 |
| 50 | private: |
| 51 | // Map holding sent packets (mapped by sequence number). |
| 52 | struct SequenceNumberOlderThan { |
| 53 | bool operator()(uint16_t seq1, uint16_t seq2) const { |
| 54 | return IsNewerSequenceNumber(seq2, seq1); |
| 55 | } |
| 56 | }; |
| 57 | struct Packet { |
| 58 | AvgCounter* send_delay; |
| 59 | Timestamp capture_time; |
| 60 | Timestamp send_time; |
| 61 | }; |
| 62 |
| 63 | void UpdateHistograms(); |
| 64 | void RemoveOld(Timestamp now) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 65 |
| 66 | Clock* const clock_; |
| 67 | Mutex mutex_; |
| 68 |
| 69 | std::map<uint16_t, Packet, SequenceNumberOlderThan> packets_ |
| 70 | RTC_GUARDED_BY(mutex_); |
| 71 | size_t num_old_packets_ RTC_GUARDED_BY(mutex_); |
| 72 | size_t num_skipped_packets_ RTC_GUARDED_BY(mutex_); |
| 73 |
| 74 | // Mapped by SSRC. |
| 75 | std::map<uint32_t, AvgCounter> send_delay_counters_ RTC_GUARDED_BY(mutex_); |
| 76 | }; |
| 77 |
| 78 | } // namespace webrtc |
| 79 | #endif // VIDEO_SEND_DELAY_STATS_H_ |
| 80 |