mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Version 0.1.12 from FTP
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@462 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
* the GNU General Public License
|
||||
*/
|
||||
|
||||
#include <asterisk/lock.h>
|
||||
#include <asterisk/file.h>
|
||||
#include <asterisk/logger.h>
|
||||
#include <asterisk/channel.h>
|
||||
@@ -51,7 +52,7 @@ static int record_exec(struct ast_channel *chan, void *data)
|
||||
|
||||
struct ast_filestream *s = '\0';
|
||||
struct localuser *u;
|
||||
struct ast_frame *f;
|
||||
struct ast_frame *f = NULL;
|
||||
|
||||
vdata = data; /* explained above */
|
||||
|
||||
@@ -103,10 +104,8 @@ static int record_exec(struct ast_channel *chan, void *data)
|
||||
/* Some code to play a nice little beep to signify the start of the record operation */
|
||||
res = ast_streamfile(chan, "beep", chan->language);
|
||||
if (!res) {
|
||||
printf("Waiting on stream\n");
|
||||
res = ast_waitstream(chan, "");
|
||||
} else {
|
||||
printf("streamfile failed\n");
|
||||
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", chan->name);
|
||||
}
|
||||
ast_stopstream(chan);
|
||||
@@ -114,8 +113,12 @@ static int record_exec(struct ast_channel *chan, void *data)
|
||||
s = ast_writefile( tmp, ext, NULL, O_CREAT|O_TRUNC|O_WRONLY , 0, 0644);
|
||||
|
||||
if (s) {
|
||||
|
||||
while ((f = ast_read(chan))) {
|
||||
while (ast_waitfor(chan, -1) > -1) {
|
||||
f = ast_read(chan);
|
||||
if (!f) {
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
if (f->frametype == AST_FRAME_VOICE) {
|
||||
res = ast_writestream(s, f);
|
||||
|
||||
|
51
contrib/init.d/rc.redhat.asterisk
Executable file
51
contrib/init.d/rc.redhat.asterisk
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# asterisk This shell script takes care of starting and stopping
|
||||
# asterisk (printer daemon).
|
||||
#
|
||||
# chkconfig: 2345 60 60
|
||||
# description: asterisk is the print daemon required for lpr to work properly. \
|
||||
# It is basically a server that arbitrates print jobs to printer(s).
|
||||
# processname: asterisk
|
||||
# config: /etc/printcap
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
[ -f /usr/sbin/asterisk ] || exit 0
|
||||
|
||||
RETVAL=0
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
# Start daemons.
|
||||
echo -n "Starting asterisk: "
|
||||
daemon safe_asterisk
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
|
||||
;;
|
||||
stop)
|
||||
# Stop daemons.
|
||||
echo -n "Shutting down asterisk: "
|
||||
killproc asterisk
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
|
||||
;;
|
||||
status)
|
||||
status asterisk
|
||||
RETVAL=$?
|
||||
;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
RETVAL=$?
|
||||
;;
|
||||
*)
|
||||
echo "Usage: asterisk {start|stop|restart|reload|status}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $RETVAL
|
83
frame.c
83
frame.c
@@ -25,18 +25,93 @@
|
||||
#ifdef TRACE_FRAMES
|
||||
static int headers = 0;
|
||||
static struct ast_frame *headerlist = NULL;
|
||||
static pthread_mutex_t framelock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t framelock = AST_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
#define SMOOTHER_SIZE 8000
|
||||
|
||||
struct ast_smoother {
|
||||
int size;
|
||||
int format;
|
||||
int readdata;
|
||||
float timeperbyte;
|
||||
struct ast_frame f;
|
||||
char data[SMOOTHER_SIZE];
|
||||
char framedata[SMOOTHER_SIZE + AST_FRIENDLY_OFFSET];
|
||||
int len;
|
||||
};
|
||||
|
||||
struct ast_smoother *ast_smoother_new(int size)
|
||||
{
|
||||
struct ast_smoother *s;
|
||||
s = malloc(sizeof(struct ast_smoother));
|
||||
if (s) {
|
||||
memset(s, 0, sizeof(s));
|
||||
s->size = size;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f)
|
||||
{
|
||||
if (f->frametype != AST_FRAME_VOICE) {
|
||||
ast_log(LOG_WARNING, "Huh? Can't smooth a non-voice frame!\n");
|
||||
return -1;
|
||||
}
|
||||
if (!s->format) {
|
||||
s->format = f->subclass;
|
||||
s->timeperbyte = (float)f->timelen / (float)f->datalen;
|
||||
} else if (s->format != f->subclass) {
|
||||
ast_log(LOG_WARNING, "Smoother was working on %d format frames, now trying to feed %d?\n", s->format, f->subclass);
|
||||
return -1;
|
||||
}
|
||||
if (s->len + f->datalen > SMOOTHER_SIZE) {
|
||||
ast_log(LOG_WARNING, "Out of smoother space\n");
|
||||
return -1;
|
||||
}
|
||||
memcpy(s->data + s->len, f->data, f->datalen);
|
||||
s->len += f->datalen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ast_frame *ast_smoother_read(struct ast_smoother *s)
|
||||
{
|
||||
/* Make sure we have enough data */
|
||||
if (s->len < s->size)
|
||||
return NULL;
|
||||
/* Make frame */
|
||||
s->f.frametype = AST_FRAME_VOICE;
|
||||
s->f.subclass = s->format;
|
||||
s->f.data = s->framedata;
|
||||
s->f.offset = AST_FRIENDLY_OFFSET;
|
||||
s->f.datalen = s->size;
|
||||
s->f.timelen = s->size * s->timeperbyte;
|
||||
/* Fill Data */
|
||||
memcpy(s->f.data + AST_FRIENDLY_OFFSET, s->f.data, s->size);
|
||||
s->len -= s->size;
|
||||
/* Move remaining data to the front if applicable */
|
||||
if (s->len)
|
||||
memmove(s->f.data, s->f.data + s->size, s->len);
|
||||
/* Return frame */
|
||||
return &s->f;
|
||||
}
|
||||
|
||||
void ast_smoother_free(struct ast_smoother *s)
|
||||
{
|
||||
free(s);
|
||||
}
|
||||
|
||||
static struct ast_frame *ast_frame_header_new(void)
|
||||
{
|
||||
struct ast_frame *f;
|
||||
f = malloc(sizeof(struct ast_frame));
|
||||
if (f)
|
||||
memset(f, 0, sizeof(struct ast_frame));
|
||||
#ifdef TRACE_FRAMES
|
||||
if (f) {
|
||||
headers++;
|
||||
f->prev = NULL;
|
||||
pthread_mutex_lock(&framelock);
|
||||
ast_pthread_mutex_lock(&framelock);
|
||||
f->next = headerlist;
|
||||
if (headerlist)
|
||||
headerlist->prev = f;
|
||||
@@ -65,7 +140,7 @@ void ast_frfree(struct ast_frame *fr)
|
||||
if (fr->mallocd & AST_MALLOCD_HDR) {
|
||||
#ifdef TRACE_FRAMES
|
||||
headers--;
|
||||
pthread_mutex_lock(&framelock);
|
||||
ast_pthread_mutex_lock(&framelock);
|
||||
if (fr->next)
|
||||
fr->next->prev = fr->prev;
|
||||
if (fr->prev)
|
||||
@@ -237,7 +312,7 @@ static int show_frame_stats(int fd, int argc, char *argv[])
|
||||
ast_cli(fd, "---------------------------\n");
|
||||
ast_cli(fd, "Total allocated headers: %d\n", headers);
|
||||
ast_cli(fd, "Queue Dump:\n");
|
||||
pthread_mutex_lock(&framelock);
|
||||
ast_pthread_mutex_lock(&framelock);
|
||||
for (f=headerlist; f; f = f->next) {
|
||||
ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ extern "C" {
|
||||
struct ast_channel_pvt {
|
||||
/*! Private data used by channel backend */
|
||||
void *pvt;
|
||||
struct ast_frame *readq;
|
||||
int alertpipe[2];
|
||||
/*! Write translation path */
|
||||
struct ast_trans_pvt *writetrans;
|
||||
/*! Read translation path */
|
||||
@@ -67,7 +69,14 @@ struct ast_channel_pvt {
|
||||
|
||||
//! Create a channel structure
|
||||
/*! Returns NULL on failure to allocate */
|
||||
struct ast_channel *ast_channel_alloc(void);
|
||||
struct ast_channel *ast_channel_alloc(int needalertpipe);
|
||||
|
||||
/*! Queue an outgoing frame, locking if necessary */
|
||||
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f, int lock);
|
||||
|
||||
int ast_queue_hangup(struct ast_channel *chan, int lock);
|
||||
|
||||
int ast_queue_control(struct ast_channel *chan, int control, int lock);
|
||||
|
||||
//! Free a channel structure
|
||||
void ast_channel_free(struct ast_channel *);
|
||||
|
51
init.asterisk
Executable file
51
init.asterisk
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# asterisk This shell script takes care of starting and stopping
|
||||
# asterisk (printer daemon).
|
||||
#
|
||||
# chkconfig: 2345 60 60
|
||||
# description: asterisk is the print daemon required for lpr to work properly. \
|
||||
# It is basically a server that arbitrates print jobs to printer(s).
|
||||
# processname: asterisk
|
||||
# config: /etc/printcap
|
||||
|
||||
# Source function library.
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
[ -f /usr/sbin/asterisk ] || exit 0
|
||||
|
||||
RETVAL=0
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
# Start daemons.
|
||||
echo -n "Starting asterisk: "
|
||||
daemon safe_asterisk
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
|
||||
;;
|
||||
stop)
|
||||
# Stop daemons.
|
||||
echo -n "Shutting down asterisk: "
|
||||
killproc asterisk
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
|
||||
;;
|
||||
status)
|
||||
status asterisk
|
||||
RETVAL=$?
|
||||
;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
RETVAL=$?
|
||||
;;
|
||||
*)
|
||||
echo "Usage: asterisk {start|stop|restart|reload|status}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $RETVAL
|
Reference in New Issue
Block a user