]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_record: Add RECORD_TIME output variable.
authorNaveen Albert <asterisk@phreaknet.org>
Mon, 22 Jan 2024 12:23:47 +0000 (07:23 -0500)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Tue, 30 Apr 2024 15:25:44 +0000 (15:25 +0000)
This adds the RECORD_TIME variable to Record(),
which is set to the recording duration before
the application returns.

Resolves: #548

UpgradeNote: The RECORD_TIME variable now contains
the duration of Record() recordings in milliseconds.

apps/app_record.c

index 93249e45b7857a379361bf0e0ca1f3bd3a2bf8f5..57a5297b093dc77bcba27bc1ff17aebe4bf37dfb 100644 (file)
                                        <value name="HANGUP">The channel was hung up.</value>
                                        <value name="ERROR">An unrecoverable error occurred, which resulted in a WARNING to the logs.</value>
                                </variable>
+                               <variable name="RECORD_TIME">
+                                       <para>Will be set to the duration of the recording, in milliseconds.</para>
+                                       <para>If the recording fails for whatever reason, this will still be set to 0.</para>
+                               </variable>
                        </variablelist>
                </description>
        </application>
@@ -251,6 +255,9 @@ static int record_exec(struct ast_channel *chan, const char *data)
        int ms;
        struct timeval start;
        const char *status_response = "ERROR";
+       char durationbuf[20];
+
+       pbx_builtin_setvar_helper(chan, "RECORD_TIME", "0"); /* Reset, in case already set */
 
        /* The next few lines of code parse out the filename and header from the input string */
        if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
@@ -514,6 +521,9 @@ static int record_exec(struct ast_channel *chan, const char *data)
                ast_channel_stop_silence_generator(chan, silgen);
 
 out:
+       snprintf(durationbuf, sizeof(durationbuf), "%ld", ast_tvdiff_ms(ast_tvnow(), start));
+       pbx_builtin_setvar_helper(chan, "RECORD_TIME", durationbuf);
+
        if ((silence > 0) && rfmt) {
                res = ast_set_read_format(chan, rfmt);
                if (res) {