Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


mod_format.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Header for providers of file and format handling routines.
21  * Clients of these routines should include "asterisk/file.h" instead.
22  */
23 
24 #ifndef _ASTERISK_MOD_FORMAT_H
25 #define _ASTERISK_MOD_FORMAT_H
26 
27 #include "asterisk/file.h"
28 #include "asterisk/frame.h"
29 
30 #if defined(__cplusplus) || defined(c_plusplus)
31 extern "C" {
32 #endif
33 
34 /*! \brief
35  * Each supported file format is described by the following structure.
36  *
37  * Not all are necessary, the support routine implement default
38  * values for some of them.
39  * A handler typically fills a structure initializing the desired
40  * fields, and then calls ast_format_register() with the (readonly)
41  * structure as an argument.
42  */
43 struct ast_format {
44  char name[80]; /*!< Name of format */
45  char exts[80]; /*!< Extensions (separated by | if more than one)
46  this format can read. First is assumed for writing (e.g. .mp3) */
47  format_t format; /*!< Format of frames it uses/provides (one only) */
48  /*!
49  * \brief Prepare an input stream for playback.
50  * \return 0 on success, -1 on error.
51  * The FILE is already open (in s->f) so this function only needs to perform
52  * any applicable validity checks on the file. If none is required, the
53  * function can be omitted.
54  */
55  int (*open)(struct ast_filestream *s);
56  /*!
57  * \brief Prepare a stream for output, and comment it appropriately if applicable.
58  * \return 0 on success, -1 on error.
59  * Same as the open, the FILE is already open so the function just needs to
60  * prepare any header and other fields, if any.
61  * The function can be omitted if nothing is needed.
62  */
63  int (*rewrite)(struct ast_filestream *s, const char *comment);
64  /*! Write a frame to a channel */
65  int (*write)(struct ast_filestream *, struct ast_frame *);
66  /*! seek num samples into file, whence - like a normal seek but with offset in samples */
67  int (*seek)(struct ast_filestream *, off_t, int);
68  int (*trunc)(struct ast_filestream *fs); /*!< trunc file to current position */
69  off_t (*tell)(struct ast_filestream *fs); /*!< tell current position */
70  /*! Read the next frame from the filestream (if available) and report
71  * when to get next frame (in samples)
72  */
73  struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
74  /*! Do any closing actions, if any. The descriptor and structure are closed
75  * and destroyed by the generic routines, so they must not be done here. */
76  void (*close)(struct ast_filestream *);
77  char * (*getcomment)(struct ast_filestream *); /*!< Retrieve file comment */
78 
80 
81  /*!
82  * If the handler needs a buffer (for read, typically)
83  * and/or a private descriptor, put here the
84  * required size (in bytes) and the support routine will allocate them
85  * for you, pointed by s->buf and s->private, respectively.
86  * When allocating a buffer, remember to leave AST_FRIENDLY_OFFSET
87  * spare bytes at the bginning.
88  */
89  int buf_size; /*!< size of frame buffer, if any, aligned to 8 bytes. */
90  int desc_size; /*!< size of private descriptor, if any */
91 
92  struct ast_module *module;
93 };
94 
95 /*! \brief
96  * This structure is allocated by file.c in one chunk,
97  * together with buf_size and desc_size bytes of memory
98  * to be used for private purposes (e.g. buffers etc.)
99  */
101  /*! Everybody reserves a block of AST_RESERVED_POINTERS pointers for us */
102  struct ast_format *fmt; /* need to write to the lock and usecnt */
103  int flags;
104  mode_t mode;
106  char *filename;
108  /*! Video file stream */
109  struct ast_filestream *vfs;
110  /*! Transparently translate from another format -- just once */
112  struct ast_tranlator_pvt *tr;
116  FILE *f;
117  struct ast_frame fr; /*!< frame produced by read, typically */
118  char *buf; /*!< buffer pointed to by ast_frame; */
119  void *_private; /*!< pointer to private buffer */
120  const char *orig_chan_name;
122 };
123 
124 /*!
125  * \brief Register a new file format capability.
126  * Adds a format to Asterisk's format abilities.
127  * \retval 0 on success
128  * \retval -1 on failure
129  */
130 int __ast_format_register(const struct ast_format *f, struct ast_module *mod);
131 #define ast_format_register(f) __ast_format_register(f, ast_module_info->self)
132 
133 /*!
134  * \brief Unregisters a file format
135  * \param name the name of the format you wish to unregister
136  * Unregisters a format based on the name of the format.
137  * \retval 0 on success
138  * \retval -1 on failure to unregister
139  */
140 int ast_format_unregister(const char *name);
141 
142 #if defined(__cplusplus) || defined(c_plusplus)
143 }
144 #endif
145 
146 #endif /* _ASTERISK_MOD_FORMAT_H */
off_t(* tell)(struct ast_filestream *fs)
Definition: mod_format.h:69
Main Channel structure associated with a channel.
Definition: channel.h:742
int buf_size
Definition: mod_format.h:89
int(* write)(struct ast_filestream *, struct ast_frame *)
Definition: mod_format.h:65
int(* rewrite)(struct ast_filestream *s, const char *comment)
Prepare a stream for output, and comment it appropriately if applicable.
Definition: mod_format.h:63
Each supported file format is described by the following structure.
Definition: mod_format.h:43
char * realfilename
Definition: mod_format.h:107
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
struct ast_tranlator_pvt * tr
Definition: mod_format.h:112
char exts[80]
Definition: mod_format.h:45
char * write_buffer
Definition: mod_format.h:121
format_t format
Definition: mod_format.h:47
char * open_filename
Definition: mod_format.h:105
Asterisk internal frame definitions.
const char * orig_chan_name
Definition: mod_format.h:120
struct ast_format * fmt
Definition: mod_format.h:102
void * _private
Definition: mod_format.h:119
int ast_format_unregister(const char *name)
Unregisters a file format.
Definition: file.c:104
struct ast_format::@189 list
char name[80]
Definition: mod_format.h:44
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:135
int64_t format_t
Definition: frame_defs.h:32
struct ast_channel * owner
Definition: mod_format.h:115
int __ast_format_register(const struct ast_format *f, struct ast_module *mod)
Register a new file format capability. Adds a format to Asterisk&#39;s format abilities.
Definition: file.c:67
#define comment
Definition: ael_lex.c:961
int(* open)(struct ast_filestream *s)
Prepare an input stream for playback.
Definition: mod_format.h:55
void(* close)(struct ast_filestream *)
Definition: mod_format.h:76
struct ast_trans_pvt * trans
Definition: mod_format.h:111
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
static struct ast_format f[]
Definition: format_g726.c:181
struct ast_module * module
Definition: mod_format.h:92
char * filename
Definition: mod_format.h:106
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition: mod_format.h:100
int(* seek)(struct ast_filestream *, off_t, int)
Definition: mod_format.h:67
int desc_size
Definition: mod_format.h:90
Data structure associated with a single frame of data.
Definition: frame.h:142
struct ast_filestream * vfs
Definition: mod_format.h:109
int(* trunc)(struct ast_filestream *fs)
Definition: mod_format.h:68