Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Macros | Functions
mod_format.h File Reference

Header for providers of file and format handling routines. Clients of these routines should include "asterisk/file.h" instead. More...

#include "asterisk/file.h"
#include "asterisk/frame.h"
Include dependency graph for mod_format.h:
This graph shows which files directly or indirectly include this file:

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_def
 Each supported file format is described by the following structure. More...
 

Macros

#define ast_format_def_register(f)   __ast_format_def_register(f, AST_MODULE_SELF)
 

Functions

int __ast_format_def_register (const struct ast_format_def *f, struct ast_module *mod)
 Register a new file format capability. Adds a format to Asterisk's format abilities. More...
 
int ast_format_def_unregister (const char *name)
 Unregisters a file format. More...
 

Detailed Description

Header for providers of file and format handling routines. Clients of these routines should include "asterisk/file.h" instead.

Definition in file mod_format.h.

Macro Definition Documentation

◆ ast_format_def_register

#define ast_format_def_register (   f)    __ast_format_def_register(f, AST_MODULE_SELF)

Definition at line 136 of file mod_format.h.

Function Documentation

◆ __ast_format_def_register()

int __ast_format_def_register ( const struct ast_format_def f,
struct ast_module mod 
)

Register a new file format capability. Adds a format to Asterisk's format abilities.

Return values
0on success
-1on failure

Definition at line 124 of file file.c.

125{
126 struct ast_format_def *tmp;
127
130 if (!strcasecmp(f->name, tmp->name)) {
132 ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
133 return -1;
134 }
135 }
136 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
138 return -1;
139 }
140 *tmp = *f;
141 tmp->module = mod;
142 if (tmp->buf_size) {
143 /*
144 * Align buf_size properly, rounding up to the machine-specific
145 * alignment for pointers.
146 */
147 struct _test_align { void *a, *b; } p;
148 int align = (char *)&p.b - (char *)&p.a;
149 tmp->buf_size = ((f->buf_size + align - 1) / align) * align;
150 }
151
152 memset(&tmp->list, 0, sizeof(tmp->list));
153
156 ast_verb(5, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
158
159 return 0;
160}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
static int publish_format_update(const struct ast_format_def *f, struct stasis_message_type *type)
Definition: file.c:93
struct stasis_message_type * ast_format_register_type(void)
Get the message type used for signaling a format registration.
#define ast_verb(level,...)
#define LOG_WARNING
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
Each supported file format is described by the following structure.
Definition: mod_format.h:43
char name[80]
Definition: mod_format.h:44
struct ast_format_def::@239 list
char exts[80]
Definition: mod_format.h:45
Definition: file.c:69
static struct test_val b
static struct test_val a

References a, ast_calloc, ast_format_register_type(), ast_log, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, b, ast_format_def::buf_size, ast_format_def::exts, ast_format_def::list, LOG_WARNING, ast_format_def::name, publish_format_update(), and tmp().

◆ ast_format_def_unregister()

int ast_format_def_unregister ( const char *  name)

Unregisters a file format.

Parameters
namethe name of the format you wish to unregister Unregisters a format based on the name of the format.
Return values
0on success
-1on failure to unregister

Definition at line 162 of file file.c.

163{
164 struct ast_format_def *tmp;
165 int res = -1;
166
169 if (!strcasecmp(name, tmp->name)) {
172 ast_free(tmp);
173 res = 0;
174 }
175 }
178
179 if (!res)
180 ast_verb(5, "Unregistered format %s\n", name);
181 else
182 ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
183
184 return res;
185}
#define ast_free(a)
Definition: astmm.h:180
struct stasis_message_type * ast_format_unregister_type(void)
Get the message type used for signaling a format unregistration.
static const char name[]
Definition: format_mp3.c:68
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

References ast_format_unregister_type(), 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_def::list, LOG_WARNING, name, publish_format_update(), and tmp().

Referenced by unload_module().