Merged revisions 337120 via svnmerge from
authorMatthew Jordan <mjordan@digium.com>
Tue, 20 Sep 2011 23:02:25 +0000 (23:02 +0000)
committerMatthew Jordan <mjordan@digium.com>
Tue, 20 Sep 2011 23:02:25 +0000 (23:02 +0000)
https://origsvn.digium.com/svn/asterisk/branches/10

................
  r337120 | mjordan | 2011-09-20 17:49:36 -0500 (Tue, 20 Sep 2011) | 28 lines

  Merged revisions 337118 via svnmerge from
  https://origsvn.digium.com/svn/asterisk/branches/1.8

  ........
    r337118 | mjordan | 2011-09-20 17:38:54 -0500 (Tue, 20 Sep 2011) | 21 lines

    Fix for incorrect voicemail duration in external notifications

    This patch fixes an issue where the voicemail duration was being reported
    with a duration significantly less than the actual sound file duration.
    Voicemails that contained mostly silence were reporting the duration of
    only the sound in the file, as opposed to the duration of the file with
    the silence.  This patch fixes this by having two durations reported in
    the __ast_play_and_record family of functions - the sound_duration and the
    actual duration of the file.  The sound_duration, which is optional, now
    reports the duration of the sound in the file, while the actual full duration
    of the file is reported in the duration parameter.  This allows the voicemail
    applications to use the sound_duration for minimum duration checking, while
    reporting the full duration to external parties if the voicemail is kept.

    (issue ASTERISK-2234)
    (closes issue ASTERISK-16981)
    Reported by: Mary Ciuciu, Byron Clark, Brad House, Karsten Wemheuer, KevinH
    Tested by: Matt Jordan

    Review: https://reviewboard.asterisk.org/r/1443
  ........
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@337124 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_confbridge.c
apps/app_dial.c
apps/app_followme.c
apps/app_meetme.c
apps/app_minivm.c
apps/app_voicemail.c
include/asterisk/app.h
main/app.c

index ed00816..42c0a4c 100644 (file)
@@ -1283,6 +1283,7 @@ static int conf_rec_name(struct conference_bridge_user *user, const char *conf_n
                10,
                "sln",
                &duration,
+               NULL,
                ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE),
                0,
                NULL);
index de8deb6..6bea10f 100644 (file)
@@ -1772,7 +1772,7 @@ static int setup_privacy_args(struct privacy_args *pa,
                        */
                        silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
                        ast_answer(chan);
-                       res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, silencethreshold, 2000, 0);  /* NOTE: I've reduced the total time to 4 sec */
+                       res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0);  /* NOTE: I've reduced the total time to 4 sec */
                                                                        /* don't think we'll need a lock removed, we took care of
                                                                           conflicts by naming the pa.privintro file */
                        if (res == -1) {
index a72ef30..86f9914 100644 (file)
@@ -1123,7 +1123,7 @@ static int app_exec(struct ast_channel *chan, const char *data)
                        ast_stream_and_wait(chan, targs.statusprompt, "");
 
                if (ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_RECORDNAME)) 
-                       if (ast_play_and_record(chan, "vm-rec-name", namerecloc, 5, "sln", &duration, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL) < 0)
+                       if (ast_play_and_record(chan, "vm-rec-name", namerecloc, 5, "sln", &duration, NULL, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL) < 0)
                                goto outrun;
 
                if (!ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_DISABLEHOLDPROMPT)) {
index b9b46cd..d6a80b2 100644 (file)
@@ -2548,7 +2548,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struc
 
                res = 0;
                if (ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW) && !ast_fileexists(user->namerecloc, NULL, NULL))
-                       res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL);
+                       res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL);
                else if (ast_test_flag64(confflags, CONFFLAG_INTROUSER) && !ast_fileexists(user->namerecloc, NULL, NULL))
                        res = ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
                if (res == -1)
index 3445b7e..993a5a3 100644 (file)
@@ -1603,7 +1603,7 @@ static int vm_delete(char *file)
 /*!\internal
  * \brief Record voicemail message & let caller review or re-record it, or set options if applicable */
 static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt,
