aboutsummaryrefslogtreecommitdiffstats
path: root/frame.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>1999-11-21 02:26:43 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>1999-11-21 02:26:43 +0000
commit4c63f091a4767fbd5c0cefed92446a1a184065d0 (patch)
tree5d6ff7a3fa451a38d36e8e29c76e2ad73910b110 /frame.c
parentb3f95b5b13bd294be77c0cbe0a807c565ef568b0 (diff)
Version 0.1.0 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@65 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'frame.c')
-rwxr-xr-xframe.c89
1 files changed, 89 insertions, 0 deletions
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 <markster@linux-support.net>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <asterisk/frame.h>
+#include <asterisk/logger.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * 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;
+}