Asterisk - The Open Source Telephony Project  18.5.0
format_cache.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2014, Digium, Inc.
5  *
6  * Joshua Colp <[email protected]>
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 /*!
20  * \file
21  * \brief Media Format Cache API
22  *
23  * \author Joshua Colp <[email protected]>
24  */
25 
26 #ifndef _AST_FORMAT_CACHE_H_
27 #define _AST_FORMAT_CACHE_H_
28 
29 struct ast_format;
30 
31 /*!
32  * \brief Built-in cached signed linear 8kHz format.
33  */
34 extern struct ast_format *ast_format_slin;
35 
36 /*!
37  * \brief Built-in cached signed linear 12kHz format.
38  */
39 extern struct ast_format *ast_format_slin12;
40 
41 /*!
42  * \brief Built-in cached signed linear 16kHz format.
43  */
44 extern struct ast_format *ast_format_slin16;
45 
46 /*!
47  * \brief Built-in cached signed linear 24kHz format.
48  */
49 extern struct ast_format *ast_format_slin24;
50 
51 /*!
52  * \brief Built-in cached signed linear 32kHz format.
53  */
54 extern struct ast_format *ast_format_slin32;
55 
56 /*!
57  * \brief Built-in cached signed linear 44kHz format.
58  */
59 extern struct ast_format *ast_format_slin44;
60 
61 /*!
62  * \brief Built-in cached signed linear 48kHz format.
63  */
64 extern struct ast_format *ast_format_slin48;
65 
66 /*!
67  * \brief Built-in cached signed linear 96kHz format.
68  */
69 extern struct ast_format *ast_format_slin96;
70 
71 /*!
72  * \brief Built-in cached signed linear 192kHz format.
73  */
74 extern struct ast_format *ast_format_slin192;
75 
76 /*!
77  * \brief Built-in cached ulaw format.
78  */
79 extern struct ast_format *ast_format_ulaw;
80 
81 /*!
82  * \brief Built-in cached alaw format.
83  */
84 extern struct ast_format *ast_format_alaw;
85 
86 /*!
87  * \brief Built-in cached testlaw format.
88  */
89 extern struct ast_format *ast_format_testlaw;
90 
91 /*!
92  * \brief Built-in cached gsm format.
93  */
94 extern struct ast_format *ast_format_gsm;
95 
96 /*!
97  * \brief Built-in cached adpcm format.
98  */
99 extern struct ast_format *ast_format_adpcm;
100 
101 /*!
102  * \brief Built-in cached g722 format.
103  */
104 extern struct ast_format *ast_format_g722;
105 
106 /*!
107  * \brief Built-in cached g726 format.
108  */
109 extern struct ast_format *ast_format_g726;
110 
111 /*!
112  * \brief Built-in cached g726 aal2 format.
113  */
114 extern struct ast_format *ast_format_g726_aal2;
115 
116 /*!
117  * \brief Built-in cached ilbc format.
118  */
119 extern struct ast_format *ast_format_ilbc;
120 
121 /*!
122  * \brief Built-in cached ilbc format.
123  */
124 extern struct ast_format *ast_format_lpc10;
125 
126 /*!
127  * \brief Built-in cached speex format.
128  */
129 extern struct ast_format *ast_format_speex;
130 
131 /*!
132  * \brief Built-in cached speex at 16kHz format.
133  */
134 extern struct ast_format *ast_format_speex16;
135 
136 /*!
137  * \brief Built-in cached speex at 32kHz format.
138  */
139 extern struct ast_format *ast_format_speex32;
140 
141 /*!
142  * \brief Built-in cached g723.1 format.
143  */
144 extern struct ast_format *ast_format_g723;
145 
146 /*!
147  * \brief Built-in cached g729 format.
148  */
149 extern struct ast_format *ast_format_g729;
150 
151 /*!
152  * \brief Built-in cached g719 format.
153  */
154 extern struct ast_format *ast_format_g719;
155 
156 /*!
157  * \brief Built-in cached h261 format.
158  */
159 extern struct ast_format *ast_format_h261;
160 
161 /*!
162  * \brief Built-in cached h263 format.
163  */
164 extern struct ast_format *ast_format_h263;
165 
166 /*!
167  * \brief Built-in cached h263 plus format.
168  */
169 extern struct ast_format *ast_format_h263p;
170 
171 /*!
172  * \brief Built-in cached h264 format.
173  */
174 extern struct ast_format *ast_format_h264;
175 
176 /*!
177  * \brief Built-in cached h265 format.
178  */
179 extern struct ast_format *ast_format_h265;
180 
181 /*!
182  * \brief Built-in cached mp4 format.
183  */
184 extern struct ast_format *ast_format_mp4;
185 
186 /*!
187  * \brief Built-in cached vp8 format.
188  */
189 extern struct ast_format *ast_format_vp8;
190 
191 /*!
192  * \brief Built-in cached vp9 format.
193  */
194 extern struct ast_format *ast_format_vp9;
195 
196 /*!
197  * \brief Built-in cached jpeg format.
198  */
199 extern struct ast_format *ast_format_jpeg;
200 
201 /*!
202  * \brief Built-in cached png format.
203  */
204 extern struct ast_format *ast_format_png;
205 
206 /*!
207  * \brief Built-in cached siren14 format.
208  */
209 extern struct ast_format *ast_format_siren14;
210 
211 /*!
212  * \brief Built-in cached siren7 format.
213  */
214 extern struct ast_format *ast_format_siren7;
215 
216 /*!
217  * \brief Built-in cached opus format.
218  */
219 extern struct ast_format *ast_format_opus;
220 
221 /*!
222  * \brief Built-in cached Codec 2 format.
223  */
224 extern struct ast_format *ast_format_codec2;
225 
226 /*!
227  * \brief Built-in cached t140 format.
228  */
229 extern struct ast_format *ast_format_t140;
230 
231 /*!
232  * \brief Built-in cached t140 red format.
233  */
234 extern struct ast_format *ast_format_t140_red;
235 
236 /*!
237  * \brief Built-in cached T.38 format.
238  */
239 extern struct ast_format *ast_format_t38;
240 
241 /*!
242  * \brief Built-in "null" format.
243  */
244 extern struct ast_format *ast_format_none;
245 
246 /*!
247  * \brief Built-in SILK format.
248  */
249 extern struct ast_format *ast_format_silk8;
250 extern struct ast_format *ast_format_silk12;
251 extern struct ast_format *ast_format_silk16;
252 extern struct ast_format *ast_format_silk24;
253 
254 /*!
255  * \brief Initialize format cache support within the core.
256  *
257  * \retval 0 success
258  * \retval -1 failure
259  */
260 int ast_format_cache_init(void);
261 
262 /*!
263  * \brief Set a named format cache entry.
264  *
265  * \param format A pointer to the format to cache
266  *
267  * \retval 0 success
268  * \retval -1 failure
269  */
271 
272 /*!
273  * \brief Retrieve a named format from the cache.
274  *
275  * \param name Name of the cached format
276  *
277  * \retval non-NULL if found
278  * \retval NULL if not found
279  *
280  * \note The returned format has its reference count incremented. It must be
281  * dropped using ao2_ref or ao2_cleanup.
282  */
283 struct ast_format *__ast_format_cache_get(const char *name,
284  const char *tag, const char *file, int line, const char *func);
285 
286 #define ast_format_cache_get(name) \
287  __ast_format_cache_get((name), "ast_format_cache_get", __FILE__, __LINE__, __PRETTY_FUNCTION__)
288 #define ast_t_format_cache_get(name, tag) \
289  __ast_format_cache_get((name), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
290 
291 
292 /*!
293  * \brief Retrieve the best signed linear format given a sample rate.
294  *
295  * \param rate The sample rate
296  *
297  * \details
298  * This is a convenience function that returns one of the global
299  * ast_format_slinxxx formats.
300  *
301  * \return pointer to the signed linear format
302  *
303  * \note The returned format has NOT had its reference count incremented.
304  */
305 struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate);
306 
307 /*!
308  * \brief Determines if a format is one of the cached slin formats
309  *
310  * \param format The format to check
311  *
312  * \retval 0 if the format is not an SLIN format
313  * \retval 1 if the format is an SLIN format
314  */
316 
317 /*!
318  * \brief Retrieve a format from the cache by its codec
319  *
320  * \param codec The codec to search by
321  *
322  * \retval non-NULL if found
323  * \retval NULL if not found
324  *
325  * \note The returned format has its reference count incremented. It must be
326  * dropped using ao2_ref or ao2_cleanup.
327  */
329 
330 #endif /* _AST_FORMAT_CACHE_H */
struct ast_format * __ast_format_cache_get(const char *name, const char *tag, const char *file, int line, const char *func)
Retrieve a named format from the cache.
Definition: format_cache.c:510
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:196
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:116
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:151
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:216
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:191
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:241
struct ast_format * ast_format_cache_get_by_codec(const struct ast_codec *codec)
Retrieve a format from the cache by its codec.
Definition: format_cache.c:559
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
struct ast_format * ast_format_silk24
Definition: format_cache.c:259
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:206
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:121
Definition of a media format.
Definition: format.c:43
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
int ast_format_cache_init(void)
Initialize format cache support within the core.
Definition: format_cache.c:370
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:111
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:251
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:166
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:161
struct ast_format * ast_format_silk12
Definition: format_cache.c:257
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:176
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:131
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46
int ast_format_cache_set(struct ast_format *format)
Set a named format cache entry.
Definition: format_cache.c:482
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:226
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:101
struct ast_format * ast_format_codec2
Built-in cached Codec 2 format.
Definition: format_cache.c:231
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:211
int ast_format_cache_is_slinear(struct ast_format *format)
Determines if a format is one of the cached slin formats.
Definition: format_cache.c:542
struct ast_format * ast_format_silk8
Built-in SILK format.
Definition: format_cache.c:256
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:136
struct ast_codec * codec
Pointer to the codec in use for this format.
Definition: format.c:47
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:201
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:181
struct ast_format * ast_format_testlaw
Built-in cached testlaw format.
Definition: format_cache.c:96
static const char name[]
Definition: cdr_mysql.c:74
struct ast_format * ast_format_silk16
Definition: format_cache.c:258
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:186
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:221
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:106
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:156
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:146
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:236
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
static snd_pcm_format_t format
Definition: chan_alsa.c:102
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:171
struct ast_format * ast_format_t38
Built-in cached T.38 format.
Definition: format_cache.c:246
Represents a media codec within Asterisk.
Definition: codec.h:42
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
Definition: format_cache.c:520
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:126