@@ -983,24 +983,11 @@ static inline int check_jb_size(switch_jb_t *jb)
983983
984984 /* update the stats every x packets */
985985 if (target_seq_hs % 50 == 0 ) {
986- int packet_ms = jb -> jitter .samples_per_frame / (jb -> jitter .samples_per_second / 1000 );
987-
988986 jb -> jitter .stats .estimate_ms = (* jb -> jitter .estimate ) / jb -> jitter .samples_per_second * 1000 ;
989- if (jb -> channel ) {
990- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_size_max_ms" , "%u" , jb -> jitter .stats .size_max * packet_ms );
991- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_size_est_ms" , "%u" , jb -> jitter .stats .size_est * packet_ms );
992- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_acceleration_ms" , "%u" , jb -> jitter .stats .acceleration * packet_ms );
993- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_expand_ms" , "%u" , jb -> jitter .stats .expand * packet_ms );
994- }
995987
996988 if (jb -> jitter .stats .jitter_max_ms < jb -> jitter .stats .estimate_ms ) {
997989 jb -> jitter .stats .jitter_max_ms = jb -> jitter .stats .estimate_ms ;
998990 }
999-
1000- if (jb -> channel ) {
1001- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_max_ms" , "%u" , jb -> jitter .stats .jitter_max_ms );
1002- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_est_ms" , "%u" , jb -> jitter .stats .estimate_ms );
1003- }
1004991 }
1005992
1006993 if (old ) {
@@ -1102,19 +1089,6 @@ SWITCH_DECLARE(void) switch_jb_set_jitter_estimator(switch_jb_t *jb, double *jit
11021089{
11031090 if (jb && jitter ) {
11041091 memset (& jb -> jitter , 0 , sizeof (switch_jb_jitter_t ));
1105- if (jb -> channel ) {
1106- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_max_ms" , "%u" , 0 );
1107- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_size_ms" , "%u" , 0 );
1108- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_acceleration_ms" , "%u" , 0 );
1109- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_expand_ms" , "%u" , 0 );
1110- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_max_ms" , "%u" , 0 );
1111- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_ms" , "%u" , 0 );
1112- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_count" , "%u" , 0 );
1113- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_too_big" , "%u" , 0 );
1114- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_missing_frames" , "%u" , 0 );
1115- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_ts_jump" , "%u" , 0 );
1116- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_error" , "%u" , 0 );
1117- }
11181092
11191093 jb -> jitter .estimate = jitter ;
11201094 jb -> jitter .samples_per_frame = samples_per_frame ;
@@ -1197,14 +1171,6 @@ SWITCH_DECLARE(void) switch_jb_reset(switch_jb_t *jb)
11971171{
11981172 jb -> jitter .stats .reset ++ ;
11991173 jb -> jitter .stats .expand_frame_len = 0 ;
1200- if (jb -> channel ) {
1201- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_count" , "%u" , jb -> jitter .stats .reset );
1202- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_too_big" , "%u" , jb -> jitter .stats .reset_too_big );
1203- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_too_expanded" , "%u" , jb -> jitter .stats .reset_too_expanded );
1204- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_missing_frames" , "%u" , jb -> jitter .stats .reset_missing_frames );
1205- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_ts_jump" , "%u" , jb -> jitter .stats .reset_ts_jump );
1206- switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_error" , "%u" , jb -> jitter .stats .reset_error );
1207- }
12081174
12091175 if (jb -> type == SJB_VIDEO ) {
12101176 switch_mutex_lock (jb -> mutex );
@@ -1378,6 +1344,87 @@ SWITCH_DECLARE(switch_status_t) switch_jb_create(switch_jb_t **jbp, switch_jb_ty
13781344 return SWITCH_STATUS_SUCCESS ;
13791345}
13801346
1347+ SWITCH_DECLARE (void ) switch_jb_export_stats (switch_jb_t * jb )
1348+ {
1349+ int packet_ms = 0 ;
1350+
1351+ if (!jb || !jb -> channel ) {
1352+ return ;
1353+ }
1354+
1355+ switch_mutex_lock (jb -> mutex );
1356+
1357+ switch_log_printf (SWITCH_CHANNEL_CHANNEL_LOG (jb -> channel ), SWITCH_LOG_INFO ,
1358+ "switch_jb_export_stats: type=%s elastic=%s reset_count=%u\n" ,
1359+ jb -> type == SJB_VIDEO ? "video" : (jb -> type == SJB_AUDIO ? "audio" : "text" ),
1360+ jb -> elastic ? "true" : "false" ,
1361+ jb -> jitter .stats .reset );
1362+
1363+ /* Export jitter buffer configuration */
1364+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_type" , "%s" ,
1365+ jb -> type == SJB_VIDEO ? "video" : (jb -> type == SJB_AUDIO ? "audio" : "text" ));
1366+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_min_frame_len" , "%u" , jb -> min_frame_len );
1367+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_max_frame_len" , "%u" , jb -> max_frame_len );
1368+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_cur_frame_len" , "%u" , jb -> frame_len );
1369+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_highest_frame_len" , "%u" , jb -> highest_frame_len );
1370+
1371+ /* Export buffer state */
1372+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_visible_nodes" , "%u" , jb -> visible_nodes );
1373+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_allocated_nodes" , "%u" , jb -> allocated_nodes );
1374+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_complete_frames" , "%u" , jb -> complete_frames );
1375+
1376+ /* Export miss/hit statistics */
1377+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_period_miss_count" , "%u" , jb -> period_miss_count );
1378+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_consec_miss_count" , "%u" , jb -> consec_miss_count );
1379+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_period_good_count" , "%u" , jb -> period_good_count );
1380+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_consec_good_count" , "%u" , jb -> consec_good_count );
1381+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_period_miss_pct" , "%.2f" , jb -> period_miss_pct );
1382+
1383+ /* Export jitter estimator statistics */
1384+ if (jb -> jitter .samples_per_frame && jb -> jitter .samples_per_second ) {
1385+ packet_ms = jb -> jitter .samples_per_frame / (jb -> jitter .samples_per_second / 1000 );
1386+ }
1387+
1388+ if (jb -> jitter .estimate && jb -> jitter .samples_per_second ) {
1389+ jb -> jitter .stats .estimate_ms = (* jb -> jitter .estimate ) / jb -> jitter .samples_per_second * 1000 ;
1390+ }
1391+
1392+ if (packet_ms ) {
1393+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_size_max_ms" , "%u" , jb -> jitter .stats .size_max * packet_ms );
1394+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_size_est_ms" , "%u" , jb -> jitter .stats .size_est * packet_ms );
1395+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_acceleration_ms" , "%u" , jb -> jitter .stats .acceleration * packet_ms );
1396+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_expand_ms" , "%u" , jb -> jitter .stats .expand * packet_ms );
1397+ }
1398+
1399+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_buffering_skip" , "%u" , jb -> jitter .stats .buffering_skip );
1400+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_max_ms" , "%u" , jb -> jitter .stats .jitter_max_ms );
1401+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_jitter_est_ms" , "%u" , jb -> jitter .stats .estimate_ms );
1402+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_buffer_size_ms" , "%u" , jb -> jitter .stats .buffer_size_ms );
1403+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_expand_frame_len" , "%d" , jb -> jitter .stats .expand_frame_len );
1404+
1405+ /* Export reset statistics */
1406+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_count" , "%u" , jb -> jitter .stats .reset );
1407+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_too_big" , "%u" , jb -> jitter .stats .reset_too_big );
1408+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_too_expanded" , "%u" , jb -> jitter .stats .reset_too_expanded );
1409+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_missing_frames" , "%u" , jb -> jitter .stats .reset_missing_frames );
1410+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_ts_jump" , "%u" , jb -> jitter .stats .reset_ts_jump );
1411+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_reset_error" , "%u" , jb -> jitter .stats .reset_error );
1412+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_consecutive_miss" , "%u" , jb -> jitter .stats .consecutive_miss );
1413+
1414+ /* Export video-specific statistics */
1415+ if (jb -> type == SJB_VIDEO ) {
1416+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_nack_saved_the_day" , "%u" , jb -> nack_saved_the_day );
1417+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_nack_didnt_save_the_day" , "%u" , jb -> nack_didnt_save_the_day );
1418+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_max_packet_len" , "%u" , jb -> max_packet_len );
1419+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_packet_count" , "%u" , jb -> packet_count );
1420+ }
1421+
1422+ /* Export elastic buffer info */
1423+ switch_channel_set_variable_printf (jb -> channel , "rtp_jb_elastic" , "%s" , jb -> elastic ? "true" : "false" );
1424+
1425+ switch_mutex_unlock (jb -> mutex );
1426+ }
1427+
13811428SWITCH_DECLARE (switch_status_t ) switch_jb_destroy (switch_jb_t * * jbp )
13821429{
13831430 switch_jb_t * jb = * jbp ;
0 commit comments