diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-06 22:11:43 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-02-06 22:11:43 +0000 |
commit | 8b1f06abb435a2aa00d7b5d1e8dd1588bf895483 (patch) | |
tree | 8220ad163713cb38240eb18c24be25aa88b28865 /formats/format_gsm.c | |
parent | 12b57158d66873fd353d3ae66662e205bd96debb (diff) |
Version 0.3.0 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@608 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats/format_gsm.c')
-rwxr-xr-x | formats/format_gsm.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 1ac981f7f..87bd91bc4 100755 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -151,6 +151,7 @@ static void gsm_close(struct ast_filestream *s) ast_log(LOG_WARNING, "Freeing a filestream we don't seem to own\n"); close(s->fd); free(s); + s = NULL; } static int ast_read_callback(void *data) @@ -165,7 +166,7 @@ static int ast_read_callback(void *data) s->fr.frametype = AST_FRAME_VOICE; s->fr.subclass = AST_FORMAT_GSM; s->fr.offset = AST_FRIENDLY_OFFSET; - s->fr.timelen = 20; + s->fr.samples = 160; s->fr.datalen = 33; s->fr.mallocd = 0; s->fr.data = s->gsm; @@ -216,6 +217,11 @@ static int gsm_apply(struct ast_channel *c, struct ast_filestream *s) { /* Select our owner for this stream, and get the ball rolling. */ s->owner = c; + return 0; +} + +static int gsm_play(struct ast_filestream *s) +{ ast_read_callback(s); return 0; } @@ -242,6 +248,38 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f) return 0; } +static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence) +{ + off_t offset,min,cur,max,distance; + + min = 0; + cur = lseek(fs->fd, 0, SEEK_CUR); + max = lseek(fs->fd, 0, SEEK_END); + /* have to fudge to frame here, so not fully to sample */ + distance = (sample_offset/160) * 33; + if(whence == SEEK_SET) + offset = distance; + if(whence == SEEK_CUR) + offset = distance + cur; + if(whence == SEEK_END) + offset = max - distance; + offset = (offset > max)?max:offset; + offset = (offset < min)?min:offset; + return lseek(fs->fd, offset, SEEK_SET); +} + +static int gsm_trunc(struct ast_filestream *fs) +{ + return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR)); +} + +static long gsm_tell(struct ast_filestream *fs) +{ + off_t offset; + offset = lseek(fs->fd, 0, SEEK_CUR); + return (offset/33)*160; +} + static char *gsm_getcomment(struct ast_filestream *s) { return NULL; @@ -253,7 +291,11 @@ int load_module() gsm_open, gsm_rewrite, gsm_apply, + gsm_play, gsm_write, + gsm_seek, + gsm_trunc, + gsm_tell, gsm_read, gsm_close, gsm_getcomment); |