mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
Totally redo file formats
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1130 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
69
file.c
69
file.c
@@ -43,10 +43,6 @@ struct ast_format {
|
||||
struct ast_filestream * (*open)(int fd);
|
||||
/* Open an output stream, of a given file descriptor and comment it appropriately if applicable */
|
||||
struct ast_filestream * (*rewrite)(int fd, char *comment);
|
||||
/* Apply a reading filestream to a channel */
|
||||
int (*apply)(struct ast_channel *, struct ast_filestream *);
|
||||
/* play filestream on a channel */
|
||||
int (*play)(struct ast_filestream *);
|
||||
/* Write a frame to a channel */
|
||||
int (*write)(struct ast_filestream *, struct ast_frame *);
|
||||
/* seek num samples into file, whence(think normal seek) */
|
||||
@@ -55,8 +51,9 @@ struct ast_format {
|
||||
int (*trunc)(struct ast_filestream *fs);
|
||||
/* tell current position */
|
||||
long (*tell)(struct ast_filestream *fs);
|
||||
/* Read the next frame from the filestream (if available) */
|
||||
struct ast_frame * (*read)(struct ast_filestream *);
|
||||
/* Read the next frame from the filestream (if available) and report when to get next one
|
||||
(in samples) */
|
||||
struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
|
||||
/* Close file, and destroy filestream structure */
|
||||
void (*close)(struct ast_filestream *);
|
||||
/* Retrieve file comment */
|
||||
@@ -72,6 +69,8 @@ struct ast_filestream {
|
||||
struct ast_trans_pvt *trans;
|
||||
struct ast_tranlator_pvt *tr;
|
||||
int lastwriteformat;
|
||||
int lasttimeout;
|
||||
struct ast_channel *owner;
|
||||
};
|
||||
|
||||
static pthread_mutex_t formatlock = AST_MUTEX_INITIALIZER;
|
||||
@@ -81,13 +80,11 @@ static struct ast_format *formats = NULL;
|
||||
int ast_format_register(char *name, char *exts, int format,
|
||||
struct ast_filestream * (*open)(int fd),
|
||||
struct ast_filestream * (*rewrite)(int fd, char *comment),
|
||||
int (*apply)(struct ast_channel *, struct ast_filestream *),
|
||||
int (*play)(struct ast_filestream *),
|
||||
int (*write)(struct ast_filestream *, struct ast_frame *),
|
||||
int (*seek)(struct ast_filestream *, long sample_offset, int whence),
|
||||
int (*trunc)(struct ast_filestream *),
|
||||
long (*tell)(struct ast_filestream *),
|
||||
struct ast_frame * (*read)(struct ast_filestream *),
|
||||
struct ast_frame * (*read)(struct ast_filestream *, int *whennext),
|
||||
void (*close)(struct ast_filestream *),
|
||||
char * (*getcomment)(struct ast_filestream *))
|
||||
{
|
||||
@@ -115,8 +112,6 @@ int ast_format_register(char *name, char *exts, int format,
|
||||
strncpy(tmp->exts, exts, sizeof(tmp->exts)-1);
|
||||
tmp->open = open;
|
||||
tmp->rewrite = rewrite;
|
||||
tmp->apply = apply;
|
||||
tmp->play = play;
|
||||
tmp->read = read;
|
||||
tmp->write = write;
|
||||
tmp->seek = seek;
|
||||
@@ -164,7 +159,7 @@ int ast_stopstream(struct ast_channel *tmp)
|
||||
/* Stop a running stream if there is one */
|
||||
if (!tmp->stream)
|
||||
return 0;
|
||||
tmp->stream->fmt->close(tmp->stream);
|
||||
ast_closestream(tmp->stream);
|
||||
if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat))
|
||||
ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat);
|
||||
return 0;
|
||||
@@ -255,7 +250,7 @@ static char *build_filename(char *filename, char *ext)
|
||||
{
|
||||
char *fn;
|
||||
char tmp[AST_CONFIG_MAX_PATH];
|
||||
snprintf((char *)tmp,sizeof(tmp)-1,"%s/%s",(char *)ast_config_AST_VAR_DIR,"sounds");
|
||||
snprintf(tmp,sizeof(tmp)-1,"%s/%s",(char *)ast_config_AST_VAR_DIR,"sounds");
|
||||
fn = malloc(strlen(tmp) + strlen(filename) + strlen(ext) + 10);
|
||||
if (fn) {
|
||||
if (filename[0] == '/')
|
||||
@@ -345,6 +340,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action
|
||||
if (ret >= 0) {
|
||||
s = f->open(ret);
|
||||
if (s) {
|
||||
s->lasttimeout = -1;
|
||||
s->fmt = f;
|
||||
s->trans = NULL;
|
||||
chan->stream = s;
|
||||
@@ -427,24 +423,43 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ast_readaudio_callback(void *data)
|
||||
{
|
||||
struct ast_filestream *s = data;
|
||||
struct ast_frame *fr;
|
||||
int whennext = 0;
|
||||
|
||||
while(!whennext) {
|
||||
fr = s->fmt->read(s, &whennext);
|
||||
if (fr) {
|
||||
if (ast_write(s->owner, fr)) {
|
||||
ast_log(LOG_WARNING, "Failed to write frame\n");
|
||||
s->owner->streamid = -1;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* Stream has finished */
|
||||
s->owner->streamid = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (whennext != s->lasttimeout) {
|
||||
s->owner->streamid = ast_sched_add(s->owner->sched, whennext/8, ast_readaudio_callback, s);
|
||||
s->lasttimeout = whennext;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
|
||||
{
|
||||
if(chan->stream->fmt->apply(chan,s)){
|
||||
chan->stream->fmt->close(s);
|
||||
chan->stream = NULL;
|
||||
ast_log(LOG_WARNING, "Unable to apply stream to channel %s\n", chan->name);
|
||||
return -1;
|
||||
}
|
||||
s->owner = chan;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_playstream(struct ast_filestream *s)
|
||||
{
|
||||
if(s->fmt->play(s)){
|
||||
ast_closestream(s);
|
||||
ast_log(LOG_WARNING, "Unable to start playing stream\n");
|
||||
return -1;
|
||||
}
|
||||
ast_readaudio_callback(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -481,6 +496,12 @@ int ast_stream_rewind(struct ast_filestream *fs, long ms)
|
||||
int ast_closestream(struct ast_filestream *f)
|
||||
{
|
||||
/* Stop a running stream if there is one */
|
||||
if (f->owner) {
|
||||
f->owner->stream = NULL;
|
||||
if (f->owner->streamid > -1)
|
||||
ast_sched_del(f->owner->sched, f->owner->streamid);
|
||||
f->owner->streamid = -1;
|
||||
}
|
||||
f->fmt->close(f);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
return NULL;
|
||||
}
|
||||
/* 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 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);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
return NULL;
|
||||
}
|
||||
/* 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 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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -39,13 +39,11 @@ struct ast_filestream;
|
||||
int ast_format_register(char *name, char *exts, int format,
|
||||
struct ast_filestream * (*open)(int fd),
|
||||
struct ast_filestream * (*rewrite)(int fd, char *comment),
|
||||
int (*apply)(struct ast_channel *, struct ast_filestream *),
|
||||
int (*play)(struct ast_filestream *),
|
||||
int (*write)(struct ast_filestream *, struct ast_frame *),
|
||||
int (*seek)(struct ast_filestream *, long offset, int whence),
|
||||
int (*trunc)(struct ast_filestream *),
|
||||
long (*tell)(struct ast_filestream *),
|
||||
struct ast_frame * (*read)(struct ast_filestream *),
|
||||
struct ast_frame * (*read)(struct ast_filestream *, int *timetonext),
|
||||
void (*close)(struct ast_filestream *),
|
||||
char * (*getcomment)(struct ast_filestream *));
|
||||
|
||||
@@ -252,7 +250,7 @@ int ast_stream_rewind(struct ast_filestream *fs, long ms);
|
||||
*/
|
||||
long ast_tellstream(struct ast_filestream *fs);
|
||||
|
||||
#define AST_RESERVED_POINTERS 4
|
||||
#define AST_RESERVED_POINTERS 12
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
|
4
rtp.c
4
rtp.c
@@ -1247,7 +1247,9 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
|
||||
/* That's all we needed */
|
||||
return 0;
|
||||
} else {
|
||||
if ((f->frametype == AST_FRAME_DTMF) || (f->frametype == AST_FRAME_VOICE)) {
|
||||
if ((f->frametype == AST_FRAME_DTMF) ||
|
||||
(f->frametype == AST_FRAME_VOICE) ||
|
||||
(f->frametype == AST_FRAME_VIDEO)) {
|
||||
/* Forward voice or DTMF frames if they happen upon us */
|
||||
if (who == c0) {
|
||||
ast_write(c1, f);
|
||||
|
Reference in New Issue
Block a user