Asterisk - The Open Source Telephony Project  21.4.1
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"

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.

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

Definition at line 124 of file file.c.

References ast_calloc, ast_format_register_type(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_format_def::buf_size, ast_format_def::exts, ast_format_def::list, and ast_format_def::name.

125 {
126  struct ast_format_def *tmp;
127 
129  AST_RWLIST_TRAVERSE(&formats, tmp, list) {
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 
154  AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
156  ast_verb(5, "Registered file format %s, extension(s) %s\n", f->name, f->exts);
157  publish_format_update(f, ast_format_register_type());
158 
159  return 0;
160 }
char exts[80]
Definition: mod_format.h:45
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
Each supported file format is described by the following structure.
Definition: mod_format.h:43
struct ast_format_def::@237 list
Definition: file.c:69
struct stasis_message_type * ast_format_register_type(void)
Get the message type used for signaling a format registration.
char name[80]
Definition: mod_format.h:44
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
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.

References ast_format_unregister_type(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_format_def::name.

163 {
164  struct ast_format_def *tmp;
165  int res = -1;
166 
168  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
169  if (!strcasecmp(name, tmp->name)) {
170  AST_RWLIST_REMOVE_CURRENT(list);
171  publish_format_update(tmp, ast_format_unregister_type());
172  ast_free(tmp);
173  res = 0;
174  }
175  }
176  AST_RWLIST_TRAVERSE_SAFE_END;
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_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
Each supported file format is described by the following structure.
Definition: mod_format.h:43
struct ast_format_def::@237 list
struct stasis_message_type * ast_format_unregister_type(void)
Get the message type used for signaling a format unregistration.
Definition: file.c:69
char name[80]
Definition: mod_format.h:44
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151