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);
}
}
}
*/
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
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);