From 53f8d43e2945038fe3059fd6c1c00dd4ec117505 Mon Sep 17 00:00:00 2001 From: russell 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: http://svn.digium.com/svn/asterisk/trunk@41278 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_milliwatt.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'apps/app_milliwatt.c') 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++) { -- cgit v1.2.3