From 662b687dbe86ad62d1c6bea5a21560857a8a0a63 Mon Sep 17 00:00:00 2001 From: Scott Griepentrog Date: Tue, 16 Sep 2014 16:33:53 +0000 Subject: [PATCH] Voicemail: get correct duration when copying file to vm Changes made during format improvements resulted in the recording to voicemail option 'm' of the MixMonitor app writing a zero length duration in the msgXXXX.txt file. This change introduces a new function ast_ratestream(), which provides the sample rate of the format associated with the stream, and updates the app_voicemail function for ast_app_copy_recording_to_vm to calculate the right duration. Review: https://reviewboard.asterisk.org/r/3996/ ASTERISK-24328 #close ........ Merged revisions 423192 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@423193 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_voicemail.c | 14 +++++--------- include/asterisk/file.h | 7 +++++++ main/file.c | 5 +++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index fdfbf22551..45f9ebfea5 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -6130,15 +6130,11 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata) if ((recording_fs = ast_readfile(recdata->recording_file, recdata->recording_ext, NULL, 0, 0, VOICEMAIL_DIR_MODE))) { if (!ast_seekstream(recording_fs, 0, SEEK_END)) { long framelength = ast_tellstream(recording_fs); - struct ast_format *result; - /* XXX This use of ast_getformatbyname seems incorrect here. The file extension does not necessarily correspond - * to the name of the format. For instance, if "raw" were passed in, I don't think ast_getformatbyname would - * find the slinear format - */ - result = ast_format_cache_get(recdata->recording_ext); - if (result) { - duration = (int) (framelength / ast_format_get_sample_rate(result)); - ao2_ref(result, -1); + int sample_rate = ast_ratestream(recording_fs); + if (sample_rate) { + duration = (int) (framelength / sample_rate); + } else { + ast_log(LOG_ERROR,"Unable to determine sample rate of recording %s\n", recdata->recording_file); } } } diff --git a/include/asterisk/file.h b/include/asterisk/file.h index 3d8d2c97c3..c71866ead5 100644 --- a/include/asterisk/file.h +++ b/include/asterisk/file.h @@ -350,6 +350,13 @@ int ast_stream_rewind(struct ast_filestream *fs, off_t ms); */ off_t ast_tellstream(struct ast_filestream *fs); +/*! + * \brief Return the sample rate of the stream's format + * \param fs fs to act on + * \return sample rate in Hz + */ +int ast_ratestream(struct ast_filestream *fs); + /*! * \brief Read a frame from a filestream * \param s ast_filestream to act on diff --git a/main/file.c b/main/file.c index 393832cdd3..1d3755ac28 100644 --- a/main/file.c +++ b/main/file.c @@ -1026,6 +1026,11 @@ off_t ast_tellstream(struct ast_filestream *fs) return fs->fmt->tell(fs); } +int ast_ratestream(struct ast_filestream *fs) +{ + return ast_format_get_sample_rate(fs->fmt->format); +} + int ast_stream_fastforward(struct ast_filestream *fs, off_t ms) { return ast_seekstream(fs, ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);