From 1eabb1cfb5a737476c178de880bd6e0b27c78ab4 Mon Sep 17 00:00:00 2001 From: markster Date: Sat, 26 Apr 2003 16:06:23 +0000 Subject: Convert between MS and non-MS formats git-svn-id: http://svn.digium.com/svn/asterisk/trunk@915 f38db490-d61c-443f-a65b-d21fe96a405b --- formats/format_wav_gsm.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'formats/format_wav_gsm.c') diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c index fc6323b67..06275402f 100755 --- a/formats/format_wav_gsm.c +++ b/formats/format_wav_gsm.c @@ -520,6 +520,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f) int res; char msdata[66]; int len =0; + int alreadyms=0; if (f->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); return -1; @@ -528,29 +529,42 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f) ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass); return -1; } + if (!(f->datalen % 65)) + alreadyms = 1; while(len < f->datalen) { - if (fs->secondhalf) { - memcpy(fs->gsm + 33, f->data + len, 33); - conv66(fs->gsm, msdata); - if ((res = write(fs->fd, msdata, 65)) != 65) { + if (alreadyms) { + fs->secondhalf = 0; + if ((res = write(fs->fd, f->data + len, 65)) != 65) { ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno)); return -1; } fs->bytes += 65; update_header(fs->fd); + len += 65; } else { - /* Copy the data and do nothing */ - memcpy(fs->gsm, f->data + len, 33); + if (fs->secondhalf) { + memcpy(fs->gsm + 33, f->data + len, 33); + conv66(fs->gsm, msdata); + if ((res = write(fs->fd, msdata, 65)) != 65) { + ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno)); + return -1; + } + fs->bytes += 65; + update_header(fs->fd); + } else { + /* Copy the data and do nothing */ + memcpy(fs->gsm, f->data + len, 33); + } + fs->secondhalf = !fs->secondhalf; + len += 33; } - fs->secondhalf = !fs->secondhalf; - len += 33; } return 0; } static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence) { - off_t offset,distance,cur,min,max; + off_t offset=0,distance,cur,min,max; min = 52; cur = lseek(fs->fd, 0, SEEK_CUR); max = lseek(fs->fd, 0, SEEK_END); -- cgit v1.2.3