2 * Asterisk -- A telephony toolkit for Linux.
4 * Frame manipulation routines
6 * Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 #include <asterisk/frame.h>
15 #include <asterisk/logger.h>
20 * Important: I should be made more efficient. Frame headers should
21 * most definitely be cached
24 void ast_frfree(struct ast_frame *fr)
26 if (fr->mallocd & AST_MALLOCD_DATA) {
28 free(fr->data - fr->offset);
30 if (fr->mallocd & AST_MALLOCD_SRC) {
34 if (fr->mallocd & AST_MALLOCD_HDR) {
39 void ast_frchain(struct ast_frame_chain *fc)
41 struct ast_frame_chain *last;
51 struct ast_frame *ast_frisolate(struct ast_frame *fr)
53 struct ast_frame *out;
54 if (!(fr->mallocd & AST_MALLOCD_HDR)) {
55 /* Allocate a new header if needed */
56 out = malloc(sizeof(struct ast_frame));
58 ast_log(LOG_WARNING, "Out of memory\n");
61 out->frametype = fr->frametype;
62 out->subclass = fr->subclass;
64 out->timelen = fr->timelen;
71 if (!(fr->mallocd & AST_MALLOCD_SRC)) {
73 out->src = strdup(fr->src);
76 if (!(fr->mallocd & AST_MALLOCD_DATA)) {
77 out->data = malloc(fr->datalen + fr->offset);
78 out->data += fr->offset;
79 out->offset = fr->offset;
80 out->datalen = fr->datalen;
81 memcpy(out->data, fr->data, fr->datalen);
83 ast_log(LOG_WARNING, "Out of memory\n");
87 out->mallocd = AST_MALLOCD_HDR | AST_MALLOCD_SRC | AST_MALLOCD_DATA;