Fri Jun 19 12:10:42 2009

Asterisk developer's documentation


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"

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.


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_register ( f   )     __ast_format_register(f, ast_module_info->self)

Definition at line 130 of file mod_format.h.

Referenced by load_module().


Function Documentation

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.

Return values:
0 on success
-1 on failure

Definition at line 61 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.

00062 {
00063    struct ast_format *tmp;
00064 
00065    AST_RWLIST_WRLOCK(&formats);
00066    AST_RWLIST_TRAVERSE(&formats, tmp, list) {
00067       if (!strcasecmp(f->name, tmp->name)) {
00068          AST_RWLIST_UNLOCK(&formats);
00069          ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
00070          return -1;
00071       }
00072    }
00073    if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
00074       AST_RWLIST_UNLOCK(&formats);
00075       return -1;
00076    }
00077    *tmp = *f;
00078    tmp->module = mod;
00079    if (tmp->buf_size) {
00080       /*
00081        * Align buf_size properly, rounding up to the machine-specific
00082        * alignment for pointers.
00083        */
00084       struct _test_align { void *a, *b; } p;
00085       int align = (char *)&p.b - (char *)&p.a;
00086       tmp->buf_size = ((f->buf_size + align - 1) / align) * align;
00087    }
00088    
00089    memset(&tmp->list, 0, sizeof(tmp->list));
00090 
00091    AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
00092    AST_RWLIST_UNLOCK(&formats);
00093    ast_verb(2, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
00094 
00095    return 0;
00096 }

int ast_format_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 98 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().

00099 {
00100    struct ast_format *tmp;
00101    int res = -1;
00102 
00103    AST_RWLIST_WRLOCK(&formats);
00104    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
00105       if (!strcasecmp(name, tmp->name)) {
00106          AST_RWLIST_REMOVE_CURRENT(list);
00107          ast_free(tmp);
00108          res = 0;
00109       }
00110    }
00111    AST_RWLIST_TRAVERSE_SAFE_END;
00112    AST_RWLIST_UNLOCK(&formats);
00113 
00114    if (!res)
00115       ast_verb(2, "Unregistered format %s\n", name);
00116    else
00117       ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
00118 
00119    return res;
00120 }


Generated on Fri Jun 19 12:10:42 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7