video_stats.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef RTPBANDWIDTHSTATS_H
  2. #define RTPBANDWIDTHSTATS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "../congestion_control/common/cf_platform.h"
  7. #include "rtp.h"
  8. typedef struct _StreamBandwidthStats {
  9. struct timeval send_bw_start; /* used for bandwidth estimation */
  10. struct timeval recv_bw_start; /* used for bandwidth estimation */
  11. unsigned int sent_bytes; /* used for bandwidth estimation */
  12. unsigned int recv_bytes; /* used for bandwidth estimation */
  13. float upload_bw;
  14. float download_bw;
  15. float average_upload_bw;
  16. float average_download_bw;
  17. unsigned int seq_begin;/* used for loss rate estimation */
  18. unsigned int loss_begin;/* used for loss rate estimation */
  19. float last_loss_percent;
  20. } StreamBandwidthStats;
  21. typedef struct _ReceiverConfigStats
  22. {
  23. unsigned int remote_pt;
  24. unsigned long local_ip;
  25. int local_rtp_port;
  26. int rx_width;
  27. int rx_height;
  28. int bit_rate;
  29. }ReceiverConfigStats;
  30. typedef struct _SenderConfigStats
  31. {
  32. unsigned int local_pt;
  33. unsigned long remote_ip;
  34. int remote_rtp_port;
  35. int mtu;
  36. int tx_width;
  37. int tx_height;
  38. int capture_width;
  39. int capture_height;
  40. int fps_den;
  41. int fps_num;
  42. int bit_rate;
  43. }SenderConfigStats;
  44. typedef struct _ReceiverStats{
  45. //接收端开始时间统计
  46. int64_t start_ms_;
  47. int64_t stop_ms_;
  48. //接收端配置统计
  49. ReceiverConfigStats config_stats;
  50. //接收端接收时间统计
  51. int64_t first_frame_received_time_ms_;
  52. int64_t last_frame_received_time_ms_;
  53. int64_t received_packet_counts;
  54. //接收端解码时间统计
  55. int64_t first_decoded_frame_time_ms_ ;
  56. int64_t last_decoded_frame_time_ms_;
  57. int64_t last_decoded_key_frame_time_ms_;
  58. int64_t last_decode_duration_ms;
  59. int64_t decoded_frame_counts;
  60. //接收端render播放时间统计
  61. int64_t first_render_frame_time_ms_ ;
  62. int64_t last_render_frame_time_ms_;
  63. int64_t last_render_duration_ms;
  64. int64_t render_frame_counts;
  65. //发送端拥塞分配统计
  66. int last_report_cc_bitrate;//bps
  67. //接收端解码帧类型统计
  68. int key_frames_counts;
  69. int delta_frames_counts;
  70. }ReceiverStats;
  71. typedef struct _SenderStats{
  72. //发送端开始时间统计
  73. int64_t start_ms_;
  74. int64_t stop_ms_;
  75. //发送端配置统计
  76. SenderConfigStats config_stats;
  77. //发送端发送时间统计
  78. int64_t first_frame_sent_time_ms_;
  79. int64_t last_frame_sent_time_ms_;
  80. int64_t sent_packet_counts;
  81. //发送端编码时间统计
  82. int64_t first_encoded_frame_time_ms_ ;
  83. int64_t last_encoded_frame_time_ms_;
  84. int64_t last_encoded_key_frame_time_ms_;
  85. int64_t last_encode_duration_ms;
  86. int64_t encoded_frame_counts;
  87. //发送端拥塞分配统计
  88. int last_allocation_fps;
  89. int last_allocation_bitrate;//bps
  90. //发送端编码帧类型统计
  91. int key_frames_counts;
  92. int delta_frames_counts;
  93. //发送端主动丢帧统计
  94. int cap_drop_frames_counts;
  95. int framedropper_drop_frames_counts;
  96. }SenderStats;
  97. typedef struct _VideoStatsLogCallBack{
  98. // Callback function.
  99. int(*log_fn)(void *userdata, int level, const char* file, int line, const char* fmt, va_list vl);
  100. void *userdata;
  101. } VideoStatsLogCallBack;
  102. typedef struct _VideoStats {
  103. volatile int run; /*run线程标示 */
  104. su_thread thr; /*线程ID*/
  105. int64_t stat_ts;
  106. StreamBandwidthStats rtp_stats;
  107. StreamBandwidthStats rtcp_stats;
  108. SenderStats sender_stats;
  109. ReceiverStats receiver_stats;
  110. float last_loss_percent;
  111. VideoStatsLogCallBack log_callback;
  112. } VideoStats;
  113. void video_stats_init(VideoStatsLogCallBack *log_func);
  114. void video_stats_uninit();
  115. //接收相关统计
  116. ReceiverStats *video_stats_receiver_get_stats();
  117. void video_stats_receiver_on_started(int64_t start_ms, ReceiverConfigStats *config);
  118. void video_stats_receiver_on_stopped(int64_t stop_ms);
  119. void video_stats_receiver_on_incoming_packet(int64_t recv_time_ms);
  120. void video_stats_receiver_on_decoded_frame(int64_t decoded_time_ms, int64_t decode_duration_ms, int is_key);
  121. void video_stats_receiver_on_rendered_frame(int64_t render_time_ms, int64_t rende_duration_ms);
  122. void video_stats_receiver_on_report_cc_bitrate(int bitrate);
  123. //发送相关统计
  124. SenderStats *video_stats_sender_get_stats();
  125. void video_stats_sender_on_started(int64_t start_ms, SenderConfigStats *config);
  126. void video_stats_sender_on_stopped(int64_t stop_ms);
  127. void video_stats_sender_on_sent_packet(int64_t sent_time_ms);
  128. void video_stats_sender_on_encoded_frame(int64_t encoded_time_ms, int64_t encode_duration_ms, int is_key);
  129. void video_stats_sender_on_encoder_rate_changed(int allocation_fps, int allocation_bitrate);
  130. void video_stats_sender_on_frame_dropped(int cap_drop, int framedropper_drop);
  131. //带宽统计
  132. void video_stats_bandwidth_update_recv_rtp_bytes(size_t nbytes);
  133. void video_stats_bandwidth_update_recv_rtcp_bytes(size_t nbytes);
  134. void video_stats_bandwidth_update_send_rtp_bytes(int nbytes);
  135. void video_stats_bandwidth_update_send_rtcp_bytes(int nbytes);
  136. float video_stats_bandwidth_compute_loss_rate(rtcp_statistics *rtcp_stat);
  137. #ifdef __cplusplus
  138. }
  139. #endif /* end of __cplusplus */
  140. #endif