@@ -292,32 +292,41 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl,
292292 s -> first_pkt_rtp_ts = tmstamp ;
293293 }
294294
295+ if (unlikely (s -> latest_seq_id [s_port ] == -1 )) s -> latest_seq_id [s_port ] = seq_id - 1 ;
296+ if (unlikely (s -> session_seq_id == -1 )) s -> session_seq_id = seq_id - 1 ;
295297 if (unlikely (s -> tmstamp == -1 )) s -> tmstamp = tmstamp - 1 ;
296298
297- /* all packets need to have increasing tmstamp */
299+ /* redundant stream seq_id out of order is not a big deal as long as stream is continous
300+ */
301+ if (seq_id != (uint16_t )(s -> latest_seq_id [s_port ] + 1 )) {
302+ dbg ("%s(%d,%d), non-continuous seq now %u last %d\n" , __func__ , s -> idx , s_port ,
303+ seq_id , s -> latest_seq_id [s_port ]);
304+ s -> port_user_stats .common .port [s_port ].out_of_order_packets ++ ;
305+ s -> stat_pkts_out_of_order_per_port [s_port ]++ ;
306+ }
307+ s -> latest_seq_id [s_port ] = seq_id ;
308+
309+ /* all packets need to have increasing timestamp */
298310 if (!mt_seq32_greater (tmstamp , s -> tmstamp )) {
299311 dbg ("%s(%d,%d), drop as pkt seq_id %u (%u) or tmstamp %u (%ld) is old\n" , __func__ ,
300312 s -> idx , s_port , seq_id , s -> latest_seq_id [s_port ], tmstamp , s -> tmstamp );
301313 ST_SESSION_STAT_INC (s , port_user_stats , stat_pkts_redundant );
302- s -> latest_seq_id [s_port ] = seq_id ;
303314 return - EIO ;
304315 }
305316 s -> tmstamp = tmstamp ;
306317
307- if (unlikely (s -> latest_seq_id [MTL_PORT_P ] == -1 ))
308- s -> latest_seq_id [MTL_PORT_P ] = seq_id - 1 ;
309- if (unlikely (s -> latest_seq_id [MTL_PORT_R ] == -1 ))
310- s -> latest_seq_id [MTL_PORT_R ] = seq_id - 1 ;
311-
312- if (seq_id != (uint16_t )(s -> latest_seq_id [s_port ] + 1 )) {
313- dbg ("%s(%d,%d), non-continuous seq now %u last %d\n" , __func__ , s -> idx , s_port ,
314- seq_id , s -> latest_seq_id [s_port ]);
318+ /* hole in seq id packets going into the session check if the seq_id of the session is
319+ * consistent */
320+ if (seq_id != (uint16_t )(s -> session_seq_id + 1 )) {
321+ dbg ("%s(%d,%d), session seq_id %u out of order %d\n" , __func__ , s -> idx , s_port ,
322+ seq_id , s -> session_seq_id );
323+ s -> stat_pkts_out_of_order ++ ;
315324 ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
316325 }
317326
318327 /* The package is accepted and goes into the frame */
319- /* update seq id */
320- s -> latest_seq_id [ s_port ] = seq_id ;
328+
329+ s -> session_seq_id = seq_id ;
321330
322331 if (!s -> st30_cur_frame ) {
323332 s -> st30_cur_frame = rx_audio_session_get_frame (s );
@@ -423,6 +432,7 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl,
423432
424433 uint16_t seq_id = ntohs (rtp -> seq_number );
425434 uint8_t payload_type = rtp -> payload_type ;
435+ uint32_t tmstamp = ntohl (rtp -> tmstamp );
426436
427437 if (ops -> payload_type && (payload_type != ops -> payload_type )) {
428438 dbg ("%s(%d,%d), get payload_type %u but expect %u\n" , __func__ , s -> idx , s_port ,
@@ -441,23 +451,40 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl,
441451 }
442452
443453 if (unlikely (s -> latest_seq_id [s_port ] == -1 )) s -> latest_seq_id [s_port ] = seq_id - 1 ;
454+ if (unlikely (s -> session_seq_id == -1 )) s -> session_seq_id = seq_id - 1 ;
455+ if (unlikely (s -> tmstamp == -1 )) s -> tmstamp = tmstamp - 1 ;
456+
457+ /* redundant stream seq_id out of order is not a big deal as long as stream is continous
458+ */
444459 if (seq_id != (uint16_t )(s -> latest_seq_id [s_port ] + 1 )) {
445460 dbg ("%s(%d,%d), non-continuous seq now %u last %d\n" , __func__ , s -> idx , s_port ,
446461 seq_id , s -> latest_seq_id [s_port ]);
447- ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
462+ s -> port_user_stats .common .port [s_port ].out_of_order_packets ++ ;
463+ s -> stat_pkts_out_of_order_per_port [s_port ]++ ;
448464 }
465+ s -> latest_seq_id [s_port ] = seq_id ;
449466
450- /* Only works for redundant streams basicly drop packets that are old */
451- if (st_rx_seq_redundant_drop (seq_id , s -> latest_seq_id , s_port , s -> ops .num_port )) {
452- dbg ("%s(%d,%d), drop as pkt seq %d is old\n" , __func__ , s -> idx , s_port , seq_id );
453-
467+ /* all packets need to have increasing timestamp */
468+ if (!mt_seq32_greater (tmstamp , s -> tmstamp )) {
469+ dbg ("%s(%d,%d), drop as pkt seq_id %u (%u) or tmstamp %u (%ld) is old\n" , __func__ ,
470+ s -> idx , s_port , seq_id , s -> latest_seq_id [s_port ], tmstamp , s -> tmstamp );
471+ s -> stat_pkts_redundant ++ ;
454472 ST_SESSION_STAT_INC (s , port_user_stats , stat_pkts_redundant );
455- s -> latest_seq_id [s_port ] = seq_id ;
456473 return - EIO ;
457474 }
475+ s -> tmstamp = tmstamp ;
458476
459- /* update seq id */
460- s -> latest_seq_id [s_port ] = seq_id ;
477+ /* hole in seq id packets going into the session check if the seq_id of the session is
478+ * consistent */
479+ if (seq_id != (uint16_t )(s -> session_seq_id + 1 )) {
480+ dbg ("%s(%d,%d), session seq_id %u out of order %d\n" , __func__ , s -> idx , s_port ,
481+ seq_id , s -> session_seq_id );
482+ s -> stat_pkts_out_of_order ++ ;
483+ ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
484+ }
485+
486+ /* The package is accepted and goes into the frame */
487+ s -> session_seq_id = seq_id ;
461488
462489 /* enqueue the packet ring to app */
463490 int ret = rte_ring_sp_enqueue (s -> st30_rtps_ring , (void * )mbuf );
@@ -605,10 +632,6 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) {
605632 rv = mt_rxq_burst (s -> rxq [s_port ], & mbuf [0 ], ST_RX_AUDIO_BURST_SIZE );
606633 if (!rv ) continue ;
607634
608- if (s_port == 1 ) {
609- dbg ("DEBUG" );
610- }
611-
612635 rx_audio_session_handle_mbuf (& s -> priv [s_port ], & mbuf [0 ], rv );
613636 rte_pktmbuf_free_bulk (& mbuf [0 ], rv );
614637 if (s -> enable_timing_parser && s -> tp ) {
@@ -821,6 +844,7 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl,
821844 s -> st30_pkt_idx = 0 ;
822845 s -> st30_frame_size = ops -> framebuff_size ;
823846
847+ s -> session_seq_id = -1 ;
824848 s -> latest_seq_id [MTL_SESSION_PORT_P ] = -1 ;
825849 s -> latest_seq_id [MTL_SESSION_PORT_R ] = -1 ;
826850 s -> tmstamp = -1 ;
@@ -897,21 +921,28 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr,
897921
898922 rte_atomic32_set (& s -> stat_frames_received , 0 );
899923
900- notice ("RX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d pkts %d\n" , m_idx , idx ,
901- s -> ops_name , framerate , frames_received , s -> stat_pkts_received );
902- s -> stat_pkts_received = 0 ;
903- s -> stat_last_time = cur_time_ns ;
904-
905924 if (s -> stat_pkts_redundant ) {
906- notice ("RX_AUDIO_SESSION(%d,%d): redundant pkts %d\n" , m_idx , idx ,
925+ notice ("RX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d pkts %d (redundant %d)\n" , m_idx ,
926+ idx , s -> ops_name , framerate , frames_received , s -> stat_pkts_received ,
907927 s -> stat_pkts_redundant );
908928 s -> stat_pkts_redundant = 0 ;
929+ } else {
930+ info ("RX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d pkts %d\n" , m_idx , idx ,
931+ s -> ops_name , framerate , frames_received , s -> stat_pkts_received );
909932 }
933+
934+ s -> stat_pkts_received = 0 ;
935+ s -> stat_last_time = cur_time_ns ;
910936 if (s -> stat_pkts_out_of_order ) {
911- warn ("RX_AUDIO_SESSION(%d,%d): out of order pkts %d\n" , m_idx , idx ,
912- s -> stat_pkts_out_of_order );
937+ warn ("RX_AUDIO_SESSION(%d): out of order pkts %d (%d:%d)\n" , idx ,
938+ s -> stat_pkts_out_of_order ,
939+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_P ],
940+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_R ]);
913941 s -> stat_pkts_out_of_order = 0 ;
942+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_P ] = 0 ;
943+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_R ] = 0 ;
914944 }
945+
915946 if (s -> stat_pkts_dropped ) {
916947 notice ("RX_AUDIO_SESSION(%d,%d): dropped pkts %d\n" , m_idx , idx ,
917948 s -> stat_pkts_dropped );
@@ -989,6 +1020,8 @@ static int rx_audio_session_update_src(struct mtl_main_impl* impl,
9891020 s -> st30_dst_port [i ] = (ops -> udp_port [i ]) ? (ops -> udp_port [i ]) : (20000 + idx * 2 );
9901021 }
9911022 /* reset seq id */
1023+
1024+ s -> session_seq_id = -1 ;
9921025 s -> latest_seq_id [MTL_SESSION_PORT_P ] = -1 ;
9931026 s -> latest_seq_id [MTL_SESSION_PORT_R ] = -1 ;
9941027 s -> tmstamp = -1 ;
0 commit comments