-                             int outsidecaller, struct minivm_account *vmu, int *duration, const char *unlockdir,
+                             int outsidecaller, struct minivm_account *vmu, int *duration, int *sound_duration, const char *unlockdir,
                              signed char record_gain)
 {
        int cmd = 0;
@@ -1653,7 +1653,7 @@ static int play_record_review(struct ast_channel *chan, char *playfile, char *re
                                ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
                        if (ast_test_flag(vmu, MVM_OPERATOR))
                                canceldtmf = "0";
-                       cmd = ast_play_and_record_full(chan, playfile, recordfile, maxtime, fmt, duration, global_silencethreshold, global_maxsilence, unlockdir, acceptdtmf, canceldtmf);
+                       cmd = ast_play_and_record_full(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, global_silencethreshold, global_maxsilence, unlockdir, acceptdtmf, canceldtmf);
                        if (record_gain)
                                ast_channel_setoption(chan, AST_OPTION_RXGAIN, &zero_gain, sizeof(zero_gain), 0);
                        if (cmd == -1) /* User has hung up, no options to give */
@@ -1842,6 +1842,7 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav
        FILE *txt;
        int res = 0, txtdes;
        int duration = 0;
+       int sound_duration = 0;
        char date[256];
        char tmpdir[PATH_MAX];
        char ext_context[256] = "";
@@ -1917,7 +1918,7 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav
        /* Store information */
        ast_debug(2, "Open file for metadata: %s\n", tmptxtfile);
 
-       res = play_record_review(chan, NULL, tmptxtfile, global_vmmaxmessage, fmt, 1, vmu, &duration, NULL, options->record_gain);
+       res = play_record_review(chan, NULL, tmptxtfile, global_vmmaxmessage, fmt, 1, vmu, &duration, &sound_duration, NULL, options->record_gain);
 
        txt = fdopen(txtdes, "w+");
        if (!txt) {
@@ -1958,8 +1959,8 @@ static int leave_voicemail(struct ast_channel *chan, char *username, struct leav
                        ast_mutex_unlock(&minivmloglock);
                }
 
-               if (duration < global_vmminmessage) {
-                       ast_verb(3, "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, global_vmminmessage);
+               if (sound_duration < global_vmminmessage) {
+                       ast_verb(3, "Recording was %d seconds long but needs to be at least %d - abandoning\n", sound_duration, global_vmminmessage);
                        fclose(txt);
                        ast_filedelete(tmptxtfile, NULL);
                        unlink(tmptxtfile);
@@ -2536,7 +2537,7 @@ static int minivm_accmess_exec(struct ast_channel *chan, const char *data)
        }
        snprintf(filename,sizeof(filename), "%s%s/%s/%s", MVM_SPOOL_DIR, vmu->domain, vmu->username, message);
        /* Maybe we should check the result of play_record_review ? */
-       play_record_review(chan, prompt, filename, global_maxgreet, default_vmformat, 0, vmu, &duration, NULL, FALSE);
+       play_record_review(chan, prompt, filename, global_maxgreet, default_vmformat, 0, vmu, &duration, NULL, NULL, FALSE);
 
        ast_debug(1, "Recorded new %s message in %s (duration %d)\n", message, filename, duration);
 
index d89d581..487d0e0 100644 (file)
@@ -905,7 +905,7 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box);
 static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg, int option, signed char record_gain);
 static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context);
 static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime,
-                       char *fmt, int outsidecaller, struct ast_vm_user *vmu, int *duration, const char *unlockdir,
+                       char *fmt, int outsidecaller, struct ast_vm_user *vmu, int *duration, int *sound_duration, const char *unlockdir,
                        signed char record_gain, struct vm_state *vms, char *flag);
 static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, char *fmtc, signed char record_gain);
 static int vm_play_folder_name(struct ast_channel *chan, char *mbox);
@@ -5577,6 +5577,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
        int res = 0;
        int msgnum;
        int duration = 0;
