Skip to content
Snippets Groups Projects
Commit 21e9421c authored by Mark Spencer's avatar Mark Spencer
Browse files

Stop playing wav at end of data segment

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1029 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 166f1120
Branches
Tags
No related merge requests found
...@@ -48,6 +48,7 @@ struct ast_filestream { ...@@ -48,6 +48,7 @@ struct ast_filestream {
short buf[160]; short buf[160];
int foffset; int foffset;
int lasttimeout; int lasttimeout;
int maxlen;
struct timeval last; struct timeval last;
int adj; int adj;
struct ast_filestream *next; struct ast_filestream *next;
...@@ -185,12 +186,18 @@ static int check_header(int fd) ...@@ -185,12 +186,18 @@ static int check_header(int fd)
ast_log(LOG_WARNING, "Does not say data\n"); ast_log(LOG_WARNING, "Does not say data\n");
return -1; return -1;
} }
/* Ignore the data length */ /* Data has the actual length of data in it */
if (read(fd, &data, 4) != 4) { if (read(fd, &data, 4) != 4) {
ast_log(LOG_WARNING, "Read failed (data)\n"); ast_log(LOG_WARNING, "Read failed (data)\n");
return -1; return -1;
} }
return 0; #if 0
curpos = lseek(fd, 0, SEEK_CUR);
truelength = lseek(fd, 0, SEEK_END);
lseek(fd, curpos, SEEK_SET);
truelength -= curpos;
#endif
return ltohl(data);
} }
static int update_header(int fd) static int update_header(int fd)
...@@ -305,7 +312,7 @@ static struct ast_filestream *wav_open(int fd) ...@@ -305,7 +312,7 @@ static struct ast_filestream *wav_open(int fd)
struct ast_filestream *tmp; struct ast_filestream *tmp;
if ((tmp = malloc(sizeof(struct ast_filestream)))) { if ((tmp = malloc(sizeof(struct ast_filestream)))) {
memset(tmp, 0, sizeof(struct ast_filestream)); memset(tmp, 0, sizeof(struct ast_filestream));
if (check_header(fd)) { if ((tmp->maxlen = check_header(fd)) < 0) {
free(tmp); free(tmp);
return NULL; return NULL;
} }
...@@ -419,9 +426,17 @@ static int ast_read_callback(void *data) ...@@ -419,9 +426,17 @@ static int ast_read_callback(void *data)
int x; int x;
struct ast_filestream *s = data; struct ast_filestream *s = data;
short tmp[sizeof(s->buf) / 2]; short tmp[sizeof(s->buf) / 2];
int bytes = sizeof(tmp);
off_t here;
/* Send a frame from the file to the appropriate channel */ /* Send a frame from the file to the appropriate channel */
here = lseek(s->fd, 0, SEEK_CUR);
if ((s->maxlen - here) < bytes)
bytes = s->maxlen - here;
if (bytes < 0)
bytes = 0;
/* ast_log(LOG_DEBUG, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
if ( (res = read(s->fd, tmp, sizeof(tmp))) <= 0 ) { if ( (res = read(s->fd, tmp, bytes)) <= 0 ) {
if (res) { if (res) {
ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
} }
...@@ -550,7 +565,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f) ...@@ -550,7 +565,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence) static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
{ {
off_t min,max,cur; off_t min,max,cur;
long offset,samples; long offset=0,samples;
samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */ samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */
min = 44; /* wav header is 44 bytes */ min = 44; /* wav header is 44 bytes */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment