@@ -292,32 +292,42 @@ 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 );
313+ s -> stat_pkts_redundant ++ ;
301314 ST_SESSION_STAT_INC (s , port_user_stats , stat_pkts_redundant );
302- s -> latest_seq_id [s_port ] = seq_id ;
303315 return - EIO ;
304316 }
305317 s -> tmstamp = tmstamp ;
306318
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 ]);
319+ /* hole in seq id packets going into the session check if the seq_id of the session is
320+ * consistent */
321+ if (seq_id != (uint16_t )(s -> session_seq_id + 1 )) {
322+ dbg ("%s(%d,%d), session seq_id %u out of order %d\n" , __func__ , s -> idx , s_port ,
323+ seq_id , s -> session_seq_id );
324+ s -> stat_pkts_out_of_order ++ ;
315325 ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
316326 }
317327
318328 /* The package is accepted and goes into the frame */
319- /* update seq id */
320- s -> latest_seq_id [ s_port ] = seq_id ;
329+
330+ s -> session_seq_id = seq_id ;
321331
322332 if (!s -> st30_cur_frame ) {
323333 s -> st30_cur_frame = rx_audio_session_get_frame (s );
@@ -423,6 +433,7 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl,
423433
424434 uint16_t seq_id = ntohs (rtp -> seq_number );
425435 uint8_t payload_type = rtp -> payload_type ;
436+ uint32_t tmstamp = ntohl (rtp -> tmstamp );
426437
427438 if (ops -> payload_type && (payload_type != ops -> payload_type )) {
428439 dbg ("%s(%d,%d), get payload_type %u but expect %u\n" , __func__ , s -> idx , s_port ,
@@ -441,23 +452,40 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl,
441452 }
442453
443454 if (unlikely (s -> latest_seq_id [s_port ] == -1 )) s -> latest_seq_id [s_port ] = seq_id - 1 ;
455+ if (unlikely (s -> session_seq_id == -1 )) s -> session_seq_id = seq_id - 1 ;
456+ if (unlikely (s -> tmstamp == -1 )) s -> tmstamp = tmstamp - 1 ;
457+
458+ /* redundant stream seq_id out of order is not a big deal as long as stream is continous
459+ */
444460 if (seq_id != (uint16_t )(s -> latest_seq_id [s_port ] + 1 )) {
445461 dbg ("%s(%d,%d), non-continuous seq now %u last %d\n" , __func__ , s -> idx , s_port ,
446462 seq_id , s -> latest_seq_id [s_port ]);
447- ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
463+ s -> port_user_stats .common .port [s_port ].out_of_order_packets ++ ;
464+ s -> stat_pkts_out_of_order_per_port [s_port ]++ ;
448465 }
466+ s -> latest_seq_id [s_port ] = seq_id ;
449467
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-
468+ /* all packets need to have increasing timestamp */
469+ if (!mt_seq32_greater (tmstamp , s -> tmstamp )) {
470+ dbg ("%s(%d,%d), drop as pkt seq_id %u (%u) or tmstamp %u (%ld) is old\n" , __func__ ,
471+ s -> idx , s_port , seq_id , s -> latest_seq_id [s_port ], tmstamp , s -> tmstamp );
472+ s -> stat_pkts_redundant ++ ;
454473 ST_SESSION_STAT_INC (s , port_user_stats , stat_pkts_redundant );
455- s -> latest_seq_id [s_port ] = seq_id ;
456474 return - EIO ;
457475 }
476+ s -> tmstamp = tmstamp ;
458477
459- /* update seq id */
460- s -> latest_seq_id [s_port ] = seq_id ;
478+ /* hole in seq id packets going into the session check if the seq_id of the session is
479+ * consistent */
480+ if (seq_id != (uint16_t )(s -> session_seq_id + 1 )) {
481+ dbg ("%s(%d,%d), session seq_id %u out of order %d\n" , __func__ , s -> idx , s_port ,
482+ seq_id , s -> session_seq_id );
483+ s -> stat_pkts_out_of_order ++ ;
484+ ST_SESSION_STAT_INC (s , port_user_stats .common , stat_pkts_out_of_order );
485+ }
486+
487+ /* The package is accepted and goes into the frame */
488+ s -> session_seq_id = seq_id ;
461489
462490 /* enqueue the packet ring to app */
463491 int ret = rte_ring_sp_enqueue (s -> st30_rtps_ring , (void * )mbuf );
@@ -605,10 +633,6 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) {
605633 rv = mt_rxq_burst (s -> rxq [s_port ], & mbuf [0 ], ST_RX_AUDIO_BURST_SIZE );
606634 if (!rv ) continue ;
607635
608- if (s_port == 1 ) {
609- dbg ("DEBUG" );
610- }
611-
612636 rx_audio_session_handle_mbuf (& s -> priv [s_port ], & mbuf [0 ], rv );
613637 rte_pktmbuf_free_bulk (& mbuf [0 ], rv );
614638 if (s -> enable_timing_parser && s -> tp ) {
@@ -821,6 +845,7 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl,
821845 s -> st30_pkt_idx = 0 ;
822846 s -> st30_frame_size = ops -> framebuff_size ;
823847
848+ s -> session_seq_id = -1 ;
824849 s -> latest_seq_id [MTL_SESSION_PORT_P ] = -1 ;
825850 s -> latest_seq_id [MTL_SESSION_PORT_R ] = -1 ;
826851 s -> tmstamp = -1 ;
@@ -897,21 +922,28 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr,
897922
898923 rte_atomic32_set (& s -> stat_frames_received , 0 );
899924
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-
905925 if (s -> stat_pkts_redundant ) {
906- notice ("RX_AUDIO_SESSION(%d,%d): redundant pkts %d\n" , m_idx , idx ,
926+ notice ("RX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d pkts %d (redundant %d)\n" , m_idx ,
927+ idx , s -> ops_name , framerate , frames_received , s -> stat_pkts_received ,
907928 s -> stat_pkts_redundant );
908929 s -> stat_pkts_redundant = 0 ;
930+ } else {
931+ info ("RX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d pkts %d\n" , m_idx , idx ,
932+ s -> ops_name , framerate , frames_received , s -> stat_pkts_received );
909933 }
934+
935+ s -> stat_pkts_received = 0 ;
936+ s -> stat_last_time = cur_time_ns ;
910937 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 );
938+ warn ("RX_AUDIO_SESSION(%d): out of order pkts %d (%d:%d)\n" , idx ,
939+ s -> stat_pkts_out_of_order ,
940+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_P ],
941+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_R ]);
913942 s -> stat_pkts_out_of_order = 0 ;
943+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_P ] = 0 ;
944+ s -> stat_pkts_out_of_order_per_port [MTL_SESSION_PORT_R ] = 0 ;
914945 }
946+
915947 if (s -> stat_pkts_dropped ) {
916948 notice ("RX_AUDIO_SESSION(%d,%d): dropped pkts %d\n" , m_idx , idx ,
917949 s -> stat_pkts_dropped );
@@ -989,6 +1021,8 @@ static int rx_audio_session_update_src(struct mtl_main_impl* impl,
9891021 s -> st30_dst_port [i ] = (ops -> udp_port [i ]) ? (ops -> udp_port [i ]) : (20000 + idx * 2 );
9901022 }
9911023 /* reset seq id */
1024+
1025+ s -> session_seq_id = -1 ;
9921026 s -> latest_seq_id [MTL_SESSION_PORT_P ] = -1 ;
9931027 s -> latest_seq_id [MTL_SESSION_PORT_R ] = -1 ;
9941028 s -> tmstamp = -1 ;
0 commit comments