]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11955: JB: add stats for received packets that have been NACKed previously (video)
authorDragos Oancea <dragos@signalwire.com>
Thu, 25 Jul 2019 14:21:39 +0000 (14:21 +0000)
committerDragos Oancea <dragos@signalwire.com>
Thu, 25 Jul 2019 14:28:38 +0000 (14:28 +0000)
src/include/switch_jitterbuffer.h
src/switch_jitterbuffer.c
src/switch_rtp.c

index 5e53967b8b9cb1a1af20b2325ca3c78167db8758..d21b343c6bbcb15e9bfab66d30ebd586a842ccd1 100644 (file)
@@ -64,6 +64,7 @@ SWITCH_DECLARE(void) switch_jb_set_session(switch_jb_t *jb, switch_core_session_
 SWITCH_DECLARE(void) switch_jb_ts_mode(switch_jb_t *jb, uint32_t samples_per_frame, uint32_t samples_per_second);
 SWITCH_DECLARE(void) switch_jb_set_flag(switch_jb_t *jb, switch_jb_flag_t flag);
 SWITCH_DECLARE(void) switch_jb_clear_flag(switch_jb_t *jb, switch_jb_flag_t flag);
+SWITCH_DECLARE(uint32_t) switch_jb_get_nack_success(switch_jb_t *jb);
 
 SWITCH_END_EXTERN_C
 #endif
index 8eabe61aba0e6017f4caf669f94ed5b2be49b96f..4cecb928b9e531e4f9d238a5a9a2bbc329e852ca 100644 (file)
@@ -107,6 +107,8 @@ struct switch_jb_s {
        uint32_t packet_count;
        uint32_t max_packet_len;
        uint32_t period_len;
+       uint32_t nack_saved_the_day;
+       uint32_t nack_didnt_save_the_day;
 };
 
 
@@ -971,6 +973,15 @@ SWITCH_DECLARE(void) switch_jb_reset(switch_jb_t *jb)
        jb->last_target_ts = 0;
 }
 
+SWITCH_DECLARE(uint32_t) switch_jb_get_nack_success(switch_jb_t *jb) 
+{
+       uint32_t nack_recovered; /*count*/
+       switch_mutex_lock(jb->mutex);
+       nack_recovered = jb->nack_saved_the_day + jb->nack_didnt_save_the_day;
+       switch_mutex_unlock(jb->mutex);
+       return nack_recovered;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_jb_peek_frame(switch_jb_t *jb, uint32_t ts, uint16_t seq, int peek, switch_frame_t *frame)
 {
        switch_jb_node_t *node = NULL;
@@ -1091,6 +1102,11 @@ SWITCH_DECLARE(switch_status_t) switch_jb_destroy(switch_jb_t **jbp)
        switch_jb_t *jb = *jbp;
        *jbp = NULL;
 
+       if (jb->type == SJB_VIDEO && !switch_test_flag(jb, SJB_QUEUE_ONLY)) {
+               jb_debug(jb, 3, "Stats: NACK saved the day: %u\n", jb->nack_saved_the_day);
+               jb_debug(jb, 3, "Stats: NACK was late: %u\n", jb->nack_didnt_save_the_day);
+               jb_debug(jb, 3, "Stats: Hash entrycount: missing_seq_hash %u\n", switch_hashtable_count(jb->missing_seq_hash));
+       }
        if (jb->type == SJB_VIDEO) {
                switch_core_inthash_destroy(&jb->missing_seq_hash);
        }
@@ -1223,8 +1239,10 @@ SWITCH_DECLARE(switch_status_t) switch_jb_put_packet(switch_jb_t *jb, switch_rtp
                        if (got < ntohs(jb->target_seq)) {
                                jb_debug(jb, 2, "got nacked seq %u too late\n", got);
                                jb_frame_inc(jb, 1);
+                               jb->nack_didnt_save_the_day++;
                        } else {
                                jb_debug(jb, 2, "got nacked %u saved the day!\n", got);
+                               jb->nack_saved_the_day++;
                        }
                }
 
index cd65160646ff9fb73bdb3ba23416a8c464a108a0..fd78810dd56d854f4dfca7b659cd32f067843a14 100644 (file)
@@ -5090,6 +5090,13 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session)
                return;
        }
 
+       if ((*rtp_session)->vb) {
+               /* retrieve counter for ALL received NACKed packets */
+               uint32_t nack_jb_ok = switch_jb_get_nack_success((*rtp_session)->vb);
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG((*rtp_session)->session), SWITCH_LOG_DEBUG, 
+                               "NACK: Added to JB: [%u]\n", nack_jb_ok);
+       }
+
        (*rtp_session)->flags[SWITCH_RTP_FLAG_SHUTDOWN] = 1;
 
        READ_INC((*rtp_session));