mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	[feat] add statistics module
This commit is contained in:
		
							
								
								
									
										70
									
								
								src/common/sequence_number_unwrapper.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								src/common/sequence_number_unwrapper.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| /* | ||||
|  * @Author: DI JUNKUN | ||||
|  * @Date: 2024-08-21 | ||||
|  * Copyright (c) 2024 by DI JUNKUN, All Rights Reserved. | ||||
|  */ | ||||
|  | ||||
| #ifndef _SEQUENCE_NUMBER_UNWRAPPER_H_ | ||||
| #define _SEQUENCE_NUMBER_UNWRAPPER_H_ | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| #include <limits> | ||||
| #include <type_traits> | ||||
|  | ||||
| // A sequence number unwrapper where the first unwrapped value equals the | ||||
| // first value being unwrapped. | ||||
| template <typename T, T M = 0> | ||||
| class SeqNumUnwrapper { | ||||
|   static_assert( | ||||
|       std::is_unsigned<T>::value && | ||||
|           std::numeric_limits<T>::max() < std::numeric_limits<int64_t>::max(), | ||||
|       "Type unwrapped must be an unsigned integer smaller than int64_t."); | ||||
|  | ||||
|  public: | ||||
|   // Unwraps `value` and updates the internal state of the unwrapper. | ||||
|   int64_t Unwrap(T value) { | ||||
|     if (!last_value_) { | ||||
|       last_unwrapped_ = {value}; | ||||
|     } else { | ||||
|       last_unwrapped_ += Delta(*last_value_, value); | ||||
|     } | ||||
|  | ||||
|     last_value_ = value; | ||||
|     return last_unwrapped_; | ||||
|   } | ||||
|  | ||||
|   // Returns the `value` without updating the internal state of the unwrapper. | ||||
|   int64_t PeekUnwrap(T value) const { | ||||
|     if (!last_value_) { | ||||
|       return value; | ||||
|     } | ||||
|     return last_unwrapped_ + Delta(*last_value_, value); | ||||
|   } | ||||
|  | ||||
|   // Resets the unwrapper to its initial state. Unwrapped sequence numbers will | ||||
|   // being at 0 after resetting. | ||||
|   void Reset() { | ||||
|     last_unwrapped_ = 0; | ||||
|     last_value_.reset(); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   static int64_t Delta(T last_value, T new_value) { | ||||
|     constexpr int64_t kBackwardAdjustment = | ||||
|         M == 0 ? int64_t{std::numeric_limits<T>::max()} + 1 : M; | ||||
|     int64_t result = ForwardDiff<T, M>(last_value, new_value); | ||||
|     if (!AheadOrAt<T, M>(new_value, last_value)) { | ||||
|       result -= kBackwardAdjustment; | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   int64_t last_unwrapped_ = 0; | ||||
|   std::unique_ptr<T> last_value_; | ||||
| }; | ||||
|  | ||||
| using RtpTimestampUnwrapper = SeqNumUnwrapper<uint32_t>; | ||||
| using RtpSeqNumUnwrapper = SeqNumUnwrapper<uint16_t>; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										7
									
								
								src/statistics/receiver_statistics.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/statistics/receiver_statistics.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #include "receiver_statistics.h" | ||||
|  | ||||
| #include "log.h" | ||||
|  | ||||
| ReceiverStatistics::ReceiverStatistics() {} | ||||
|  | ||||
| ReceiverStatistics::~ReceiverStatistics() {} | ||||
							
								
								
									
										21
									
								
								src/statistics/receiver_statistics.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/statistics/receiver_statistics.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| /* | ||||
|  * @Author: DI JUNKUN | ||||
|  * @Date: 2024-09-04 | ||||
|  * Copyright (c) 2024 by DI JUNKUN, All Rights Reserved. | ||||
|  */ | ||||
|  | ||||
| #ifndef _RECEIVER_STATISTICS_H_ | ||||
| #define _RECEIVER_STATISTICS_H_ | ||||
|  | ||||
| #include "statistics_base.h" | ||||
|  | ||||
| class ReceiverStatistics : public StatisticsBase { | ||||
|  public: | ||||
|   ReceiverStatistics(); | ||||
|   virtual ~ReceiverStatistics(); | ||||
|  | ||||
|  private: | ||||
|   /* data */ | ||||
| }; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										7
									
								
								src/statistics/sender_statistics.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/statistics/sender_statistics.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #include "sender_statistics.h" | ||||
|  | ||||
| #include "log.h" | ||||
|  | ||||
| SenderStatistics::SenderStatistics() {} | ||||
|  | ||||
| SenderStatistics::~SenderStatistics() {} | ||||
							
								
								
									
										21
									
								
								src/statistics/sender_statistics.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/statistics/sender_statistics.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| /* | ||||
|  * @Author: DI JUNKUN | ||||
|  * @Date: 2024-09-04 | ||||
|  * Copyright (c) 2024 by DI JUNKUN, All Rights Reserved. | ||||
|  */ | ||||
|  | ||||
| #ifndef _SENDER_STATISTICS_H_ | ||||
| #define _SENDER_STATISTICS_H_ | ||||
|  | ||||
| #include "statistics_base.h" | ||||
|  | ||||
| class SenderStatistics : public StatisticsBase { | ||||
|  public: | ||||
|   SenderStatistics(); | ||||
|   virtual ~SenderStatistics(); | ||||
|  | ||||
|  private: | ||||
|   /* data */ | ||||
| }; | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										5
									
								
								src/statistics/statistics_base.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/statistics/statistics_base.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| #include "statistics_base.h" | ||||
|  | ||||
| StatisticsBase::StatisticsBase() {} | ||||
|  | ||||
| StatisticsBase::~StatisticsBase() {} | ||||
							
								
								
									
										19
									
								
								src/statistics/statistics_base.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/statistics/statistics_base.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| /* | ||||
|  * @Author: DI JUNKUN | ||||
|  * @Date: 2024-09-04 | ||||
|  * Copyright (c) 2024 by DI JUNKUN, All Rights Reserved. | ||||
|  */ | ||||
|  | ||||
| #ifndef _STATISTICS_BASE_H_ | ||||
| #define _STATISTICS_BASE_H_ | ||||
|  | ||||
| class StatisticsBase { | ||||
|  public: | ||||
|   StatisticsBase(); | ||||
|   virtual ~StatisticsBase(); | ||||
|  | ||||
|  private: | ||||
|   /* data */ | ||||
| }; | ||||
|  | ||||
| #endif | ||||
| @@ -11,6 +11,7 @@ | ||||
|  | ||||
| #include "congestion_control.h" | ||||
| #include "ice_agent.h" | ||||
| #include "receiver_statistics.h" | ||||
| #include "ringbuffer.h" | ||||
| #include "rtp_audio_receiver.h" | ||||
| #include "rtp_audio_sender.h" | ||||
| @@ -20,6 +21,7 @@ | ||||
| #include "rtp_packet.h" | ||||
| #include "rtp_video_receiver.h" | ||||
| #include "rtp_video_sender.h" | ||||
| #include "sender_statistics.h" | ||||
| #include "ws_transmission.h" | ||||
|  | ||||
| class IceTransmission { | ||||
| @@ -150,6 +152,10 @@ class IceTransmission { | ||||
|   bool start_send_packet_ = false; | ||||
|  | ||||
|   uint32_t last_complete_frame_ts_ = 0; | ||||
|  | ||||
|  private: | ||||
|   std::unique_ptr<SenderStatistics> sender_statistics_ = nullptr; | ||||
|   std::unique_ptr<ReceiverStatistics> receiver_statistics_ = nullptr; | ||||
| }; | ||||
|  | ||||
| #endif | ||||
| @@ -170,9 +170,15 @@ target("qos") | ||||
|     add_files("src/qos/kcp/*.c") | ||||
|     add_includedirs("src/qos/kcp", {public = true}) | ||||
|  | ||||
| target("statistics") | ||||
|     set_kind("object") | ||||
|     add_deps("log") | ||||
|     add_files("src/statistics/*.cpp") | ||||
|     add_includedirs("src/statistics", {public = true}) | ||||
|  | ||||
| target("transmission") | ||||
|     set_kind("object") | ||||
|     add_deps("log", "ws", "ice", "qos", "rtp", "rtcp") | ||||
|     add_deps("log", "ws", "ice", "qos", "rtp", "rtcp", "statistics") | ||||
|     add_files("src/transmission/*.cpp") | ||||
|     add_includedirs("src/ws", "src/ice", "src/qos", {public = true}) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user