Wed Jan 8 2020 09:50:15

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

Macros

#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. More...
 
int ast_format_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

#define ast_format_register (   f)    __ast_format_register(f, ast_module_info->self)

Definition at line 131 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
0on success
-1on failure

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

68 {
69  struct ast_format *tmp;
70 
73  if (!strcasecmp(f->name, tmp->name)) {
75  ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
76  return -1;
77  }
78  }
79  if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
81  return -1;
82  }
83  *tmp = *f;
84  tmp->module = mod;
85  if (tmp->buf_size) {
86  /*
87  * Align buf_size properly, rounding up to the machine-specific
88  * alignment for pointers.
89  */
90  struct _test_align { void *a, *b; } p;
91  int align = (char *)&p.b - (char *)&p.a;
92  tmp->buf_size = ((f->buf_size + align - 1) / align) * align;
93  }
94 
95  memset(&tmp->list, 0, sizeof(tmp->list));
96 
97  AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
99  ast_verb(2, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
100 
101  return 0;
102 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
int buf_size
Definition: mod_format.h:89
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Each supported file format is described by the following structure.
Definition: mod_format.h:43
#define ast_verb(level,...)
Definition: logger.h:243
char exts[80]
Definition: mod_format.h:45
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:703
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct ast_format::@189 list
char name[80]
Definition: mod_format.h:44
Definition: file.c:65
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct ast_format f[]
Definition: format_g726.c:181
struct ast_module * module
Definition: mod_format.h:92
#define ast_calloc(a, b)
Definition: astmm.h:82
int ast_format_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 104 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().

105 {
106  struct ast_format *tmp;
107  int res = -1;
108 
111  if (!strcasecmp(name, tmp->name)) {
113  ast_free(tmp);
114  res = 0;
115  }
116  }
119 
120  if (!res)
121  ast_verb(2, "Unregistered format %s\n", name);
122  else
123  ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
124 
125  return res;
126 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Each supported file format is described by the following structure.
Definition: mod_format.h:43
#define ast_verb(level,...)
Definition: logger.h:243
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
struct ast_format::@189 list
char name[80]
Definition: mod_format.h:44
Definition: file.c:65
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const char name[]
#define ast_free(a)
Definition: astmm.h:97
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602