From f7e7161607512ae516d4a3976048e2f0d29e5449 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Tue, 29 Aug 2006 20:50:36 +0000 Subject: Merge team/russell/frame_caching There are some situations in Asterisk where ast_frame and/or iax_frame structures are rapidly allocatted and freed (at least 50 times per second for one call). This code significantly improves the performance of ast_frame_header_new(), ast_frdup(), ast_frfree(), iax_frame_new(), and iax_frame_free() by keeping a thread-local cache of these structures and using frames from the cache whenever possible instead of calling malloc/free every time. This commit also converts the ast_frame and iax_frame structures to use the linked list macros. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@41278 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_milliwatt.c | 17 +++++++---------- apps/app_mixmonitor.c | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'apps') diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c index 08a96f96b..8b0456014 100644 --- a/apps/app_milliwatt.c +++ b/apps/app_milliwatt.c @@ -66,10 +66,16 @@ static void milliwatt_release(struct ast_channel *chan, void *data) static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples) { - struct ast_frame wf; unsigned char buf[AST_FRIENDLY_OFFSET + 640]; const int maxsamples = sizeof (buf) / sizeof (buf[0]); int i, *indexp = (int *) data; + struct ast_frame wf = { + .frametype = AST_FRAME_VOICE, + .subclass = AST_FORMAT_ULAW, + .offset = AST_FRIENDLY_OFFSET, + .data = buf + AST_FRIENDLY_OFFSET, + .src = __FUNCTION__, + }; /* Instead of len, use samples, because channel.c generator_force * generate(chan, tmp, 0, 160) ignores len. In any case, len is @@ -82,17 +88,8 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples = maxsamples; } len = samples * sizeof (buf[0]); - wf.frametype = AST_FRAME_VOICE; - wf.subclass = AST_FORMAT_ULAW; - wf.offset = AST_FRIENDLY_OFFSET; - wf.mallocd = 0; - wf.data = buf + AST_FRIENDLY_OFFSET; wf.datalen = len; wf.samples = samples; - wf.src = "app_milliwatt"; - wf.delivery.tv_sec = 0; - wf.delivery.tv_usec = 0; - wf.prev = wf.next = NULL; /* create a buffer containing the digital milliwatt pattern */ for(i = 0; i < len; i++) { diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c index 2aaf7d6a8..aa7602f65 100644 --- a/apps/app_mixmonitor.c +++ b/apps/app_mixmonitor.c @@ -191,7 +191,7 @@ static void *mixmonitor_thread(void *obj) of frames if a queue flush was necessary, so process them */ for (; f; f = next) { - next = f->next; + next = AST_LIST_NEXT(f, frame_list); if (write) ast_writestream(mixmonitor->fs, f); ast_frfree(f); -- cgit v1.2.3