<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/11009">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session Added rtcp stats result vector into the session<br><br>Currently, the Asterisk's pjsip_session module does not keeping the<br>rtcp's stats info after it was removed. But by adding the results<br>vector and keeping it until session is destroying, it can give more<br>useful information for other modules.<br><br>ASTERISK-28253<br><br>Change-Id: Ib25c2d3fc4da084aecfde2a82c1b1d733bd64fa5<br>---<br>M include/asterisk/res_pjsip_session.h<br>M res/res_pjsip_session.c<br>2 files changed, 63 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h</span><br><span>index fbd1d16..a6f8bde 100644</span><br><span>--- a/include/asterisk/res_pjsip_session.h</span><br><span>+++ b/include/asterisk/res_pjsip_session.h</span><br><span>@@ -215,6 +215,8 @@</span><br><span> enum ast_sip_dtmf_mode dtmf;</span><br><span> /*! Initial incoming INVITE Request-URI. NULL otherwise. */</span><br><span> pjsip_uri *request_uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Media statistics for negotiated RTP streams */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR(, struct ast_rtp_instance_stats *) media_stats;</span><br><span> };</span><br><span> </span><br><span> typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);</span><br><span>@@ -829,6 +831,13 @@</span><br><span> struct ast_sip_session_media_state *media_state, enum ast_media_type type, int position);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Save a media stats.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param media_state The media state to save</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_sip_session_media_stats_save(struct ast_sip_session *sip_session, struct ast_sip_session_media_state *media_state);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Reset a media state to a clean state</span><br><span> * \since 15.0.0</span><br><span> *</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 8ec9a23..5e7b833 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -48,6 +48,7 @@</span><br><span> #include "asterisk/pickup.h"</span><br><span> #include "asterisk/test.h"</span><br><span> #include "asterisk/stream.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/vector.h"</span><br><span> </span><br><span> #define SDP_HANDLER_BUCKETS 11</span><br><span> </span><br><span>@@ -176,6 +177,16 @@</span><br><span> ao2_callback_data(sdp_handlers, OBJ_KEY | OBJ_UNLINK | OBJ_NODATA, remove_handler, (void *)stream_type, handler);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int media_stats_local_ssrc_cmp(</span><br><span style="color: hsl(120, 100%, 40%);">+ const struct ast_rtp_instance_stats *vec_elem, const struct ast_rtp_instance_stats *srch)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (vec_elem->local_ssrc == srch->local_ssrc) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_sip_session_media_state *internal_sip_session_media_state_alloc(</span><br><span> size_t sessions, size_t read_callbacks)</span><br><span> {</span><br><span>@@ -206,6 +217,40 @@</span><br><span> DEFAULT_NUM_SESSION_MEDIA, DEFAULT_NUM_SESSION_MEDIA);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void ast_sip_session_media_stats_save(struct ast_sip_session *sip_session, struct ast_sip_session_media_state *media_state)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int ret;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!media_state || !sip_session) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < AST_VECTOR_SIZE(&media_state->sessions); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_rtp_instance_stats *stats_tmp = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_session_media *media = AST_VECTOR_GET(&media_state->sessions, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!media || !media->rtp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stats_tmp = ast_calloc(1, sizeof(struct ast_rtp_instance_stats));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!stats_tmp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ret = ast_rtp_instance_get_stats(media->rtp, stats_tmp, AST_RTP_INSTANCE_STAT_ALL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ret) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(stats_tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* remove all the duplicated stats if exist */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_REMOVE_CMP_UNORDERED(&sip_session->media_stats, stats_tmp, media_stats_local_ssrc_cmp, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_APPEND(&sip_session->media_stats, stats_tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ast_sip_session_media_state_reset(struct ast_sip_session_media_state *media_state)</span><br><span> {</span><br><span> int index;</span><br><span>@@ -1010,6 +1055,7 @@</span><br><span> }</span><br><span> </span><br><span> /* Active and pending flip flop as needed */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_media_stats_save(session, session->active_media_state);</span><br><span> SWAP(session->active_media_state, session->pending_media_state);</span><br><span> ast_sip_session_media_state_reset(session->pending_media_state);</span><br><span> </span><br><span>@@ -2113,6 +2159,10 @@</span><br><span> ast_sip_session_remove_supplements(session);</span><br><span> AST_LIST_HEAD_DESTROY(&session->supplements);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* remove all saved media stats */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_RESET(&session->media_stats, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_FREE(&session->media_stats);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_taskprocessor_unreference(session->serializer);</span><br><span> ao2_cleanup(session->datastores);</span><br><span> ast_sip_session_media_state_free(session->active_media_state);</span><br><span>@@ -2194,6 +2244,9 @@</span><br><span> if (!session->pending_media_state) {</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_VECTOR_INIT(&session->media_stats, 1) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (endpoint->dtmf == AST_SIP_DTMF_INBAND || endpoint->dtmf == AST_SIP_DTMF_AUTO) {</span><br><span> dsp_features |= DSP_FEATURE_DIGIT_DETECT;</span><br><span>@@ -2637,6 +2690,7 @@</span><br><span> * places when the session is to be terminated we terminate any existing</span><br><span> * media sessions here.</span><br><span> */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sip_session_media_stats_save(session, session->active_media_state);</span><br><span> SWAP(session->active_media_state, session->pending_media_state);</span><br><span> ast_sip_session_media_state_reset(session->pending_media_state);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/11009">change 11009</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/11009"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib25c2d3fc4da084aecfde2a82c1b1d733bd64fa5 </div>
<div style="display:none"> Gerrit-Change-Number: 11009 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>