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...

Defines

#define ast_format_def_register(f)   __ast_format_def_register(f, ast_module_info->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.
int ast_format_def_unregister (const char *name)
 Unregisters a file format.


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.


Define Documentation

#define ast_format_def_register ( f   )     __ast_format_def_register(f, ast_module_info->self)

Definition at line 131 of file mod_format.h.

Referenced by load_module().


Function Documentation

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:
0 on success
-1 on failure

Definition at line 125 of file file.c.

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::module, ast_format_def::name, publish_format_update(), and tmp().

00126 {
00127    struct ast_format_def *tmp;
00128 
00129    AST_RWLIST_WRLOCK(&formats);
00130    AST_RWLIST_TRAVERSE(&formats, tmp, list) {
00131       if (!strcasecmp(f->name, tmp->name)) {
00132          AST_RWLIST_UNLOCK(&formats);
00133          ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
00134          return -1;
00135       }
00136    }
00137    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00138       AST_RWLIST_UNLOCK(&formats);
00139       return -1;
00140    }
00141    *tmp = *f;
00142    tmp->module = mod;
00143    if (tmp->buf_size) {
00144       /*
00145        * Align buf_size properly, rounding up to the machine-specific
00146        * alignment for pointers.
00147        */
00148       struct _test_align { void *a, *b; } p;
00149       int align = (char *)&p.b - (char *)&p.a;
00150       tmp->buf_size = ((f->buf_size + align - 1) / align) * align;
00151    }
00152 
00153    memset(&tmp->list, 0, sizeof(tmp->list));
00154 
00155    AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
00156    AST_RWLIST_UNLOCK(&formats);
00157    ast_verb(2, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
00158    publish_format_update(f, ast_format_register_type());
00159 
00160    return 0;
00161 }

int ast_format_def_unregister ( const char *  name  ) 

Unregisters a file format.

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

Definition at line 163 of file file.c.

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, ast_format_def::name, publish_format_update(), and tmp().

Referenced by unload_module().

00164 {
00165    struct ast_format_def *tmp;
00166    int res = -1;
00167 
00168    AST_RWLIST_WRLOCK(&formats);
00169    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
00170       if (!strcasecmp(name, tmp->name)) {
00171          AST_RWLIST_REMOVE_CURRENT(list);
00172          publish_format_update(tmp, ast_format_unregister_type());
00173          ast_free(tmp);
00174          res = 0;
00175       }
00176    }
00177    AST_RWLIST_TRAVERSE_SAFE_END;
00178    AST_RWLIST_UNLOCK(&formats);
00179 
00180    if (!res)
00181       ast_verb(2, "Unregistered format %s\n", name);
00182    else
00183       ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
00184 
00185    return res;
00186 }


Generated on Thu Apr 16 06:32:01 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6