diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-06-28 22:50:47 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-06-28 22:50:47 +0000 |
commit | 3a0233e8edb056a24609732411d306608ffccece (patch) | |
tree | 902d5085d33fe26d1e4423a993e2443df2c20aa1 /formats | |
parent | fd42183b7866425be9ddc6359cb6daea866fd066 (diff) |
Totally redo file formats
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1130 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats')
-rwxr-xr-x | formats/Makefile | 9 | ||||
-rwxr-xr-x | formats/format_g723.c | 8 | ||||
-rwxr-xr-x | formats/format_g729.c | 116 | ||||
-rwxr-xr-x | formats/format_gsm.c | 118 | ||||
-rwxr-xr-x | formats/format_mp3.c | 108 | ||||
-rwxr-xr-x | formats/format_pcm.c | 117 | ||||
-rwxr-xr-x | formats/format_pcm_alaw.c | 116 | ||||
-rwxr-xr-x | formats/format_vox.c | 114 | ||||
-rwxr-xr-x | formats/format_wav.c | 96 | ||||
-rwxr-xr-x | formats/format_wav_gsm.c | 119 |
10 files changed, 44 insertions, 877 deletions
diff --git a/formats/Makefile b/formats/Makefile index 885469463..540785b2d 100755 --- a/formats/Makefile +++ b/formats/Makefile @@ -11,9 +11,14 @@ # the GNU General Public License # -FORMAT_LIBS=format_g723.so format_wav.so format_mp3.so format_wav_gsm.so \ - format_gsm.so format_vox.so format_pcm.so format_g729.so format_pcm_alaw.so +FORMAT_LIBS=format_gsm.so format_wav.so format_mp3.so \ + format_wav_gsm.so format_vox.so format_pcm.so format_g729.so \ + format_pcm_alaw.so FORMAT_LIBS+=format_jpeg.so +# +# G723 simple frame is depricated +# +#FORMAT_LIBS+=format_g723.so GSMLIB=../codecs/gsm/lib/libgsm.a diff --git a/formats/format_g723.c b/formats/format_g723.c index 520aeb7ef..8ce2ec266 100755 --- a/formats/format_g723.c +++ b/formats/format_g723.c @@ -35,8 +35,6 @@ struct ast_filestream { void *reserved[AST_RESERVED_POINTERS]; /* This is what a filestream means to us */ int fd; /* Descriptor */ - u_int32_t lasttimeout; /* Last amount of timeout */ - struct ast_channel *owner; struct ast_filestream *next; struct ast_frame *fr; /* Frame representation of buf */ struct timeval orig; /* Original frame time */ @@ -44,7 +42,6 @@ struct ast_filestream { }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t g723_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -64,10 +61,7 @@ static struct ast_filestream *g723_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr = (struct ast_frame *)tmp->buf; tmp->fr->data = tmp->buf + sizeof(struct ast_frame); tmp->fr->frametype = AST_FRAME_VOICE; @@ -97,8 +91,6 @@ static struct ast_filestream *g723_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; tmp->owner = NULL; tmp->fr = NULL; diff --git a/formats/format_g729.c b/formats/format_g729.c index ee6f6ab50..a2336c94b 100755 --- a/formats/format_g729.c +++ b/formats/format_g729.c @@ -41,19 +41,13 @@ struct ast_filestream { weird MS format */ /* This is what a filestream means to us */ int fd; /* Descriptor */ - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char g729[20]; /* Two Real G729 Frames */ - int lasttimeout; - struct timeval last; - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t g729_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -74,17 +68,13 @@ static struct ast_filestream *g729_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->g729; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_G729A; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&g729_lock); ast_update_use_count(); @@ -105,11 +95,7 @@ static struct ast_filestream *g729_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&g729_lock); ast_update_use_count(); @@ -118,55 +104,24 @@ static struct ast_filestream *g729_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *g729_read(struct ast_filestream *s) -{ - return NULL; -} - static void g729_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (ast_pthread_mutex_lock(&g729_lock)) { ast_log(LOG_WARNING, "Unable to lock g729 list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&g729_lock); ast_update_use_count(); - if (!tmp) - 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) +static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; - int delay = 20; - struct ast_filestream *s = data; - struct timeval tv; /* Send a frame from the file to the appropriate channel */ - s->fr.frametype = AST_FRAME_VOICE; s->fr.subclass = AST_FORMAT_G729A; s->fr.offset = AST_FRIENDLY_OFFSET; @@ -177,57 +132,10 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, s->g729, 20)) != 20) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; - } - /* Lastly, process the frame */ - if (ast_write(s->owner, &s->fr)) { - ast_log(LOG_WARNING, "Failed to write frame\n"); - s->owner->streamid = -1; - return 0; + return NULL; } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; - } - return retval; -} - -static int g729_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 g729_play(struct ast_filestream *s) -{ - ast_read_callback(s); - return 0; + *whennext = s->fr.samples; + return &s->fr; } static int g729_write(struct ast_filestream *fs, struct ast_frame *f) @@ -299,8 +207,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_G729A, g729_open, g729_rewrite, - g729_apply, - g729_play, g729_write, g729_seek, g729_trunc, @@ -314,20 +220,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&g729_lock)) { - ast_log(LOG_WARNING, "Unable to lock g729 list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&g729_lock); return ast_format_unregister(name); } diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 0c36fde30..49d53df27 100755 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -43,19 +43,13 @@ struct ast_filestream { weird MS format */ /* This is what a filestream means to us */ int fd; /* Descriptor */ - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char gsm[66]; /* Two Real GSM Frames */ - int lasttimeout; - struct timeval last; - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t gsm_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -76,17 +70,13 @@ static struct ast_filestream *gsm_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->gsm; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_GSM; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&gsm_lock); ast_update_use_count(); @@ -107,11 +97,7 @@ static struct ast_filestream *gsm_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&gsm_lock); ast_update_use_count(); @@ -120,55 +106,22 @@ static struct ast_filestream *gsm_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *gsm_read(struct ast_filestream *s) -{ - return NULL; -} - static void gsm_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (ast_pthread_mutex_lock(&gsm_lock)) { ast_log(LOG_WARNING, "Unable to lock gsm list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&gsm_lock); ast_update_use_count(); - if (!tmp) - 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) +static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; - int delay = 20; - struct ast_filestream *s = data; - struct timeval tv; - /* Send a frame from the file to the appropriate channel */ - s->fr.frametype = AST_FRAME_VOICE; s->fr.subclass = AST_FORMAT_GSM; s->fr.offset = AST_FRIENDLY_OFFSET; @@ -179,57 +132,10 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, s->gsm, 33)) != 33) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; - } - /* Lastly, process the frame */ - if (ast_write(s->owner, &s->fr)) { - ast_log(LOG_WARNING, "Failed to write frame\n"); - s->owner->streamid = -1; - return 0; - } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; + return NULL; } - return retval; -} - -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; + *whennext = 160; + return &s->fr; } static int gsm_write(struct ast_filestream *fs, struct ast_frame *f) @@ -310,8 +216,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_GSM, gsm_open, gsm_rewrite, - gsm_apply, - gsm_play, gsm_write, gsm_seek, gsm_trunc, @@ -325,20 +229,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&gsm_lock)) { - ast_log(LOG_WARNING, "Unable to lock gsm list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&gsm_lock); return ast_format_unregister(name); } diff --git a/formats/format_mp3.c b/formats/format_mp3.c index e702e5563..7f6b6992c 100755 --- a/formats/format_mp3.c +++ b/formats/format_mp3.c @@ -34,14 +34,10 @@ struct ast_filestream { void *reserved[AST_RESERVED_POINTERS]; /* This is what a filestream means to us */ int fd; /* Descriptor */ - struct ast_channel *owner; - struct ast_filestream *next; struct ast_frame fr; /* Frame representation of buf */ char offset[AST_FRIENDLY_OFFSET]; unsigned char buf[MAX_FRAME_SIZE * 2]; - int lasttimeout; int pos; - int adj; struct timeval last; }; @@ -68,14 +64,9 @@ static struct ast_filestream *mp3_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; tmp->last.tv_usec = 0; tmp->last.tv_sec = 0; - tmp->adj = 0; glistcnt++; ast_pthread_mutex_unlock(&mp3_lock); ast_update_use_count(); @@ -95,10 +86,7 @@ static struct ast_filestream *mp3_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; glistcnt++; ast_pthread_mutex_unlock(&mp3_lock); ast_update_use_count(); @@ -107,71 +95,40 @@ static struct ast_filestream *mp3_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *mp3_read(struct ast_filestream *s) -{ - return NULL; -} - static void mp3_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (ast_pthread_mutex_lock(&mp3_lock)) { ast_log(LOG_WARNING, "Unable to lock mp3 list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&mp3_lock); ast_update_use_count(); - if (!tmp) - ast_log(LOG_WARNING, "Freeing a filestream we don't seem to own\n"); close(s->fd); free(s); } -static int ast_read_callback(void *data) +static struct ast_frame *mp3_read(struct ast_filestream *s, int *whennext) { /* XXX Don't assume frames are this size XXX */ u_int32_t delay = -1; int res; - struct ast_filestream *s = data; int size; - int ms=0; - struct timeval tv; if ((res = read(s->fd, s->buf , 4)) != 4) { ast_log(LOG_WARNING, "Short read (%d of 4 bytes) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } if (mp3_badheader(s->buf)) { ast_log(LOG_WARNING, "Bad mp3 header\n"); - return 0; + return NULL; } if ((size = mp3_framelen(s->buf)) < 0) { ast_log(LOG_WARNING, "Unable to calculate frame size\n"); - return 0; + return NULL; } if ((res = read(s->fd, s->buf + 4 , size - 4)) != size - 4) { ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size - 4, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } /* Send a frame from the file to the appropriate channel */ /* Read the data into the buffer */ @@ -183,48 +140,15 @@ static int ast_read_callback(void *data) s->fr.datalen = size; s->fr.data = s->buf; delay = mp3_samples(s->buf) * 1000 / mp3_samplerate(s->buf); - if (s->last.tv_sec || s->last.tv_usec) { - /* To keep things running smoothly, we watch how close we're coming */ - gettimeofday(&tv, NULL); - ms = ((tv.tv_usec - s->last.tv_usec) / 1000 + (tv.tv_sec - s->last.tv_sec) * 1000); - /* If we're within 2 milliseconds, that's close enough */ - if ((ms - delay) > 0 ) - s->adj -= (ms - delay); - s->adj -= 2; - } s->fr.samples = delay * 8; #if 0 ast_log(LOG_DEBUG, "delay is %d, adjusting by %d, as last was %d\n", delay, s->adj, ms); #endif - delay += s->adj; + delay *= 8; if (delay < 1) delay = 1; - /* Lastly, process the frame */ - if (ast_write(s->owner, &s->fr)) { - ast_log(LOG_WARNING, "Failed to write frame\n"); - s->owner->streamid = -1; - return 0; - } - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - s->owner->streamid = ast_sched_add(s->owner->sched, delay, ast_read_callback, s); - s->lasttimeout = delay; - return 0; - } - return -1; -} - -static int mp3_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 mp3_play(struct ast_filestream *s) -{ - ast_read_callback(s); - return 0; + *whennext = delay; + return &s->fr; } static int mp3_write(struct ast_filestream *fs, struct ast_frame *f) @@ -270,8 +194,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_MP3, mp3_open, mp3_rewrite, - mp3_apply, - mp3_play, mp3_write, mp3_seek, mp3_trunc, @@ -285,20 +207,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&mp3_lock)) { - ast_log(LOG_WARNING, "Unable to lock mp3 list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&mp3_lock); return ast_format_unregister(name); } diff --git a/formats/format_pcm.c b/formats/format_pcm.c index 14931dfdf..fe384ca5f 100755 --- a/formats/format_pcm.c +++ b/formats/format_pcm.c @@ -35,8 +35,6 @@ struct ast_filestream { void *reserved[AST_RESERVED_POINTERS]; - /* Believe it or not, we must decode/recode to account for the - weird MS format */ /* This is what a filestream means to us */ int fd; /* Descriptor */ struct ast_channel *owner; @@ -44,14 +42,10 @@ struct ast_filestream { char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char buf[BUF_SIZE]; /* Output Buffer */ - int lasttimeout; struct timeval last; - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t pcm_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -72,17 +66,13 @@ static struct ast_filestream *pcm_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->buf; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_ULAW; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; - tmp->lasttimeout = -1; glistcnt++; pthread_mutex_unlock(&pcm_lock); ast_update_use_count(); @@ -103,11 +93,7 @@ static struct ast_filestream *pcm_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; pthread_mutex_unlock(&pcm_lock); ast_update_use_count(); @@ -116,53 +102,23 @@ static struct ast_filestream *pcm_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *pcm_read(struct ast_filestream *s) -{ - return NULL; -} - static void pcm_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (pthread_mutex_lock(&pcm_lock)) { ast_log(LOG_WARNING, "Unable to lock pcm list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } - glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } pthread_mutex_unlock(&pcm_lock); ast_update_use_count(); - if (!tmp) - 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) +static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; int delay; - struct ast_filestream *s = data; - struct timeval tv; /* Send a frame from the file to the appropriate channel */ s->fr.frametype = AST_FRAME_VOICE; @@ -173,60 +129,13 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } s->fr.samples = res; s->fr.datalen = res; - 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"); - s->owner->streamid = -1; - return 0; - } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; - } - return retval; -} - -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; + delay = s->fr.samples; + *whennext = delay; + return &s->fr; } static int pcm_write(struct ast_filestream *fs, struct ast_frame *f) @@ -287,8 +196,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_ULAW, pcm_open, pcm_rewrite, - pcm_apply, - pcm_play, pcm_write, pcm_seek, pcm_trunc, @@ -302,20 +209,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (pthread_mutex_lock(&pcm_lock)) { - ast_log(LOG_WARNING, "Unable to lock pcm list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - pthread_mutex_unlock(&pcm_lock); return ast_format_unregister(name); } diff --git a/formats/format_pcm_alaw.c b/formats/format_pcm_alaw.c index 9a4f66586..ef17680d7 100755 --- a/formats/format_pcm_alaw.c +++ b/formats/format_pcm_alaw.c @@ -43,22 +43,16 @@ struct ast_filestream { weird MS format */ /* This is what a filestream means to us */ int fd; /* Descriptor */ - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char buf[BUF_SIZE]; /* Output Buffer */ - int lasttimeout; - struct timeval last; #ifdef REALTIME_WRITE unsigned long start_time; #endif - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t pcm_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -95,17 +89,13 @@ static struct ast_filestream *pcm_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->buf; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_ALAW; /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; - tmp->lasttimeout = -1; #ifdef REALTIME_WRITE tmp->start_time = get_time(); #endif @@ -129,11 +119,7 @@ static struct ast_filestream *pcm_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; #ifdef REALTIME_WRITE tmp->start_time = get_time(); #endif @@ -145,53 +131,23 @@ static struct ast_filestream *pcm_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *pcm_read(struct ast_filestream *s) -{ - return NULL; -} - static void pcm_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (pthread_mutex_lock(&pcm_lock)) { ast_log(LOG_WARNING, "Unable to lock pcm list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } pthread_mutex_unlock(&pcm_lock); ast_update_use_count(); - if (!tmp) - 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) +static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; - int delay; - struct ast_filestream *s = data; - struct timeval tv; /* Send a frame from the file to the appropriate channel */ s->fr.frametype = AST_FRAME_VOICE; @@ -202,60 +158,12 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } s->fr.samples = res; s->fr.datalen = res; - 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"); - s->owner->streamid = -1; - return 0; - } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; - } - return retval; -} - -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; + *whennext = s->fr.samples; + return &s->fr; } static int pcm_write(struct ast_filestream *fs, struct ast_frame *f) @@ -368,8 +276,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_ALAW, pcm_open, pcm_rewrite, - pcm_apply, - pcm_play, pcm_write, pcm_seek, pcm_trunc, @@ -381,20 +287,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (pthread_mutex_lock(&pcm_lock)) { - ast_log(LOG_WARNING, "Unable to lock pcm list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - pthread_mutex_unlock(&pcm_lock); return ast_format_unregister(name); } diff --git a/formats/format_vox.c b/formats/format_vox.c index 3848f47c0..095ca1703 100755 --- a/formats/format_vox.c +++ b/formats/format_vox.c @@ -35,21 +35,16 @@ struct ast_filestream { void *reserved[AST_RESERVED_POINTERS]; - /* Believe it or not, we must decode/recode to account for the - weird MS format */ /* This is what a filestream means to us */ int fd; /* Descriptor */ - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char buf[BUF_SIZE + 3]; /* Output Buffer */ int lasttimeout; struct timeval last; - int adj; short signal; /* Signal level (file side) */ short ssindex; /* Signal ssindex (file side) */ - struct ast_filestream *next; }; @@ -182,10 +177,7 @@ static struct ast_filestream *vox_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->buf; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_ADPCM; @@ -213,11 +205,7 @@ static struct ast_filestream *vox_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&vox_lock); ast_update_use_count(); @@ -226,53 +214,23 @@ static struct ast_filestream *vox_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *vox_read(struct ast_filestream *s) -{ - return NULL; -} - static void vox_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; if (ast_pthread_mutex_lock(&vox_lock)) { ast_log(LOG_WARNING, "Unable to lock vox list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&vox_lock); ast_update_use_count(); - if (!tmp) - 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) +static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; - int delay; - struct ast_filestream *s = data; - struct timeval tv; int x; /* Send a frame from the file to the appropriate channel */ @@ -284,8 +242,7 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, s->buf + 3, BUF_SIZE)) < 1) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } /* Store index, then signal */ s->buf[0] = s->ssindex & 0xff; @@ -298,55 +255,8 @@ static int ast_read_callback(void *data) } s->fr.samples = res * 2; s->fr.datalen = res + 3; - 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"); - s->owner->streamid = -1; - return 0; - } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; - } - return retval; -} - -static int vox_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 vox_play(struct ast_filestream *s) -{ - ast_read_callback(s); - return 0; + *whennext = s->fr.samples; + return &s->fr; } static int vox_write(struct ast_filestream *fs, struct ast_frame *f) @@ -396,8 +306,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_ADPCM, vox_open, vox_rewrite, - vox_apply, - vox_play, vox_write, vox_seek, vox_trunc, @@ -411,20 +319,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&vox_lock)) { - ast_log(LOG_WARNING, "Unable to lock vox list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&vox_lock); return ast_format_unregister(name); } diff --git a/formats/format_wav.c b/formats/format_wav.c index 185234768..c80d47e74 100755 --- a/formats/format_wav.c +++ b/formats/format_wav.c @@ -41,7 +41,6 @@ struct ast_filestream { int fd; /* Descriptor */ int bytes; int needsgain; - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ @@ -50,12 +49,9 @@ struct ast_filestream { int lasttimeout; int maxlen; struct timeval last; - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t wav_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -321,10 +317,7 @@ static struct ast_filestream *wav_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->needsgain = 1; tmp->fr.data = tmp->buf; tmp->fr.frametype = AST_FRAME_VOICE; @@ -332,7 +325,6 @@ static struct ast_filestream *wav_open(int fd) /* datalen will vary for each frame */ tmp->fr.src = name; tmp->fr.mallocd = 0; - tmp->lasttimeout = -1; tmp->bytes = 0; glistcnt++; ast_pthread_mutex_unlock(&wav_lock); @@ -358,11 +350,7 @@ static struct ast_filestream *wav_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&wav_lock); ast_update_use_count(); @@ -371,60 +359,29 @@ static struct ast_filestream *wav_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *wav_read(struct ast_filestream *s) -{ - return NULL; -} - static void wav_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; char zero = 0; if (ast_pthread_mutex_lock(&wav_lock)) { ast_log(LOG_WARNING, "Unable to lock wav list\n"); return; } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&wav_lock); ast_update_use_count(); - if (!tmp) - ast_log(LOG_WARNING, "Freeing a filestream we don't seem to own\n"); /* Pad to even length */ if (s->bytes & 0x1) write(s->fd, &zero, 1); close(s->fd); free(s); s = NULL; -#if 0 - printf("bytes = %d\n", s->bytes); -#endif } -static int ast_read_callback(void *data) +static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; int delay; int x; - struct ast_filestream *s = data; short tmp[sizeof(s->buf) / 2]; int bytes = sizeof(tmp); off_t here; @@ -440,8 +397,7 @@ static int ast_read_callback(void *data) if (res) { ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); } - s->owner->streamid = -1; - return 0; + return NULL; } #if __BYTE_ORDER == __BIG_ENDIAN @@ -472,36 +428,8 @@ static int ast_read_callback(void *data) s->fr.data = s->buf; s->fr.mallocd = 0; s->fr.samples = delay; - delay /= 8; - /* Lastly, process the frame */ - if (delay != s->lasttimeout) { - s->owner->streamid = ast_sched_add(s->owner->sched, delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - retval = -1; - } - - - if (ast_write(s->owner, &s->fr)) { - ast_log(LOG_WARNING, "Failed to write frame\n"); - s->owner->streamid = -1; - return 0; - } - - return retval; -} - -static int wav_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 wav_play(struct ast_filestream *s) -{ - ast_read_callback(s); - return 0; + *whennext = delay; + return &s->fr; } static int wav_write(struct ast_filestream *fs, struct ast_frame *f) @@ -607,8 +535,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_SLINEAR, wav_open, wav_rewrite, - wav_apply, - wav_play, wav_write, wav_seek, wav_trunc, @@ -622,20 +548,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&wav_lock)) { - ast_log(LOG_WARNING, "Unable to lock wav list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&wav_lock); return ast_format_unregister(name); } diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c index 06275402f..a9a1e8313 100755 --- a/formats/format_wav_gsm.c +++ b/formats/format_wav_gsm.c @@ -43,21 +43,16 @@ struct ast_filestream { /* This is what a filestream means to us */ int fd; /* Descriptor */ int bytes; - struct ast_channel *owner; struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ unsigned char gsm[66]; /* Two Real GSM Frames */ int foffset; int secondhalf; /* Are we on the second half */ - int lasttimeout; struct timeval last; - int adj; - struct ast_filestream *next; }; -static struct ast_filestream *glist = NULL; static pthread_mutex_t wav_lock = AST_MUTEX_INITIALIZER; static int glistcnt = 0; @@ -341,10 +336,7 @@ static struct ast_filestream *wav_open(int fd) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; tmp->fr.data = tmp->gsm; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_GSM; @@ -352,7 +344,6 @@ static struct ast_filestream *wav_open(int fd) tmp->fr.src = name; tmp->fr.mallocd = 0; tmp->secondhalf = 0; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&wav_lock); ast_update_use_count(); @@ -377,11 +368,7 @@ static struct ast_filestream *wav_rewrite(int fd, char *comment) free(tmp); return NULL; } - tmp->next = glist; - glist = tmp; tmp->fd = fd; - tmp->owner = NULL; - tmp->lasttimeout = -1; glistcnt++; ast_pthread_mutex_unlock(&wav_lock); ast_update_use_count(); @@ -390,42 +377,11 @@ static struct ast_filestream *wav_rewrite(int fd, char *comment) return tmp; } -static struct ast_frame *wav_read(struct ast_filestream *s) -{ - return NULL; -} - static void wav_close(struct ast_filestream *s) { - struct ast_filestream *tmp, *tmpl = NULL; char zero = 0; - if (ast_pthread_mutex_lock(&wav_lock)) { - ast_log(LOG_WARNING, "Unable to lock wav list\n"); - return; - } - tmp = glist; - while(tmp) { - if (tmp == s) { - if (tmpl) - tmpl->next = tmp->next; - else - glist = tmp->next; - break; - } - tmpl = tmp; - tmp = tmp->next; - } - glistcnt--; - if (s->owner) { - s->owner->stream = NULL; - if (s->owner->streamid > -1) - ast_sched_del(s->owner->sched, s->owner->streamid); - s->owner->streamid = -1; - } ast_pthread_mutex_unlock(&wav_lock); ast_update_use_count(); - if (!tmp) - ast_log(LOG_WARNING, "Freeing a filestream we don't seem to own\n"); /* Pad to even length */ if (s->bytes & 0x1) write(s->fd, &zero, 1); @@ -434,14 +390,10 @@ static void wav_close(struct ast_filestream *s) s = NULL; } -static int ast_read_callback(void *data) +static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext) { - int retval = 0; int res; - int delay = 20; - struct ast_filestream *s = data; char msdata[66]; - struct timeval tv; /* Send a frame from the file to the appropriate channel */ s->fr.frametype = AST_FRAME_VOICE; @@ -457,62 +409,15 @@ static int ast_read_callback(void *data) if ((res = read(s->fd, msdata, 65)) != 65) { if (res && (res != 1)) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); - s->owner->streamid = -1; - return 0; + return NULL; } /* Convert from MS format to two real GSM frames */ conv65(msdata, s->gsm); s->fr.data = s->gsm; } s->secondhalf = !s->secondhalf; - /* Lastly, process the frame */ - if (ast_write(s->owner, &s->fr)) { - ast_log(LOG_WARNING, "Failed to write frame\n"); - s->owner->streamid = -1; - return 0; - } - if (s->last.tv_usec || s->last.tv_usec) { - int ms; - gettimeofday(&tv, NULL); - ms = 1000 * (tv.tv_sec - s->last.tv_sec) + - (tv.tv_usec - s->last.tv_usec) / 1000; - s->last.tv_sec = tv.tv_sec; - s->last.tv_usec = tv.tv_usec; - if ((ms - delay) * (ms - delay) > 4) { - /* Compensate if we're more than 2 ms off */ - s->adj -= (ms - delay); - } -#if 0 - fprintf(stdout, "Delay is %d, adjustment is %d, last was %d\n", delay, s->adj, ms); -#endif - delay += s->adj; - if (delay < 1) - delay = 1; - } else - gettimeofday(&s->last, NULL); - if (s->lasttimeout != delay) { - /* We'll install the next timeout now. */ - s->owner->streamid = ast_sched_add(s->owner->sched, - delay, ast_read_callback, s); - s->lasttimeout = delay; - } else { - /* Just come back again at the same time */ - retval = -1; - } - return retval; -} - -static int wav_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 wav_play(struct ast_filestream *s) -{ - ast_read_callback(s); - return 0; + *whennext = 160; + return &s->fr; } static int wav_write(struct ast_filestream *fs, struct ast_frame *f) @@ -609,8 +514,6 @@ int load_module() return ast_format_register(name, exts, AST_FORMAT_GSM, wav_open, wav_rewrite, - wav_apply, - wav_play, wav_write, wav_seek, wav_trunc, @@ -624,20 +527,6 @@ int load_module() int unload_module() { - struct ast_filestream *tmp, *tmpl; - if (ast_pthread_mutex_lock(&wav_lock)) { - ast_log(LOG_WARNING, "Unable to lock wav list\n"); - return -1; - } - tmp = glist; - while(tmp) { - if (tmp->owner) - ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD); - tmpl = tmp; - tmp = tmp->next; - free(tmpl); - } - ast_pthread_mutex_unlock(&wav_lock); return ast_format_unregister(name); } |