+       int sound_duration = 0;
        int ausemacro = 0;
        int ousemacro = 0;
        int ouseexten = 0;
@@ -5964,13 +5965,13 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
                        res = ast_streamfile(chan, "vm-mailboxfull", chan->language);
                        goto leave_vm_out;
                }
-               res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, NULL, options->record_gain, vms, flag);
+               res = play_record_review(chan, NULL, tmptxtfile, vmu->maxsecs, fmt, 1, vmu, &duration, &sound_duration, NULL, options->record_gain, vms, flag);
 
                if (txt) {
                        fprintf(txt, "flag=%s\n", flag);
-                       if (duration < vmu->minsecs) {
+                       if (sound_duration < vmu->minsecs) {
                                fclose(txt);
-                               ast_verb(3, "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmu->minsecs);
+                               ast_verb(3, "Recording was %d seconds long but needs to be at least %d - abandoning\n", sound_duration, vmu->minsecs);
                                ast_filedelete(tmptxtfile, NULL);
                                unlink(tmptxtfile);
                                if (ast_check_realtime("voicemail_data")) {
@@ -6092,7 +6093,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
                } else if (res > 0 && res != 't')
                        res = 0;
 
-               if (duration < vmu->minsecs)
+               if (sound_duration < vmu->minsecs)
                        /* XXX We should really give a prompt too short/option start again, with leave_vm_out called only after a timeout XXX */
                        pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
                else
@@ -6870,7 +6871,7 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu,
                        strncat(vms->introfn, "intro", sizeof(vms->introfn));
                        res = ast_play_and_wait(chan, INTRO);
                        res = ast_play_and_wait(chan, "beep");
-                       res = play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, record_gain, vms, flag);
+                       res = play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, NULL, record_gain, vms, flag);
                        cmd = 't';
 #else
 
@@ -6903,7 +6904,7 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu,
                        if (record_gain)
                                ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
 
-                       cmd = ast_play_and_prepend(chan, NULL, msgfile, 0, vm_fmts, &prepend_duration, 1, silencethreshold, maxsilence);
+                       cmd = ast_play_and_prepend(chan, NULL, msgfile, 0, vm_fmts, &prepend_duration, NULL, 1, silencethreshold, maxsilence);
 
                        if (cmd == 'S') { /* If we timed out, tell the user it didn't work properly and clean up the files */
                                ast_stream_and_wait(chan, vm_pls_try_again, ""); /* this might be removed if a proper vm_prepend_timeout is ever recorded */
@@ -9237,7 +9238,7 @@ static int vm_newuser(struct ast_channel *chan, struct ast_vm_user *vmu, struct
        if (ast_test_flag(vmu, VM_FORCENAME)) {
                snprintf(prefile, sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
                if (ast_fileexists(prefile, NULL, NULL) < 1) {
-                       cmd = play_record_review(chan, "vm-rec-name", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-name", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        if (cmd < 0 || cmd == 't' || cmd == '#')
                                return cmd;
                }
@@ -9247,14 +9248,14 @@ static int vm_newuser(struct ast_channel *chan, struct ast_vm_user *vmu, struct
        if (ast_test_flag(vmu, VM_FORCEGREET)) {
                snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
                if (ast_fileexists(prefile, NULL, NULL) < 1) {
-                       cmd = play_record_review(chan, "vm-rec-unv", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-unv", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        if (cmd < 0 || cmd == 't' || cmd == '#')
                                return cmd;
                }
 
                snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
                if (ast_fileexists(prefile, NULL, NULL) < 1) {
-                       cmd = play_record_review(chan, "vm-rec-busy", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-busy", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        if (cmd < 0 || cmd == 't' || cmd == '#')
                                return cmd;
                }
@@ -9289,15 +9290,15 @@ static int vm_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct
                switch (cmd) {
                case '1': /* Record your unavailable message */
                        snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
-                       cmd = play_record_review(chan, "vm-rec-unv", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-unv", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        break;
                case '2':  /* Record your busy message */
                        snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
-                       cmd = play_record_review(chan, "vm-rec-busy", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-busy", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        break;
                case '3': /* Record greeting */
                        snprintf(prefile, sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
-                       cmd = play_record_review(chan, "vm-rec-name", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-name", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        break;
                case '4':  /* manage the temporary greeting */
                        cmd = vm_tempgreeting(chan, vmu, vms, fmtc, record_gain);
@@ -9431,12 +9432,12 @@ static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, st
                        retries = 0;
                RETRIEVE(prefile, -1, vmu->mailbox, vmu->context);
                if (ast_fileexists(prefile, NULL, NULL) <= 0) {
-                       play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                       play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                        cmd = 't';      
                } else {
                        switch (cmd) {
                        case '1':
-                               cmd = play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain, vms, NULL);
+                               cmd = play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
                                break;
                        case '2':
                                DELETE(prefile, -1, prefile, vmu);
@@ -13252,7 +13253,7 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, s
 }
 
 static int play_record_review(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt,
-                       int outsidecaller, struct ast_vm_user *vmu, int *duration, const char *unlockdir,
+                       int outsidecaller, struct ast_vm_user *vmu, int *duration, int *sound_duration, const char *unlockdir,
                        signed char record_gain, struct vm_state *vms, char *flag)
 {
        /* Record message & let caller review or re-record it, or set options if applicable */
@@ -13327,7 +13328,7 @@ static int play_record_review(struct ast_channel *chan, char *playfile, char *re
                                ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
                        if (ast_test_flag(vmu, VM_OPERATOR))
                                canceldtmf = "0";
-                       cmd = ast_play_and_record_full(chan, playfile, tempfile, maxtime, fmt, duration, silencethreshold, maxsilence, unlockdir, acceptdtmf, canceldtmf);
+                       cmd = ast_play_and_record_full(chan, playfile, tempfile, maxtime, fmt, duration, sound_duration, silencethreshold, maxsilence, unlockdir, acceptdtmf, canceldtmf);
                        if (strchr(canceldtmf, cmd)) {
                        /* need this flag here to distinguish between pressing '0' during message recording or after */
                                canceleddtmf = 1;
@@ -13347,13 +13348,13 @@ static int play_record_review(struct ast_channel *chan, char *playfile, char *re
                        } else if (cmd == '*') {
                                break;
 #if 0
-                       } else if (vmu->review && (*duration < 5)) {
+                       } else if (vmu->review && sound_duration && (*sound_duration < 5)) {
                                /* Message is too short */
                                ast_verb(3, "Message too short\n");
                                cmd = ast_play_and_wait(chan, "vm-tooshort");
                                cmd = ast_filedelete(tempfile, NULL);
                                break;
-                       } else if (vmu->review && (cmd == 2 && *duration < (maxsilence + 3))) {
+                       } else if (vmu->review && (cmd == 2 && sound_duration && *sound_duration < (maxsilence + 3))) {
                                /* Message is all silence */
                                ast_verb(3, "Nothing recorded\n");
                                cmd = ast_filedelete(tempfile, NULL);
index fe74e0b..87f7c80 100644 (file)
@@ -280,6 +280,7 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn);
  * \param maxtime_sec Longest possible message length in seconds
  * \param fmt string containing all formats to be recorded delimited by '|'
  * \param duration pointer to integer for storing length of the recording
+ * \param sound_duration pointer to integer for storing length of the recording minus all silence
  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
  * \param maxsilence_ms Length of time in milliseconds which will trigger a timeout from silence, -1 for default
  * \param path Optional filesystem path to unlock
@@ -291,7 +292,7 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn);
  * \retval 't' Recording ended from the message exceeding the maximum duration
  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
  */
-int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf);
+int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf);
 
 /*!
  * \brief Record a file based on input from a channel. Use default accept and cancel DTMF.
@@ -303,6 +304,7 @@ int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, con
  * \param maxtime_sec Longest possible message length in seconds
  * \param fmt string containing all formats to be recorded delimited by '|'
  * \param duration pointer to integer for storing length of the recording
+ * \param sound_duration pointer to integer for storing length of the recording minus all silence
  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
  * \param maxsilence_ms length of time in milliseconds which will trigger a timeout from silence, -1 for default
  * \param path Optional filesystem path to unlock
@@ -312,7 +314,7 @@ int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, con
  * \retval 't' Recording ended from the message exceeding the maximum duration
  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
  */
-int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path);
+int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path);
 
 /*!
  * \brief Record a file based on input frm a channel. Recording is performed in 'prepend' mode which works a little differently from normal recordings
@@ -324,6 +326,7 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
  * \param maxtime_sec Longest possible message length in seconds
  * \param fmt string containing all formats to be recorded delimited by '|'
  * \param duration pointer to integer for storing length of the recording
+ * \param sound_duration pointer to integer for storing length of the recording minus all silence
  * \param beep whether to play a beep to prompt the recording
  * \param silencethreshold tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
  * \param maxsilence_ms length of time in milliseconds which will trigger a timeout from silence, -1 for default.
@@ -332,7 +335,7 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch
  * \retval 'S' Recording ended from silence timeout
  * \retval 't' Recording either exceeded maximum duration or the call was ended via DTMF
  */
-int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms);
+int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence_ms);
 
 enum ast_getdata_result {
        AST_GETDATA_FAILED = -1,
index a48935e..367a783 100644 (file)
@@ -721,6 +721,7 @@ static int global_maxsilence = 0;
  * \param maxtime Maximum length of recording (in seconds).
  * \param fmt Format(s) to record message in. Multiple formats may be specified by separating them with a '|'.
  * \param duration Where to store actual length of the recorded message (in milliseconds).
+ * \param sound_duration Where to store the length of the recorded message (in milliseconds), minus any silence
  * \param beep Whether to play a beep before starting to record.
  * \param silencethreshold
  * \param maxsilence Length of silence that will end a recording (in milliseconds).
@@ -735,7 +736,7 @@ static int global_maxsilence = 0;
  * \retval 't' Recording ended from the message exceeding the maximum duration, or via DTMF in prepend mode
  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
  */
-static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound)
+static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound)
 {
        int d = 0;
        char *fmts;
@@ -956,6 +957,9 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
         * closed (which would create a resource leak).
         */
        *duration = others[0] ? ast_tellstream(others[0]) / 8000 : 0;
+       if (sound_duration) {
+               *sound_duration = *duration;
+       }
 
        if (!prepend) {
                /* Reduce duration by a total silence amount */
@@ -963,12 +967,23 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
                        totalsilence += dspsilence;
                }
 
-               if (totalsilence > 0) {
-                       *duration -= (totalsilence - 200) / 1000;
+               if (sound_duration) {
+                       if (totalsilence > 0) {
+                               *sound_duration -= (totalsilence - 200) / 1000;
+                       }
+                       if (*sound_duration < 0) {
+                               *sound_duration = 0;
+                       }
                }
+
+               if (dspsilence > 0) {
+                       *duration -= (dspsilence - 200) / 1000;
+               }
+
                if (*duration < 0) {
                        *duration = 0;
                }
+
                for (x = 0; x < fmtcnt; x++) {
                        if (!others[x]) {
                                break;
@@ -1029,19 +1044,19 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
 static const char default_acceptdtmf[] = "#";
 static const char default_canceldtmf[] = "";
 
-int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf)
+int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf)
 {
-       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf), 0);
+       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf), 0);
 }
 
-int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path)
+int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path)
 {
-       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0);
+       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0);
 }
 
-int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence)
+int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence)
 {
-       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1);
+       return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1);
 }
 
 /* Channel group core functions */
@@ -1578,7 +1593,7 @@ int ast_record_review(struct ast_channel *chan, const char *playfile, const char
                        /* Record */
                        ast_verb(3, "R%secording\n", recorded == 1 ? "e-r" : "");
                        recorded = 1;
-                       if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path)) == -1) {
+                       if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) {
                                /* User has hung up, no options to give */
                                return cmd;
                        }