From 42a21812e9b8808248ad246354f0813261e5f31d Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Sun, 21 Nov 1999 02:26:43 +0000 Subject: Version 0.1.0 from FTP git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@65 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- frame.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 frame.c (limited to 'frame.c') diff --git a/frame.c b/frame.c new file mode 100755 index 000000000..ba0e48e92 --- /dev/null +++ b/frame.c @@ -0,0 +1,89 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Frame manipulation routines + * + * Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC + * + * Mark Spencer + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include +#include +#include +#include + +/* + * Important: I should be made more efficient. Frame headers should + * most definitely be cached + */ + +void ast_frfree(struct ast_frame *fr) +{ + if (fr->mallocd & AST_MALLOCD_DATA) { + if (fr->data) + free(fr->data - fr->offset); + } + if (fr->mallocd & AST_MALLOCD_SRC) { + if (fr->src) + free(fr->src); + } + if (fr->mallocd & AST_MALLOCD_HDR) { + free(fr); + } +} + +void ast_frchain(struct ast_frame_chain *fc) +{ + struct ast_frame_chain *last; + while(fc) { + last = fc; + fc = fc->next; + if (last->fr) + ast_frfree(last->fr); + free(last); + } +} + +struct ast_frame *ast_frisolate(struct ast_frame *fr) +{ + struct ast_frame *out; + if (!(fr->mallocd & AST_MALLOCD_HDR)) { + /* Allocate a new header if needed */ + out = malloc(sizeof(struct ast_frame)); + if (!out) { + ast_log(LOG_WARNING, "Out of memory\n"); + return NULL; + } + out->frametype = fr->frametype; + out->subclass = fr->subclass; + out->datalen = 0; + out->timelen = fr->timelen; + out->offset = 0; + out->src = NULL; + out->data = NULL; + } else { + out = fr; + } + if (!(fr->mallocd & AST_MALLOCD_SRC)) { + if (fr->src) + out->src = strdup(fr->src); + } else + out->src = fr->src; + if (!(fr->mallocd & AST_MALLOCD_DATA)) { + out->data = malloc(fr->datalen + fr->offset); + out->data += fr->offset; + out->offset = fr->offset; + out->datalen = fr->datalen; + memcpy(out->data, fr->data, fr->datalen); + if (!out->data) { + ast_log(LOG_WARNING, "Out of memory\n"); + return NULL; + } + } + out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA; + return out; +} -- cgit v1.2.3