123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #ifndef RTPBANDWIDTHSTATS_H
- #define RTPBANDWIDTHSTATS_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "../congestion_control/common/cf_platform.h"
- #include "rtp.h"
- typedef struct _StreamBandwidthStats {
- struct timeval send_bw_start; /* used for bandwidth estimation */
- struct timeval recv_bw_start; /* used for bandwidth estimation */
- unsigned int sent_bytes; /* used for bandwidth estimation */
- unsigned int recv_bytes; /* used for bandwidth estimation */
- float upload_bw;
- float download_bw;
- float average_upload_bw;
- float average_download_bw;
- unsigned int seq_begin;/* used for loss rate estimation */
- unsigned int loss_begin;/* used for loss rate estimation */
- float last_loss_percent;
- } StreamBandwidthStats;
- typedef struct _ReceiverConfigStats
- {
- unsigned int remote_pt;
- unsigned long local_ip;
- int local_rtp_port;
- int rx_width;
- int rx_height;
- int bit_rate;
- }ReceiverConfigStats;
- typedef struct _SenderConfigStats
- {
- unsigned int local_pt;
- unsigned long remote_ip;
- int remote_rtp_port;
- int mtu;
- int tx_width;
- int tx_height;
- int capture_width;
- int capture_height;
- int fps_den;
- int fps_num;
- int bit_rate;
- }SenderConfigStats;
- typedef struct _ReceiverStats{
- //接收端开始时间统计
- int64_t start_ms_;
- int64_t stop_ms_;
- //接收端配置统计
- ReceiverConfigStats config_stats;
- //接收端接收时间统计
- int64_t first_frame_received_time_ms_;
- int64_t last_frame_received_time_ms_;
- int64_t received_packet_counts;
-
- //接收端解码时间统计
- int64_t first_decoded_frame_time_ms_ ;
- int64_t last_decoded_frame_time_ms_;
- int64_t last_decoded_key_frame_time_ms_;
- int64_t last_decode_duration_ms;
- int64_t decoded_frame_counts;
- //接收端render播放时间统计
- int64_t first_render_frame_time_ms_ ;
- int64_t last_render_frame_time_ms_;
- int64_t last_render_duration_ms;
- int64_t render_frame_counts;
-
- //发送端拥塞分配统计
- int last_report_cc_bitrate;//bps
- //接收端解码帧类型统计
- int key_frames_counts;
- int delta_frames_counts;
- }ReceiverStats;
- typedef struct _SenderStats{
- //发送端开始时间统计
- int64_t start_ms_;
- int64_t stop_ms_;
-
- //发送端配置统计
- SenderConfigStats config_stats;
- //发送端发送时间统计
- int64_t first_frame_sent_time_ms_;
- int64_t last_frame_sent_time_ms_;
- int64_t sent_packet_counts;
-
- //发送端编码时间统计
- int64_t first_encoded_frame_time_ms_ ;
- int64_t last_encoded_frame_time_ms_;
- int64_t last_encoded_key_frame_time_ms_;
- int64_t last_encode_duration_ms;
- int64_t encoded_frame_counts;
-
- //发送端拥塞分配统计
- int last_allocation_fps;
- int last_allocation_bitrate;//bps
-
- //发送端编码帧类型统计
- int key_frames_counts;
- int delta_frames_counts;
-
- //发送端主动丢帧统计
- int cap_drop_frames_counts;
- int framedropper_drop_frames_counts;
- }SenderStats;
- typedef struct _VideoStatsLogCallBack{
- // Callback function.
- int(*log_fn)(void *userdata, int level, const char* file, int line, const char* fmt, va_list vl);
- void *userdata;
- } VideoStatsLogCallBack;
- typedef struct _VideoStats {
- volatile int run; /*run线程标示 */
- su_thread thr; /*线程ID*/
- int64_t stat_ts;
-
- StreamBandwidthStats rtp_stats;
- StreamBandwidthStats rtcp_stats;
- SenderStats sender_stats;
- ReceiverStats receiver_stats;
- float last_loss_percent;
- VideoStatsLogCallBack log_callback;
- } VideoStats;
- void video_stats_init(VideoStatsLogCallBack *log_func);
- void video_stats_uninit();
- //接收相关统计
- ReceiverStats *video_stats_receiver_get_stats();
- void video_stats_receiver_on_started(int64_t start_ms, ReceiverConfigStats *config);
- void video_stats_receiver_on_stopped(int64_t stop_ms);
- void video_stats_receiver_on_incoming_packet(int64_t recv_time_ms);
- void video_stats_receiver_on_decoded_frame(int64_t decoded_time_ms, int64_t decode_duration_ms, int is_key);
- void video_stats_receiver_on_rendered_frame(int64_t render_time_ms, int64_t rende_duration_ms);
- void video_stats_receiver_on_report_cc_bitrate(int bitrate);
- //发送相关统计
- SenderStats *video_stats_sender_get_stats();
- void video_stats_sender_on_started(int64_t start_ms, SenderConfigStats *config);
- void video_stats_sender_on_stopped(int64_t stop_ms);
- void video_stats_sender_on_sent_packet(int64_t sent_time_ms);
- void video_stats_sender_on_encoded_frame(int64_t encoded_time_ms, int64_t encode_duration_ms, int is_key);
- void video_stats_sender_on_encoder_rate_changed(int allocation_fps, int allocation_bitrate);
- void video_stats_sender_on_frame_dropped(int cap_drop, int framedropper_drop);
- //带宽统计
- void video_stats_bandwidth_update_recv_rtp_bytes(size_t nbytes);
- void video_stats_bandwidth_update_recv_rtcp_bytes(size_t nbytes);
- void video_stats_bandwidth_update_send_rtp_bytes(int nbytes);
- void video_stats_bandwidth_update_send_rtcp_bytes(int nbytes);
- float video_stats_bandwidth_compute_loss_rate(rtcp_statistics *rtcp_stat);
- #ifdef __cplusplus
- }
- #endif /* end of __cplusplus */
- #endif
|