#include "asterisk/file.h"
#include "asterisk/frame.h"
Go to the source code of this file.
Data Structures | |
struct | ast_filestream |
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of memory to be used for private purposes (e.g. buffers etc.). More... | |
struct | ast_format |
Each supported file format is described by the following structure. More... | |
Defines | |
#define | ast_format_register(f) __ast_format_register(f, ast_module_info->self) |
Functions | |
int | __ast_format_register (const struct ast_format *f, struct ast_module *mod) |
Register a new file format capability. Adds a format to Asterisk's format abilities. | |
int | ast_format_unregister (const char *name) |
Unregisters a file format. |
Definition in file mod_format.h.
#define ast_format_register | ( | f | ) | __ast_format_register(f, ast_module_info->self) |
int __ast_format_register | ( | const struct ast_format * | f, | |
struct ast_module * | mod | |||
) |
Register a new file format capability. Adds a format to Asterisk's format abilities.
0 | on success | |
-1 | on failure |
Definition at line 60 of file file.c.
References ast_calloc, ast_log(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_format::buf_size, ast_format::exts, f, ast_format::list, LOG_WARNING, ast_format::module, and ast_format::name.
00061 { 00062 struct ast_format *tmp; 00063 00064 AST_RWLIST_WRLOCK(&formats); 00065 AST_RWLIST_TRAVERSE(&formats, tmp, list) { 00066 if (!strcasecmp(f->name, tmp->name)) { 00067 AST_RWLIST_UNLOCK(&formats); 00068 ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name); 00069 return -1; 00070 } 00071 } 00072 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00073 AST_RWLIST_UNLOCK(&formats); 00074 return -1; 00075 } 00076 *tmp = *f; 00077 tmp->module = mod; 00078 if (tmp->buf_size) { 00079 /* 00080 * Align buf_size properly, rounding up to the machine-specific 00081 * alignment for pointers. 00082 */ 00083 struct _test_align { void *a, *b; } p; 00084 int align = (char *)&p.b - (char *)&p.a; 00085 tmp->buf_size = ((f->buf_size + align - 1) / align) * align; 00086 } 00087 00088 memset(&tmp->list, 0, sizeof(tmp->list)); 00089 00090 AST_RWLIST_INSERT_HEAD(&formats, tmp, list); 00091 AST_RWLIST_UNLOCK(&formats); 00092 ast_verb(2, "Registered file format %s, extension(s) %s\n", f->name, f->exts); 00093 00094 return 0; 00095 }
int ast_format_unregister | ( | const char * | name | ) |
Unregisters a file format.
name | the name of the format you wish to unregister Unregisters a format based on the name of the format. |
0 | on success | |
-1 | on failure to unregister |
Definition at line 97 of file file.c.
References ast_free, ast_log(), AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_format::list, LOG_WARNING, and ast_format::name.
Referenced by unload_module().
00098 { 00099 struct ast_format *tmp; 00100 int res = -1; 00101 00102 AST_RWLIST_WRLOCK(&formats); 00103 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) { 00104 if (!strcasecmp(name, tmp->name)) { 00105 AST_RWLIST_REMOVE_CURRENT(list); 00106 ast_free(tmp); 00107 res = 0; 00108 } 00109 } 00110 AST_RWLIST_TRAVERSE_SAFE_END; 00111 AST_RWLIST_UNLOCK(&formats); 00112 00113 if (!res) 00114 ast_verb(2, "Unregistered format %s\n", name); 00115 else 00116 ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name); 00117 00118 return res; 00119 }