summaryrefslogtreecommitdiff
path: root/formats/format_pcm.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2003-02-06 22:11:43 +0000
committerMark Spencer <markster@digium.com>2003-02-06 22:11:43 +0000
commit8ce222478dd4a01ef0704468b28118baa87338b9 (patch)
tree8220ad163713cb38240eb18c24be25aa88b28865 /formats/format_pcm.c
parent1bd973bfce6aa7dae27d46029eef9b6f9991f0a1 (diff)
Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@608 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'formats/format_pcm.c')
-rwxr-xr-xformats/format_pcm.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 8576f6995..28daed68f 100755
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -149,6 +149,7 @@ static void pcm_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)
@@ -171,9 +172,9 @@ static int ast_read_callback(void *data)
s->owner->streamid = -1;
return 0;
}
- s->fr.timelen = res / 8;
+ s->fr.samples = res;
s->fr.datalen = res;
- delay = s->fr.timelen;
+ delay = s->fr.samples/8;
/* Lastly, process the frame */
if (ast_write(s->owner, &s->fr)) {
ast_log(LOG_WARNING, "Failed to write frame\n");
@@ -215,6 +216,11 @@ static int pcm_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 pcm_play(struct ast_filestream *s)
+{
ast_read_callback(s);
return 0;
}
@@ -237,6 +243,36 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
return 0;
}
+static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
+{
+ off_t offset,min,cur,max;
+
+ min = 0;
+ cur = lseek(fs->fd, 0, SEEK_CUR);
+ max = lseek(fs->fd, 0, SEEK_END);
+ if(whence == SEEK_SET)
+ offset = sample_offset;
+ if(whence == SEEK_CUR)
+ offset = sample_offset + cur;
+ if(whence == SEEK_END)
+ offset = max - sample_offset;
+ offset = (offset > max)?max:offset;
+ offset = (offset < min)?min:offset;
+ return lseek(fs->fd, offset, SEEK_SET);
+}
+
+static int pcm_trunc(struct ast_filestream *fs)
+{
+ return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+}
+
+static long pcm_tell(struct ast_filestream *fs)
+{
+ off_t offset;
+ offset = lseek(fs->fd, 0, SEEK_CUR);
+ return offset;
+}
+
static char *pcm_getcomment(struct ast_filestream *s)
{
return NULL;
@@ -248,7 +284,11 @@ int load_module()
pcm_open,
pcm_rewrite,
pcm_apply,
+ pcm_play,
pcm_write,
+ pcm_seek,
+ pcm_trunc,
+ pcm_tell,
pcm_read,
pcm_close,
pcm_getcomment);