diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index a616738..08c5021 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -664,6 +664,7 @@ struct ast_vm_user { int imapversion; /*!< If configuration changes, use the new values */ #endif double volgain; /*!< Volume gain for voicemails sent via email */ + double volheadroom; /*!< Volume headroom for voicemails sent via email */ AST_LIST_ENTRY(ast_vm_user) list; }; @@ -793,6 +794,7 @@ static char externnotify[160]; static struct ast_smdi_interface *smdi_iface = NULL; static char vmfmts[80]; static double volgain; +static double volheadroom; static int vmminsecs; static int vmmaxsecs; static int maxgreet; @@ -1021,6 +1023,7 @@ static void populate_defaults(struct ast_vm_user *vmu) vmu->maxdeletedmsg = maxdeletedmsg; } vmu->volgain = volgain; + vmu->volheadroom = volheadroom; vmu->emailsubject = NULL; vmu->emailbody = NULL; #ifdef IMAP_STORAGE @@ -1146,6 +1149,8 @@ static void apply_option(struct ast_vm_user *vmu, const char *var, const char *v } } else if (!strcasecmp(var, "volgain")) { sscanf(value, "%30lf", &vmu->volgain); + } else if (!strcasecmp(var, "volheadroom")) { + sscanf(value, "%30lf", &vmu->volheadroom); } else if (!strcasecmp(var, "passwordlocation")) { if (!strcasecmp(value, "spooldir")) { vmu->passwordlocation = OPT_PWLOC_SPOOLDIR; @@ -4756,6 +4761,24 @@ static int add_email_attachment(FILE *p, struct ast_vm_user *vmu, char *format, ast_log(LOG_WARNING, "Voicemail attachment will have no volume gain.\n"); } } + } else if (vmu->volheadroom < -.001 || vmu->volheadroom > .001) { + create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp"); + snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir); + tmpfd = mkstemp(newtmp); + chmod(newtmp, VOICEMAIL_FILE_MODE & ~my_umask); + ast_debug(3, "newtmp: %s\n", newtmp); + if (tmpfd > -1) { + int soxstatus; + snprintf(tmpcmd, sizeof(tmpcmd), "sox %s.%s %s.%s gain -n %.4f", attach, format, newtmp, format, vmu->volheadroom); + if ((soxstatus = ast_safe_system(tmpcmd)) == 0) { + attach = newtmp; + ast_debug(3, "VOLHEADROOM: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volheadroom, mailbox); + } else { + ast_log(LOG_WARNING, "Sox failed to reencode %s.%s: %s (have you installed support for all sox file formats?)\n", attach, format, + soxstatus == 1 ? "Problem with command line options" : "An error occurred during file processing"); + ast_log(LOG_WARNING, "Voicemail attachment will have no volume headroom adjustment.\n"); + } + } } fprintf(p, "--%s" ENDL, bound); if (msgnum > -1) @@ -11465,6 +11488,7 @@ static int manager_list_voicemail_users(struct mansession *s, const struct messa "AttachmentFormat: %s\r\n" "DeleteMessage: %s\r\n" "VolumeGain: %.2f\r\n" + "VolumeHeadroom: %.2f\r\n" "CanReview: %s\r\n" "CallOperator: %s\r\n" "MaxMessageCount: %d\r\n" @@ -11496,6 +11520,7 @@ static int manager_list_voicemail_users(struct mansession *s, const struct messa vmu->attachfmt, ast_test_flag(vmu, VM_DELETE) ? "Yes" : "No", vmu->volgain, + vmu->volheadroom, ast_test_flag(vmu, VM_REVIEW) ? "Yes" : "No", ast_test_flag(vmu, VM_OPERATOR) ? "Yes" : "No", vmu->maxmsg, @@ -11659,6 +11684,10 @@ static int load_config(int reload) if ((val = ast_variable_retrieve(cfg, "general", "volgain"))) sscanf(val, "%30lf", &volgain); + volheadroom = 0.0; + if ((val = ast_variable_retrieve(cfg, "general", "volheadroom"))) + sscanf(val, "%30lf", &volheadroom); + #ifdef ODBC_STORAGE strcpy(odbc_database, "asterisk"); if ((val = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {