summaryrefslogtreecommitdiff
path: root/formats
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2013-08-08 18:40:15 +0000
committerMatthew Jordan <mjordan@digium.com>2013-08-08 18:40:15 +0000
commit16fd65bb73b3cac8df5fc3fe9836b34bfd1fd541 (patch)
tree85da2a702aceb401df89a9f196a18e4ba7bd5d19 /formats
parent73b3c70a5fbd3665e428f26b64b0549c890e1955 (diff)
Improve disk writes for wav49 format
Writing to a file in the wav49 format performs rather inefficiently. The procedure is approximately: (1) Write GSM frame to the end of the file (2) Seek to the end of the file (3) Seek to the header (4) Update the file size (5) Seek (again) to the end of the file (6) Repeat This pattern negates any attempt to use the stdio buffering setup in ast_writefile. It also results in many small writes that require a seek going to the disk each second which translates to poor disk performance on certain file systems, particularly when there are multiple wav49 files being written simultaneously. (closes issue ASTERISK-19595) Reported by: Byron Clark Tested by: Byron Clark patches: gsm_wav_only_update_header_on_close.patch uploaded by byronclark (License 6157) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396412 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'formats')
-rw-r--r--formats/format_wav_gsm.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index f08e9ce21..c8d83ff4c 100644
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -393,6 +393,17 @@ static int wav_rewrite(struct ast_filestream *s, const char *comment)
return 0;
}
+static void wav_close(struct ast_filestream *s)
+{
+ if (s->mode == O_RDONLY) {
+ return;
+ }
+
+ if (s->filename) {
+ update_header(s->f);
+ }
+}
+
static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
{
/* Send a frame from the file to the appropriate channel */
@@ -468,7 +479,6 @@ static int wav_write(struct ast_filestream *s, struct ast_frame *f)
ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
return -1;
}
- update_header(s->f); /* XXX inefficient! */
}
return 0;
}
@@ -560,6 +570,7 @@ static struct ast_format_def wav49_f = {
.trunc = wav_trunc,
.tell = wav_tell,
.read = wav_read,
+ .close = wav_close,
.buf_size = 2*GSM_FRAME_SIZE + AST_FRIENDLY_OFFSET,
.desc_size = sizeof(struct wavg_desc),
};