<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11294">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_dial.c: RINGTIME, PROGRESSTIME and ms resolution dial timings<br><br>Added RINGTIME, RINGTIME_MS, PROGRESSTIME, PROGRESSTIME_MS variables filled<br>at the earliest received PROGRESS or RINGING.<br>Added millisecond versions of DIALEDTIME and ANSWEREDTIME.<br><br>Added millisecond versions of ast_channel_get_up_time and<br>ast_channel_get_duration in channel.c.<br><br>ASTERISK-28363<br><br>Change-Id: If95f1a7d8c4acbac740037de0c6e3109ff6620b1<br>---<br>M apps/app_dial.c<br>A doc/CHANGES-staging/app_dial_ringtime_progresstime.txt<br>M include/asterisk/channel.h<br>M main/channel.c<br>4 files changed, 129 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_dial.c b/apps/app_dial.c</span><br><span>index 21d37eb..4adfc47 100644</span><br><span>--- a/apps/app_dial.c</span><br><span>+++ b/apps/app_dial.c</span><br><span>@@ -565,9 +565,27 @@</span><br><span> <variable name="DIALEDTIME"></span><br><span> <para>This is the time from dialing a channel until when it is disconnected.</para></span><br><span> </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="DIALEDTIME_MS"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the milliseconds version of the DIALEDTIME variable.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span> <variable name="ANSWEREDTIME"></span><br><span> <para>This is the amount of time for actual call.</para></span><br><span> </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="ANSWEREDTIME_MS"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the milliseconds version of the ANSWEREDTIME variable.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="RINGTIME"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the time from creating the channel to the first RINGING event received. Empty if there was no ring.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="RINGTIME_MS"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the milliseconds version of the RINGTIME variable.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="PROGRESSTIME"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the time from creating the channel to the first PROGRESS event received. Empty if there was no such event.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="PROGRESSTIME_MS"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This is the milliseconds version of the PROGRESSTIME variable.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span> <variable name="DIALEDPEERNAME"></span><br><span> <para>The name of the outbound channel that answered the call.</para></span><br><span> </variable></span><br><span>@@ -1162,6 +1180,23 @@</span><br><span> ast_party_connected_line_free(&connected_caller);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \pre chan is locked</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char buf[32];</span><br><span style="color: hsl(120, 100%, 40%);">+ char full_var_name[128];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, var_base, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buf, sizeof(buf), "%" PRId64, duration);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, full_var_name, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_channel *wait_for_answer(struct ast_channel *in,</span><br><span> struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,</span><br><span> char *opt_args[],</span><br><span>@@ -1184,6 +1219,8 @@</span><br><span> int is_cc_recall;</span><br><span> int cc_frame_received = 0;</span><br><span> int num_ringing = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int sent_ring = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int sent_progress = 0;</span><br><span> struct timeval start = ast_tvnow();</span><br><span> </span><br><span> if (single) {</span><br><span>@@ -1457,6 +1494,23 @@</span><br><span> ast_indicate(in, AST_CONTROL_RINGING);</span><br><span> pa->sentringing++;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!sent_ring) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval now, then;</span><br><span style="color: hsl(120, 100%, 40%);">+ int64_t diff;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ now = ast_tvnow();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_stage_snapshot(in);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ then = ast_channel_creationtime(c);</span><br><span style="color: hsl(120, 100%, 40%);">+ diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_duration_var(in, "RINGTIME", diff);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_stage_snapshot_done(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ sent_ring = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> ast_channel_publish_dial(in, c, NULL, "RINGING");</span><br><span> break;</span><br><span>@@ -1472,6 +1526,23 @@</span><br><span> ast_indicate(in, AST_CONTROL_PROGRESS);</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!sent_progress) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval now, then;</span><br><span style="color: hsl(120, 100%, 40%);">+ int64_t diff;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ now = ast_tvnow();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_stage_snapshot(in);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ then = ast_channel_creationtime(c);</span><br><span style="color: hsl(120, 100%, 40%);">+ diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_duration_var(in, "PROGRESSTIME", diff);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_stage_snapshot_done(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(in);</span><br><span style="color: hsl(120, 100%, 40%);">+ sent_progress = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> if (!ast_strlen_zero(dtmf_progress)) {</span><br><span> ast_verb(3,</span><br><span> "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",</span><br><span>@@ -2058,18 +2129,12 @@</span><br><span> </span><br><span> static void end_bridge_callback(void *data)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char buf[80];</span><br><span style="color: hsl(0, 100%, 40%);">- time_t end;</span><br><span> struct ast_channel *chan = data;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- time(&end);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ast_channel_lock(chan);</span><br><span> ast_channel_stage_snapshot(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(buf, sizeof(buf), "%d", ast_channel_get_up_time(chan));</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(buf, sizeof(buf), "%d", ast_channel_get_duration(chan));</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+ set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan));</span><br><span> ast_channel_stage_snapshot_done(chan);</span><br><span> ast_channel_unlock(chan);</span><br><span> }</span><br><span>@@ -2211,7 +2276,13 @@</span><br><span> pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");</span><br><span> pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");</span><br><span> pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");</span><br><span> pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "RINGTIME", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");</span><br><span> ast_channel_stage_snapshot_done(chan);</span><br><span> max_forwards = ast_max_forwards_get(chan);</span><br><span> ast_channel_unlock(chan);</span><br><span>diff --git a/doc/CHANGES-staging/app_dial_ringtime_progresstime.txt b/doc/CHANGES-staging/app_dial_ringtime_progresstime.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..9b5cdd5</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_dial_ringtime_progresstime.txt</span><br><span>@@ -0,0 +1,12 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: Dial</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add RINGTIME and RINGTIME_MS variables containing respectively seconds and</span><br><span style="color: hsl(120, 100%, 40%);">+milliseconds between creation of the dialing channel and receiving the first</span><br><span style="color: hsl(120, 100%, 40%);">+RINGING signal</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add PROGRESSTIME and PROGRESSTIME_MS variables analogous to the above with respect to</span><br><span style="color: hsl(120, 100%, 40%);">+the PROGRESS signal. Shorter of these two times should be equivalent to</span><br><span style="color: hsl(120, 100%, 40%);">+the PDD (Post Dial Delay) value</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add DIALEDTIME_MS and ANSWEREDTIME_MS variables to get millisecond resolution</span><br><span style="color: hsl(120, 100%, 40%);">+versions of DIALEDTIME and ANSWEREDTIME</span><br><span>diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index e2f7959..3d8b70a 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2415,6 +2415,18 @@</span><br><span> void ast_deactivate_generator(struct ast_channel *chan);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.27.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.4.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Obtain how long it's been, in milliseconds, since the channel was created</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan The channel object</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if the time value cannot be computed (or you called this really fast)</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval The number of milliseconds since channel creation</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int64_t ast_channel_get_duration_ms(struct ast_channel *chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \since 12</span><br><span> * \brief Obtain how long the channel since the channel was created</span><br><span> *</span><br><span>@@ -2426,6 +2438,18 @@</span><br><span> int ast_channel_get_duration(struct ast_channel *chan);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.27.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 16.4.0</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Obtain how long it has been since the channel was answered in ms</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan The channel object</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if the channel isn't answered (or you called this really fast)</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval The number of milliseconds the channel has been up</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int64_t ast_channel_get_up_time_ms(struct ast_channel *chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \since 12</span><br><span> * \brief Obtain how long it has been since the channel was answered</span><br><span> *</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index bad1480..be88a3b 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -2789,24 +2789,34 @@</span><br><span> return ast_answer(chan);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-int ast_channel_get_duration(struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+int64_t ast_channel_get_duration_ms(struct ast_channel *chan)</span><br><span> {</span><br><span> ast_assert(NULL != chan);</span><br><span> </span><br><span> if (ast_tvzero(ast_channel_creationtime(chan))) {</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return (ast_tvdiff_ms(ast_tvnow(), ast_channel_creationtime(chan)) / 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_tvdiff_ms(ast_tvnow(), ast_channel_creationtime(chan));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-int ast_channel_get_up_time(struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_channel_get_duration(struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return (ast_channel_get_duration_ms(chan) / 1000);</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%);">+int64_t ast_channel_get_up_time_ms(struct ast_channel *chan)</span><br><span> {</span><br><span> ast_assert(NULL != chan);</span><br><span> </span><br><span> if (ast_tvzero(ast_channel_answertime(chan))) {</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return (ast_tvdiff_ms(ast_tvnow(), ast_channel_answertime(chan)) / 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_tvdiff_ms(ast_tvnow(), ast_channel_answertime(chan));</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%);">+int ast_channel_get_up_time(struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return (ast_channel_get_up_time_ms(chan) / 1000);</span><br><span> }</span><br><span> </span><br><span> static void deactivate_generator_nolock(struct ast_channel *chan)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11294">change 11294</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/c/asterisk/+/11294"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: If95f1a7d8c4acbac740037de0c6e3109ff6620b1 </div>
<div style="display:none"> Gerrit-Change-Number: 11294 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Antoni Goldstein <action@gdevel.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </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>
<div style="display:none"> Gerrit-MessageType: merged </div>