Asterisk - The Open Source Telephony Project  GIT-master-b7027de
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 <jcolp@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 /*!
20  * \file
21  * \brief Media Format Cache API
22  *
23  * \author Joshua Colp <jcolp@digium.com>
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 gsm format.
88  */
89 extern struct ast_format *ast_format_gsm;
90 
91 /*!
92  * \brief Built-in cached adpcm format.
93  */
94 extern struct ast_format *ast_format_adpcm;
95 
96 /*!
97  * \brief Built-in cached g722 format.
98  */
99 extern struct ast_format *ast_format_g722;
100 
101 /*!
102  * \brief Built-in cached g726 format.
103  */
104 extern struct ast_format *ast_format_g726;
105 
106 /*!
107  * \brief Built-in cached g726 aal2 format.
108  */
109 extern struct ast_format *ast_format_g726_aal2;
110 
111 /*!
112  * \brief Built-in cached ilbc format.
113  */
114 extern struct ast_format *ast_format_ilbc;
115 
116 /*!
117  * \brief Built-in cached ilbc format.
118  */
119 extern struct ast_format *ast_format_lpc10;
120 
121 /*!
122  * \brief Built-in cached speex format.
123  */
124 extern struct ast_format *ast_format_speex;
125 
126 /*!
127  * \brief Built-in cached speex at 16kHz format.
128  */
129 extern struct ast_format *ast_format_speex16;
130 
131 /*!
132  * \brief Built-in cached speex at 32kHz format.
133  */
134 extern struct ast_format *ast_format_speex32;
135 
136 /*!
137  * \brief Built-in cached g723.1 format.
138  */
139 extern struct ast_format *ast_format_g723;
140 
141 /*!
142  * \brief Built-in cached g729 format.
143  */
144 extern struct ast_format *ast_format_g729;
145 
146 /*!
147  * \brief Built-in cached g719 format.
148  */
149 extern struct ast_format *ast_format_g719;
150 
151 /*!
152  * \brief Built-in cached h261 format.
153  */
154 extern struct ast_format *ast_format_h261;
155 
156 /*!
157  * \brief Built-in cached h263 format.
158  */
159 extern struct ast_format *ast_format_h263;
160 
161 /*!
162  * \brief Built-in cached h263 plus format.
163  */
164 extern struct ast_format *ast_format_h263p;
165 
166 /*!
167  * \brief Built-in cached h264 format.
168  */
169 extern struct ast_format *ast_format_h264;
170 
171 /*!
172  * \brief Built-in cached h265 format.
173  */
174 extern struct ast_format *ast_format_h265;
175 
176 /*!
177  * \brief Built-in cached mp4 format.
178  */
179 extern struct ast_format *ast_format_mp4;
180 
181 /*!
182  * \brief Built-in cached vp8 format.
183  */
184 extern struct ast_format *ast_format_vp8;
185 
186 /*!
187  * \brief Built-in cached vp9 format.
188  */
189 extern struct ast_format *ast_format_vp9;
190 
191 /*!
192  * \brief Built-in cached jpeg format.
193  */
194 extern struct ast_format *ast_format_jpeg;
195 
196 /*!
197  * \brief Built-in cached png format.
198  */
199 extern struct ast_format *ast_format_png;
200 
201 /*!
202  * \brief Built-in cached siren14 format.
203  */
204 extern struct ast_format *ast_format_siren14;
205 
206 /*!
207  * \brief Built-in cached siren7 format.
208  */
209 extern struct ast_format *ast_format_siren7;
210 
211 /*!
212  * \brief Built-in cached opus format.
213  */
214 extern struct ast_format *ast_format_opus;
215 
216 /*!
217  * \brief Built-in cached Codec 2 format.
218  */
219 extern struct ast_format *ast_format_codec2;
220 
221 /*!
222  * \brief Built-in cached t140 format.
223  */
224 extern struct ast_format *ast_format_t140;
225 
226 /*!
227  * \brief Built-in cached t140 red format.
228  */
229 extern struct ast_format *ast_format_t140_red;
230 
231 /*!
232  * \brief Built-in cached T.38 format.
233  */
234 extern struct ast_format *ast_format_t38;
235 
236 /*!
237  * \brief Built-in "null" format.
238  */
239 extern struct ast_format *ast_format_none;
240 
241 /*!
242  * \brief Built-in SILK format.
243  */
244 extern struct ast_format *ast_format_silk8;
245 extern struct ast_format *ast_format_silk12;
246 extern struct ast_format *ast_format_silk16;
247 extern struct ast_format *ast_format_silk24;
248 
249 /*!
250  * \brief Initialize format cache support within the core.
251  *
252  * \retval 0 success
253  * \retval -1 failure
254  */
255 int ast_format_cache_init(void);
256 
257 /*!
258  * \brief Set a named format cache entry.
259  *
260  * \param format A pointer to the format to cache
261  *
262  * \retval 0 success
263  * \retval -1 failure
264  */
266 
267 /*!
268  * \brief Retrieve a named format from the cache.
269  *
270  * \param name Name of the cached format
271  *
272  * \retval non-NULL if found
273  * \retval NULL if not found
274  *
275  * \note The returned format has its reference count incremented. It must be
276  * dropped using ao2_ref or ao2_cleanup.
277  */
278 struct ast_format *__ast_format_cache_get(const char *name,
279  const char *tag, const char *file, int line, const char *func);
280 
281 #define ast_format_cache_get(name) \
282  __ast_format_cache_get((name), "ast_format_cache_get", __FILE__, __LINE__, __PRETTY_FUNCTION__)
283 #define ast_t_format_cache_get(name, tag) \
284  __ast_format_cache_get((name), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
285 
286 
287 /*!
288  * \brief Retrieve the best signed linear format given a sample rate.
289  *
290  * \param rate The sample rate
291  *
292  * \details
293  * This is a convenience function that returns one of the global
294  * ast_format_slinxxx formats.
295  *
296  * \return pointer to the signed linear format
297  *
298  * \note The returned format has NOT had its reference count incremented.
299  */
300 struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate);
301 
302 /*!
303  * \brief Determines if a format is one of the cached slin formats
304  *
305  * \param format The format to check
306  *
307  * \retval 0 if the format is not an SLIN format
308  * \retval 1 if the format is an SLIN format
309  */
311 
312 /*!
313  * \brief Retrieve a format from the cache by its codec
314  *
315  * \param codec The codec to search by
316  *
317  * \retval non-NULL if found
318  * \retval NULL if not found
319  *
320  * \note The returned format has its reference count incremented. It must be
321  * dropped using ao2_ref or ao2_cleanup.
322  */
324 
325 #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:502
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:191
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:111
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:146
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:211
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:186
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:236
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:551
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:254
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:201
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
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:364
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:106
struct ast_format * ast_format_none
Built-in "null" format.
Definition: format_cache.c:246
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:161
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:156
struct ast_format * ast_format_silk12
Definition: format_cache.c:252
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:171
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:126
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:474
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:221
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:96
struct ast_format * ast_format_codec2
Built-in cached Codec 2 format.
Definition: format_cache.c:226
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:136
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:206
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:534
struct ast_format * ast_format_silk8
Built-in SILK format.
Definition: format_cache.c:251
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:131
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:196
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:176
static const char name[]
Definition: cdr_mysql.c:74
struct ast_format * ast_format_silk16
Definition: format_cache.c:253
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:181
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:216
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:101
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:151
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:231
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:166
struct ast_format * ast_format_t38
Built-in cached T.38 format.
Definition: format_cache.c:241
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:512
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:121