aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 01:51:21 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 01:51:21 +0000
commitd3323c9c37e93007eae9df8b25a174fc9cbcbbfa (patch)
tree44c03bd656930ad4b36b921854685fd0ab516452 /main
parente9def2b3fb87a25a2fdbed138f1a5331ff1b08d9 (diff)
revert commit that included extranous changes
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@182807 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/Makefile13
-rw-r--r--main/asterisk.exports28
-rw-r--r--main/astobj2.c6
-rw-r--r--main/autoservice.c17
-rw-r--r--main/channel.c228
-rw-r--r--main/file.c18
-rw-r--r--main/frame.c127
-rw-r--r--main/slinfactory.c30
8 files changed, 174 insertions, 293 deletions
diff --git a/main/Makefile b/main/Makefile
index 0b83191e0..c8a878378 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -94,10 +94,6 @@ ifeq ($(OSARCH),SunOS)
ASTLINK=
endif
-ifeq ($(GNU_LD),1)
-ASTLINK+=-Wl,--version-script,asterisk.exports
-endif
-
editline/libedit.a:
cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(subst $(ASTTOPDIR),../../,$(ASTCFLAGS:-Werror=))" LDFLAGS="$(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
$(MAKE) -C editline libedit.a
@@ -137,19 +133,20 @@ else
H323LDLIBS=
endif
-asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) asterisk.exports
+asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
@$(ASTTOPDIR)/build_tools/make_build_h > $(ASTTOPDIR)/include/asterisk/build.h.tmp
@if cmp -s $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; then echo ; else \
mv $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; \
fi
@rm -f $(ASTTOPDIR)/include/asterisk/build.h.tmp
@$(CC) -c -o buildinfo.o $(ASTCFLAGS) buildinfo.c
- $(ECHO_PREFIX) echo " [LD] $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) -> $@"
+ $(ECHO_PREFIX) echo " [LD] $^ -> $@"
ifneq ($(findstring chan_h323,$(MENUSELECT_CHANNELS)),)
- $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
+ $(CMD_PREFIX) $(CC) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS)
else
- $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
+ $(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)
endif
+ $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/strip_nonapi $@ || rm $@
clean::
rm -f asterisk
diff --git a/main/asterisk.exports b/main/asterisk.exports
deleted file mode 100644
index f18c0fff0..000000000
--- a/main/asterisk.exports
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- global:
- ast_*;
- _ast_*;
- __ast_*;
- pbx_*;
- astman_*;
- ao2_*;
- __ao2_*;
- option_debug;
- option_verbose;
- dahdi_chan_name;
- dahdi_chan_name_len;
- dahdi_chan_mode;
- cid_di;
- cid_dr;
- clidsb;
- MD5*;
- sched_*;
- io_*;
- jb_*;
- channelreloadreason2txt;
- devstate2str;
- manager_event;
- dialed_interface_info;
- local:
- *;
-};
diff --git a/main/astobj2.c b/main/astobj2.c
index 8157c78cf..56ab75a21 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -128,7 +128,7 @@ static inline struct astobj2 *INTERNAL_OBJ(void *user_data)
#ifndef DEBUG_THREADS
int ao2_lock(void *user_data)
#else
-int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
+int _ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -150,7 +150,7 @@ int __ao2_lock(void *user_data, const char *file, const char *func, int line, co
#ifndef DEBUG_THREADS
int ao2_trylock(void *user_data)
#else
-int __ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
+int _ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -177,7 +177,7 @@ int __ao2_trylock(void *user_data, const char *file, const char *func, int line,
#ifndef DEBUG_THREADS
int ao2_unlock(void *user_data)
#else
-int __ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
+int _ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
diff --git a/main/autoservice.c b/main/autoservice.c
index 8bcf81742..1150c4c7f 100644
--- a/main/autoservice.c
+++ b/main/autoservice.c
@@ -168,22 +168,15 @@ static void *autoservice_run(void *ign)
continue;
}
- if (defer_frame != f) {
- if ((dup_f = ast_frdup(defer_frame))) {
- AST_LIST_INSERT_HEAD(&ents[i]->deferred_frames, dup_f, frame_list);
- }
- } else {
- if ((dup_f = ast_frisolate(defer_frame))) {
- if (dup_f != defer_frame) {
- ast_frfree(defer_frame);
- }
- AST_LIST_INSERT_HEAD(&ents[i]->deferred_frames, dup_f, frame_list);
- }
+ if ((dup_f = ast_frdup(defer_frame))) {
+ AST_LIST_INSERT_HEAD(&ents[i]->deferred_frames, dup_f, frame_list);
}
break;
}
- } else if (f) {
+ }
+
+ if (f) {
ast_frfree(f);
}
}
diff --git a/main/channel.c b/main/channel.c
index 16fe23b24..475942163 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -895,90 +895,60 @@ alertpipe_failed:
}
/*! \brief Queue an outgoing media frame */
-static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after)
+static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, int head)
{
struct ast_frame *f;
struct ast_frame *cur;
int blah = 1;
- unsigned int new_frames = 0;
- unsigned int new_voice_frames = 0;
- unsigned int queued_frames = 0;
- unsigned int queued_voice_frames = 0;
-
- AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
-
- /* Build copies of all the frames and count them */
- AST_LIST_HEAD_INIT_NOLOCK(&frames);
- for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
- if (!(f = ast_frdup(cur))) {
- ast_frfree(AST_LIST_FIRST(&frames));
- return -1;
- }
+ int qlen = 0;
- AST_LIST_INSERT_TAIL(&frames, f, frame_list);
- new_frames++;
- if (f->frametype == AST_FRAME_VOICE) {
- new_voice_frames++;
- }
+ /* Build us a copy and free the original one */
+ if (!(f = ast_frdup(fin))) {
+ return -1;
}
ast_channel_lock(chan);
/* See if the last frame on the queue is a hangup, if so don't queue anything */
if ((cur = AST_LIST_LAST(&chan->readq)) && (cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP)) {
- while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
- ast_frfree(f);
- }
+ ast_frfree(f);
ast_channel_unlock(chan);
return 0;
}
/* Count how many frames exist on the queue */
AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) {
- queued_frames++;
- if (cur->frametype == AST_FRAME_VOICE) {
- queued_voice_frames++;
- }
+ qlen++;
}
- if ((queued_frames + new_frames) > 128) {
- ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name);
- while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
+ /* Allow up to 96 voice frames outstanding, and up to 128 total frames */
+ if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen > 128)) {
+ if (fin->frametype != AST_FRAME_VOICE) {
+ ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name);
+ ast_assert(fin->frametype == AST_FRAME_VOICE);
+ } else {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name);
ast_frfree(f);
+ ast_channel_unlock(chan);
+ return 0;
}
- ast_channel_unlock(chan);
- return 0;
}
- if ((queued_voice_frames + new_voice_frames) > 96) {
- ast_log(LOG_WARNING, "Exceptionally long voice queue length queuing to %s\n", chan->name);
- while ((f = AST_LIST_REMOVE_HEAD(&frames, frame_list))) {
- ast_frfree(f);
- }
- ast_channel_unlock(chan);
- return 0;
- }
-
- if (after) {
- AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list);
+ if (head) {
+ AST_LIST_INSERT_HEAD(&chan->readq, f, frame_list);
} else {
- if (head) {
- AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list);
- AST_LIST_HEAD_INIT_NOLOCK(&chan->readq);
- }
- AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list);
+ AST_LIST_INSERT_TAIL(&chan->readq, f, frame_list);
}
if (chan->alertpipe[1] > -1) {
- if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) {
- ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n",
- chan->name, queued_frames, strerror(errno));
+ if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah)) {
+ ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
+ chan->name, f->frametype, f->subclass, qlen, strerror(errno));
}
#ifdef HAVE_DAHDI
} else if (chan->timingfd > -1) {
- while (new_frames--) {
- ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
- }
+ ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
#endif
} else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
pthread_kill(chan->blocker, SIGURG);
@@ -991,12 +961,12 @@ static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, in
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
{
- return __ast_queue_frame(chan, fin, 0, NULL);
+ return __ast_queue_frame(chan, fin, 0);
}
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
{
- return __ast_queue_frame(chan, fin, 1, NULL);
+ return __ast_queue_frame(chan, fin, 1);
}
/*! \brief Queue a hangup frame for channel */
@@ -2180,7 +2150,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
AST_LIST_REMOVE_CURRENT(&chan->readq, frame_list);
break;
}
- AST_LIST_TRAVERSE_SAFE_END;
+ AST_LIST_TRAVERSE_SAFE_END
if (!f) {
/* There were no acceptable frames on the readq. */
@@ -2225,14 +2195,13 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
chan->fdno = -1;
if (f) {
- struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq);
-
/* if the channel driver returned more than one frame, stuff the excess
- into the readq for the next ast_read call
+ into the readq for the next ast_read call (note that we can safely assume
+ that the readq is empty, because otherwise we would not have called into
+ the channel driver and f would be only a single frame)
*/
if (AST_LIST_NEXT(f, frame_list)) {
- ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list));
- ast_frfree(AST_LIST_NEXT(f, frame_list));
+ AST_LIST_HEAD_SET_NOLOCK(&chan->readq, AST_LIST_NEXT(f, frame_list));
AST_LIST_NEXT(f, frame_list) = NULL;
}
@@ -2441,26 +2410,8 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
}
}
- if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) {
+ if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL)
f = &ast_null_frame;
- }
-
- /* it is possible for the translation process on chan->readtrans to have
- produced multiple frames from the single input frame we passed it; if
- this happens, queue the additional frames *before* the frames we may
- have queued earlier. if the readq was empty, put them at the head of
- the queue, and if it was not, put them just after the frame that was
- at the end of the queue.
- */
- if (AST_LIST_NEXT(f, frame_list)) {
- if (!readq_tail) {
- ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list));
- } else {
- __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail);
- }
- ast_frfree(AST_LIST_NEXT(f, frame_list));
- AST_LIST_NEXT(f, frame_list) = NULL;
- }
/* Run generator sitting on the line if timing device not available
* and synchronous generation of outgoing frames is necessary */
@@ -2791,7 +2742,7 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
{
int res = -1;
int count = 0;
- struct ast_frame *f = NULL;
+ struct ast_frame *f = NULL, *f2 = NULL;
/*Deadlock avoidance*/
while(ast_channel_trylock(chan)) {
@@ -2862,12 +2813,10 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
break;
case AST_FRAME_DTMF_END:
if (chan->audiohooks) {
- struct ast_frame *new_frame = fr;
-
- new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
- if (new_frame != fr) {
- ast_frfree(new_frame);
- }
+ struct ast_frame *old_frame = fr;
+ fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
+ if (old_frame != fr)
+ f = fr;
}
ast_clear_flag(chan, AST_FLAG_BLOCKING);
ast_channel_unlock(chan);
@@ -2896,6 +2845,13 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
if (chan->tech->write == NULL)
break; /*! \todo XXX should return 0 maybe ? */
+ if (chan->audiohooks) {
+ struct ast_frame *old_frame = fr;
+ fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
+ if (old_frame != fr)
+ f2 = fr;
+ }
+
/* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
if (fr->subclass == chan->rawwriteformat)
f = fr;
@@ -2908,82 +2864,37 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
break;
}
- if (chan->audiohooks) {
- struct ast_frame *new_frame, *cur;
-
- for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
- new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur);
- if (new_frame != cur) {
- ast_frfree(new_frame);
- }
- }
- }
-
/* If Monitor is running on this channel, then we have to write frames out there too */
- /* the translator on chan->writetrans may have returned multiple frames
- from the single frame we passed in; if so, feed each one of them to the
- monitor */
if (chan->monitor && chan->monitor->write_stream) {
- struct ast_frame *cur;
-
- for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
/* XXX must explain this code */
#ifndef MONITOR_CONSTANT_DELAY
- int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples;
- if (jump >= 0) {
- jump = chan->insmpl - chan->outsmpl;
- if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
- chan->outsmpl += jump + cur->samples;
- } else {
- chan->outsmpl += cur->samples;
- }
+ int jump = chan->insmpl - chan->outsmpl - 4 * f->samples;
+ if (jump >= 0) {
+ jump = chan->insmpl - chan->outsmpl;
+ if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
+ ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
+ chan->outsmpl += jump + f->samples;
+ } else
+ chan->outsmpl += f->samples;
#else
- int jump = chan->insmpl - chan->outsmpl;
- if (jump - MONITOR_DELAY >= 0) {
- if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1)
- ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
- chan->outsmpl += jump;
- } else {
- chan->outsmpl += cur->samples;
- }
+ int jump = chan->insmpl - chan->outsmpl;
+ if (jump - MONITOR_DELAY >= 0) {
+ if (ast_seekstream(chan->monitor->write_stream, jump - f->samples, SEEK_FORCECUR) == -1)
+ ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
+ chan->outsmpl += jump;
+ } else
+ chan->outsmpl += f->samples;
#endif
- if (chan->monitor->state == AST_MONITOR_RUNNING) {
- if (ast_writestream(chan->monitor->write_stream, cur) < 0)
- ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
- }
+ if (chan->monitor->state == AST_MONITOR_RUNNING) {
+ if (ast_writestream(chan->monitor->write_stream, f) < 0)
+ ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
}
}
- /* the translator on chan->writetrans may have returned multiple frames
- from the single frame we passed in; if so, feed each one of them to the
- channel, freeing each one after it has been written */
- if ((f != fr) && AST_LIST_NEXT(f, frame_list)) {
- struct ast_frame *cur, *next;
- unsigned int skip = 0;
-
- for (cur = f, next = AST_LIST_NEXT(cur, frame_list);
- cur;
- cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) {
- if (!skip) {
- if ((res = chan->tech->write(chan, cur)) < 0) {
- chan->_softhangup |= AST_SOFTHANGUP_DEV;
- skip = 1;
- } else if (next) {
- /* don't do this for the last frame in the list,
- as the code outside the loop will do it once
- */
- chan->fout = FRAMECOUNT_INC(chan->fout);
- }
- }
- ast_frfree(cur);
- }
-
- /* reset f so the code below doesn't attempt to free it */
- f = NULL;
- } else {
- res = chan->tech->write(chan, f);
- }
+ if (f)
+ res = chan->tech->write(chan,f);
+ else
+ res = 0;
break;
case AST_FRAME_NULL:
case AST_FRAME_IAX:
@@ -3000,12 +2911,13 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
if (f && f != fr)
ast_frfree(f);
+ if (f2)
+ ast_frfree(f2);
ast_clear_flag(chan, AST_FLAG_BLOCKING);
-
/* Consider a write failure to force a soft hangup */
- if (res < 0) {
+ if (res < 0)
chan->_softhangup |= AST_SOFTHANGUP_DEV;
- } else {
+ else {
chan->fout = FRAMECOUNT_INC(chan->fout);
}
done:
diff --git a/main/file.c b/main/file.c
index 43a7030f7..faca5a9be 100644
--- a/main/file.c
+++ b/main/file.c
@@ -203,20 +203,14 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
struct ast_frame *trf;
fs->lastwriteformat = f->subclass;
/* Get the translated frame but don't consume the original in case they're using it on another stream */
- if ((trf = ast_translate(fs->trans, f, 0))) {
- struct ast_frame *cur;
-
- /* the translator may have returned multiple frames, so process them */
- for (cur = trf; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
- if ((res = fs->fmt->write(fs, trf))) {
- ast_log(LOG_WARNING, "Translated frame write failed\n");
- break;
- }
- }
+ trf = ast_translate(fs->trans, f, 0);
+ if (trf) {
+ res = fs->fmt->write(fs, trf);
ast_frfree(trf);
- } else {
+ if (res)
+ ast_log(LOG_WARNING, "Translated frame write failed\n");
+ } else
res = 0;
- }
}
}
return res;
diff --git a/main/frame.c b/main/frame.c
index 253bc0536..58e0762eb 100644
--- a/main/frame.c
+++ b/main/frame.c
@@ -47,6 +47,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/dsp.h"
#include "asterisk/file.h"
+#ifdef TRACE_FRAMES
+static int headers;
+static AST_LIST_HEAD_STATIC(headerlist, ast_frame);
+#endif
+
#if !defined(LOW_MEMORY)
static void frame_cache_cleanup(void *data);
@@ -286,7 +291,7 @@ struct ast_frame *ast_smoother_read(struct ast_smoother *s)
memmove(s->data, s->data + len, s->len);
if (!ast_tvzero(s->delivery)) {
/* If we have delivery time, increment it, otherwise, leave it at 0 */
- s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, ast_format_rate(s->format)));
+ s->delivery = ast_tvadd(s->delivery, ast_samp2tv(s->f.samples, 8000));
}
}
/* Return frame */
@@ -323,6 +328,12 @@ static struct ast_frame *ast_frame_header_new(void)
#endif
f->mallocd_hdr_len = sizeof(*f);
+#ifdef TRACE_FRAMES
+ AST_LIST_LOCK(&headerlist);
+ headers++;
+ AST_LIST_INSERT_HEAD(&headerlist, f, frame_list);
+ AST_LIST_UNLOCK(&headerlist);
+#endif
return f;
}
@@ -340,7 +351,7 @@ static void frame_cache_cleanup(void *data)
}
#endif
-static void __frame_free(struct ast_frame *fr, int cache)
+void ast_frame_free(struct ast_frame *fr, int cache)
{
if (ast_test_flag(fr, AST_FRFLAG_FROM_TRANSLATOR)) {
ast_translate_frame_freed(fr);
@@ -359,8 +370,8 @@ static void __frame_free(struct ast_frame *fr, int cache)
* to keep things simple... */
struct ast_frame_cache *frames;
- if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) &&
- (frames->size < FRAME_CACHE_MAX_SIZE)) {
+ if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))
+ && frames->size < FRAME_CACHE_MAX_SIZE) {
AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list);
frames->size++;
return;
@@ -374,25 +385,19 @@ static void __frame_free(struct ast_frame *fr, int cache)
}
if (fr->mallocd & AST_MALLOCD_SRC) {
if (fr->src)
- free((void *)fr->src);
+ free((char *)fr->src);
}
if (fr->mallocd & AST_MALLOCD_HDR) {
+#ifdef TRACE_FRAMES
+ AST_LIST_LOCK(&headerlist);
+ headers--;
+ AST_LIST_REMOVE(&headerlist, fr, frame_list);
+ AST_LIST_UNLOCK(&headerlist);
+#endif
free(fr);
}
}
-
-void ast_frame_free(struct ast_frame *frame, int cache)
-{
- struct ast_frame *next;
-
- for (next = AST_LIST_NEXT(frame, frame_list);
- frame;
- frame = next, next = frame ? AST_LIST_NEXT(frame, frame_list) : NULL) {
- __frame_free(frame, cache);
- }
-}
-
/*!
* \brief 'isolates' a frame by duplicating non-malloc'ed components
* (header, src, data).
@@ -403,29 +408,19 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
struct ast_frame *out;
void *newdata;
- /* if none of the existing frame is malloc'd, let ast_frdup() do it
- since it is more efficient
- */
- if (fr->mallocd == 0) {
- return ast_frdup(fr);
- }
-
- /* if everything is already malloc'd, we are done */
- if ((fr->mallocd & (AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) ==
- (AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA)) {
- return fr;
- }
+ ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
+ ast_clear_flag(fr, AST_FRFLAG_FROM_DSP);
if (!(fr->mallocd & AST_MALLOCD_HDR)) {
/* Allocate a new header if needed */
- if (!(out = ast_frame_header_new())) {
+ if (!(out = ast_frame_header_new()))
return NULL;
- }
out->frametype = fr->frametype;
out->subclass = fr->subclass;
out->datalen = fr->datalen;
out->samples = fr->samples;
out->offset = fr->offset;
+ out->data = fr->data;
/* Copy the timing data */
ast_copy_flags(out, fr, AST_FRFLAG_HAS_TIMING_INFO);
if (ast_test_flag(fr, AST_FRFLAG_HAS_TIMING_INFO)) {
@@ -433,34 +428,26 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
out->len = fr->len;
out->seqno = fr->seqno;
}
- } else {
- ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
- ast_clear_flag(fr, AST_FRFLAG_FROM_DSP);
- ast_clear_flag(fr, AST_FRFLAG_FROM_FILESTREAM);
+ } else
out = fr;
- }
- if (!(fr->mallocd & AST_MALLOCD_SRC) && fr->src) {
- if (!(out->src = ast_strdup(fr->src))) {
- if (out != fr) {
- free(out);
+ if (!(fr->mallocd & AST_MALLOCD_SRC)) {
+ if (fr->src) {
+ if (!(out->src = ast_strdup(fr->src))) {
+ if (out != fr)
+ free(out);
+ return NULL;
}
- return NULL;
}
- } else {
+ } else
out->src = fr->src;
- fr->src = NULL;
- fr->mallocd &= ~AST_MALLOCD_SRC;
- }
if (!(fr->mallocd & AST_MALLOCD_DATA)) {
if (!(newdata = ast_malloc(fr->datalen + AST_FRIENDLY_OFFSET))) {
- if (out->src != fr->src) {
+ if (out->src != fr->src)
free((void *) out->src);
- }
- if (out != fr) {
+ if (out != fr)
free(out);
- }
return NULL;
}
newdata += AST_FRIENDLY_OFFSET;
@@ -468,10 +455,6 @@ struct ast_frame *ast_frisolate(struct ast_frame *fr)
out->datalen = fr->datalen;
memcpy(newdata, fr->data, fr->datalen);
out->data = newdata;
- } else {
- out->data = fr->data;
- fr->data = NULL;
- fr->mallocd &= ~AST_MALLOCD_DATA;
}
out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;
@@ -514,7 +497,7 @@ struct ast_frame *ast_frdup(const struct ast_frame *f)
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END;
+ AST_LIST_TRAVERSE_SAFE_END
}
#endif
@@ -987,6 +970,29 @@ void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix)
}
+#ifdef TRACE_FRAMES
+static int show_frame_stats(int fd, int argc, char *argv[])
+{
+ struct ast_frame *f;
+ int x=1;
+ if (argc != 4)
+ return RESULT_SHOWUSAGE;
+ AST_LIST_LOCK(&headerlist);
+ ast_cli(fd, " Framer Statistics \n");
+ ast_cli(fd, "---------------------------\n");
+ ast_cli(fd, "Total allocated headers: %d\n", headers);
+ ast_cli(fd, "Queue Dump:\n");
+ AST_LIST_TRAVERSE(&headerlist, f, frame_list)
+ ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
+ AST_LIST_UNLOCK(&headerlist);
+ return RESULT_SUCCESS;
+}
+
+static char frame_stats_usage[] =
+"Usage: core show frame stats\n"
+" Displays debugging statistics from framer\n";
+#endif
+
/* Builtin Asterisk CLI-commands for debugging */
static struct ast_cli_entry cli_show_codecs = {
{ "show", "codecs", NULL },
@@ -1013,6 +1019,13 @@ static struct ast_cli_entry cli_show_codec = {
show_codec_n_deprecated, NULL,
NULL };
+#ifdef TRACE_FRAMES
+static struct ast_cli_entry cli_show_frame_stats = {
+ { "show", "frame", "stats", NULL },
+ show_frame_stats, NULL,
+ NULL };
+#endif
+
static struct ast_cli_entry my_clis[] = {
{ { "core", "show", "codecs", NULL },
show_codecs, "Displays a list of codecs",
@@ -1033,6 +1046,12 @@ static struct ast_cli_entry my_clis[] = {
{ { "core", "show", "codec", NULL },
show_codec_n, "Shows a specific codec",
frame_show_codec_n_usage, NULL, &cli_show_codec },
+
+#ifdef TRACE_FRAMES
+ { { "core", "show", "frame", "stats", NULL },
+ show_frame_stats, "Shows frame statistics",
+ frame_stats_usage, NULL, &cli_show_frame_stats },
+#endif
};
int init_framer(void)
diff --git a/main/slinfactory.c b/main/slinfactory.c
index b848fb074..212edef92 100644
--- a/main/slinfactory.c
+++ b/main/slinfactory.c
@@ -57,7 +57,7 @@ void ast_slinfactory_destroy(struct ast_slinfactory *sf)
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
{
struct ast_frame *begin_frame = f, *duped_frame = NULL, *frame_ptr;
- unsigned int x = 0;
+ unsigned int x;
/* In some cases, we can be passed a frame which has no data in it, but
* which has a positive number of samples defined. Once such situation is
@@ -84,33 +84,27 @@ int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
}
}
- if (!(begin_frame = ast_translate(sf->trans, f, 0))) {
+ if (!(begin_frame = ast_translate(sf->trans, f, 0)))
return 0;
- }
- if (!(duped_frame = ast_frisolate(begin_frame))) {
- return 0;
- }
+ duped_frame = ast_frdup(begin_frame);
- if (duped_frame != begin_frame) {
- ast_frfree(begin_frame);
- }
+ ast_frfree(begin_frame);
+
+ if (!duped_frame)
+ return 0;
} else {
if (!(duped_frame = ast_frdup(f)))
return 0;
}
- AST_LIST_TRAVERSE(&sf->queue, frame_ptr, frame_list) {
+ x = 0;
+ AST_LIST_TRAVERSE(&sf->queue, frame_ptr, frame_list)
x++;
- }
- /* if the frame was translated, the translator may have returned multiple
- frames, so process each of them
- */
- for (begin_frame = duped_frame; begin_frame; begin_frame = AST_LIST_NEXT(begin_frame, frame_list)) {
- AST_LIST_INSERT_TAIL(&sf->queue, begin_frame, frame_list);
- sf->size += begin_frame->samples;
- }
+ AST_LIST_INSERT_TAIL(&sf->queue, duped_frame, frame_list);
+
+ sf->size += duped_frame->samples;
return x;
}