From 733e7599bda2f225c7052d3e869a0f76a8ffd3e7 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 10 Oct 2007 16:36:13 +0000 Subject: [PATCH] added min_record_time to voicemail, will not send voicemail messages shorter than that. git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@517 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/voicemail/AnswerMachine.cpp | 19 ++++++++++-------- apps/voicemail/AnswerMachine.h | 1 + apps/voicemail/etc/voicemail.conf | 32 +++++++++++++++++++------------ core/AmAudio.cpp | 10 ++++++++++ core/AmAudio.h | 3 +++ 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/apps/voicemail/AnswerMachine.cpp b/apps/voicemail/AnswerMachine.cpp index 29034ab3..93c8d1a5 100644 --- a/apps/voicemail/AnswerMachine.cpp +++ b/apps/voicemail/AnswerMachine.cpp @@ -58,10 +58,10 @@ #define MOD_NAME "voicemail" #define DEFAULT_AUDIO_EXT "wav" -#define DEFAULT_MAIL_TMPL_PATH string("/usr/local/etc/sems") -#define DEFAULT_MAIL_TMPL string("default") -#define DEFAULT_MAIL_TMPL_EXT string("template") - +#define DEFAULT_MAIL_TMPL_PATH string("/usr/local/etc/sems") +#define DEFAULT_MAIL_TMPL string("default") +#define DEFAULT_MAIL_TMPL_EXT string("template") +#define DEFAULT_MIN_RECORD_TIME 0 #define RECORD_TIMER 99 EXPORT_SESSION_FACTORY(AnswerMachineFactory,MOD_NAME); @@ -75,6 +75,7 @@ string AnswerMachineFactory::RecFileExt; string AnswerMachineFactory::AnnouncePath; string AnswerMachineFactory::DefaultAnnounce; int AnswerMachineFactory::MaxRecordTime; +int AnswerMachineFactory::MinRecordTime = 0; AmDynInvokeFactory* AnswerMachineFactory::UserTimer=0; #ifdef USE_MYSQL @@ -383,6 +384,7 @@ int AnswerMachineFactory::onLoad() #endif MaxRecordTime = cfg.getParameterInt("max_record_time",DEFAULT_RECORD_TIME); + MinRecordTime = cfg.getParameterInt("min_record_time",DEFAULT_MIN_RECORD_TIME); RecFileExt = cfg.getParameter("rec_file_ext",DEFAULT_AUDIO_EXT); UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer"); @@ -635,10 +637,11 @@ void AnswerMachineDialog::onBye(const AmSipRequest& req) void AnswerMachineDialog::sendMailNotification() { - unsigned int rec_size = a_msg.getDataSize(); - DBG("recorded data size: %i\n",rec_size); - - if(!rec_size){ + int rec_length = a_msg.getLength(); + DBG("recorded file length: %i ms\n",rec_length); + + if(rec_length <= AnswerMachineFactory::MinRecordTime){ + DBG("recorded file too small. Not sending voicemail.\n"); unlink(msg_filename.c_str()); } else { diff --git a/apps/voicemail/AnswerMachine.h b/apps/voicemail/AnswerMachine.h index 778b918d..93e84da0 100644 --- a/apps/voicemail/AnswerMachine.h +++ b/apps/voicemail/AnswerMachine.h @@ -62,6 +62,7 @@ public: static string AnnouncePath; static string DefaultAnnounce; static int MaxRecordTime; + static int MinRecordTime; static AmDynInvokeFactory* UserTimer; #ifdef USE_MYSQL diff --git a/apps/voicemail/etc/voicemail.conf b/apps/voicemail/etc/voicemail.conf index 87cbb9db..1ad74bc4 100644 --- a/apps/voicemail/etc/voicemail.conf +++ b/apps/voicemail/etc/voicemail.conf @@ -1,24 +1,21 @@ -# These are needed if you keep audio and template files in file system: # if set, this overrides the email address, meaning that # the voicemail will always be sent to that address. # email_address = blub@mail.domain.net # -#CFGOPTION_SEMS_ANNOUNCEPATH +# These are needed if you keep audio and template files in file system: +# +# path from which announcements are played: announce_path=/usr/local/lib/sems/audio/voicemail/ -#ENDCFGOPTION - -#CFGOPTION_SEMS_ANNOUNCEMENT +# +# announcement played if no user/domain specific prompt found default_announce=default_en.wav -#ENDCFGOPTION - -#CFGOPTION_SEMS_TEMPLATEDIR +# +# path for email templates: email_template_path=/usr/local/etc/sems/ -#ENDCFGOPTION # These are needed if you keep audio and template files in MySQL database: - #mysql_host=localhost #mysql_user=sems #mysql_passwd=sems @@ -26,9 +23,20 @@ email_template_path=/usr/local/etc/sems/ # These are independent on where audio and template files are kept: -#CFGOPTION_SEMS_RECORDTIME +# +# maximum voicemail message length, in seconds. +# After the maximum time, the call is ended by SEMS. +# max_record_time=30 -#ENDCFGOPTION + +# +# optional: minimum voicemail message length, in milliseconds +# no voicemail is sent if the recorded message is shorter than +# or equal to the value set here. +# example - do not send voicemail shorter than 1.5s: +# min_record_time=1500 +# default: 0 +#min_record_time=0 # rec_file_ext : extension to recorded file, determines file # format (wav, mp3; need mp3 plugin loaded for mp3) diff --git a/core/AmAudio.cpp b/core/AmAudio.cpp index a3d3a656..526f4d65 100644 --- a/core/AmAudio.cpp +++ b/core/AmAudio.cpp @@ -735,6 +735,16 @@ int AmAudioFile::write(unsigned int user_ts, unsigned int size) return (!ferror(fp) ? s : -1); } +int AmAudioFile::getLength() +{ + if (!data_size || !fmt.get()) + return 0; + + return + fmt->bytes2samples(data_size) / + (fmt->rate/1000); +} + AmAudioFileFormat* AmAudioFile::fileName2Fmt(const string& name) { string ext = file_extension(name); diff --git a/core/AmAudio.h b/core/AmAudio.h index 0ae3793a..9dfe6710 100644 --- a/core/AmAudio.h +++ b/core/AmAudio.h @@ -415,6 +415,9 @@ public: /** Gets data size in the current file */ int getDataSize() { return data_size; } + /** Gets length of the current file in ms */ + int getLength(); + /** * @return MIME type corresponding to the audio file. */