Asterisk - The Open Source Telephony Project GIT-master-f36a736
main/format_compatibility.c
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/*! \file
20 *
21 * \brief Media Format Bitfield Compatibility API
22 *
23 * \author Joshua Colp <jcolp@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "asterisk/logger.h"
33#include "asterisk/astobj2.h"
34#include "asterisk/codec.h"
35#include "asterisk/format.h"
38
40{
42 return AST_FORMAT_G723;
43 } else if (ast_format_cmp(format, ast_format_gsm) == AST_FORMAT_CMP_EQUAL) {
44 return AST_FORMAT_GSM;
46 return AST_FORMAT_ULAW;
48 return AST_FORMAT_ALAW;
52 return AST_FORMAT_ADPCM;
54 return AST_FORMAT_SLIN;
56 return AST_FORMAT_LPC10;
58 return AST_FORMAT_G729;
60 return AST_FORMAT_SPEEX;
62 return AST_FORMAT_ILBC;
64 return AST_FORMAT_G726;
66 return AST_FORMAT_G722;
68 return AST_FORMAT_SIREN7;
70 return AST_FORMAT_SIREN14;
72 return AST_FORMAT_SLIN16;
74 return AST_FORMAT_G719;
76 return AST_FORMAT_SPEEX16;
78 return AST_FORMAT_OPUS;
80 return AST_FORMAT_H261;
82 return AST_FORMAT_H263;
84 return AST_FORMAT_H263P;
86 return AST_FORMAT_H264;
87 } else if (ast_format_cmp(format, ast_format_mp4) == AST_FORMAT_CMP_EQUAL) {
88 return AST_FORMAT_MP4;
89 } else if (ast_format_cmp(format, ast_format_vp8) == AST_FORMAT_CMP_EQUAL) {
90 return AST_FORMAT_VP8;
92 return AST_FORMAT_JPEG;
93 } else if (ast_format_cmp(format, ast_format_png) == AST_FORMAT_CMP_EQUAL) {
94 return AST_FORMAT_PNG;
98 return AST_FORMAT_T140;
99 }
100
101 return 0;
102}
103
105{
107 return AST_FORMAT_G723;
108 } else if (codec->id == ast_format_get_codec_id(ast_format_gsm)) {
109 return AST_FORMAT_GSM;
110 } else if (codec->id == ast_format_get_codec_id(ast_format_ulaw)) {
111 return AST_FORMAT_ULAW;
112 } else if (codec->id == ast_format_get_codec_id(ast_format_alaw)) {
113 return AST_FORMAT_ALAW;
114 } else if (codec->id == ast_format_get_codec_id(ast_format_g726_aal2)) {
116 } else if (codec->id == ast_format_get_codec_id(ast_format_adpcm)) {
117 return AST_FORMAT_ADPCM;
118 } else if (codec->id == ast_format_get_codec_id(ast_format_slin)) {
119 return AST_FORMAT_SLIN;
120 } else if (codec->id == ast_format_get_codec_id(ast_format_lpc10)) {
121 return AST_FORMAT_LPC10;
122 } else if (codec->id == ast_format_get_codec_id(ast_format_g729)) {
123 return AST_FORMAT_G729;
124 } else if (codec->id == ast_format_get_codec_id(ast_format_speex)) {
125 return AST_FORMAT_SPEEX;
126 } else if (codec->id == ast_format_get_codec_id(ast_format_ilbc)) {
127 return AST_FORMAT_ILBC;
128 } else if (codec->id == ast_format_get_codec_id(ast_format_g726)) {
129 return AST_FORMAT_G726;
130 } else if (codec->id == ast_format_get_codec_id(ast_format_g722)) {
131 return AST_FORMAT_G722;
132 } else if (codec->id == ast_format_get_codec_id(ast_format_siren7)) {
133 return AST_FORMAT_SIREN7;
134 } else if (codec->id == ast_format_get_codec_id(ast_format_siren14)) {
135 return AST_FORMAT_SIREN14;
136 } else if (codec->id == ast_format_get_codec_id(ast_format_slin16)) {
137 return AST_FORMAT_SLIN16;
138 } else if (codec->id == ast_format_get_codec_id(ast_format_g719)) {
139 return AST_FORMAT_G719;
140 } else if (codec->id == ast_format_get_codec_id(ast_format_speex16)) {
141 return AST_FORMAT_SPEEX16;
142 } else if (codec->id == ast_format_get_codec_id(ast_format_opus)) {
143 return AST_FORMAT_OPUS;
144 } else if (codec->id == ast_format_get_codec_id(ast_format_h261)) {
145 return AST_FORMAT_H261;
146 } else if (codec->id == ast_format_get_codec_id(ast_format_h263)) {
147 return AST_FORMAT_H263;
148 } else if (codec->id == ast_format_get_codec_id(ast_format_h263p)) {
149 return AST_FORMAT_H263P;
150 } else if (codec->id == ast_format_get_codec_id(ast_format_h264)) {
151 return AST_FORMAT_H264;
152 } else if (codec->id == ast_format_get_codec_id(ast_format_mp4)) {
153 return AST_FORMAT_MP4;
154 } else if (codec->id == ast_format_get_codec_id(ast_format_vp8)) {
155 return AST_FORMAT_VP8;
156 } else if (codec->id == ast_format_get_codec_id(ast_format_jpeg)) {
157 return AST_FORMAT_JPEG;
158 } else if (codec->id == ast_format_get_codec_id(ast_format_png)) {
159 return AST_FORMAT_PNG;
160 } else if (codec->id == ast_format_get_codec_id(ast_format_t140_red)) {
161 return AST_FORMAT_T140_RED;
162 } else if (codec->id == ast_format_get_codec_id(ast_format_t140)) {
163 return AST_FORMAT_T140;
164 }
165
166 return 0;
167}
168
170{
171 switch (bitfield) {
172 /*! G.723.1 compression */
173 case AST_FORMAT_G723:
174 return ast_format_g723;
175 /*! GSM compression */
176 case AST_FORMAT_GSM:
177 return ast_format_gsm;
178 /*! Raw mu-law data (G.711) */
179 case AST_FORMAT_ULAW:
180 return ast_format_ulaw;
181 /*! Raw A-law data (G.711) */
182 case AST_FORMAT_ALAW:
183 return ast_format_alaw;
184 /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
187 /*! ADPCM (IMA) */
188 case AST_FORMAT_ADPCM:
189 return ast_format_adpcm;
190 /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
191 case AST_FORMAT_SLIN:
192 return ast_format_slin;
193 /*! LPC10, 180 samples/frame */
194 case AST_FORMAT_LPC10:
195 return ast_format_lpc10;
196 /*! G.729A audio */
197 case AST_FORMAT_G729:
198 return ast_format_g729;
199 /*! SpeeX Free Compression */
200 case AST_FORMAT_SPEEX:
201 return ast_format_speex;
202 /*! iLBC Free Compression */
203 case AST_FORMAT_ILBC:
204 return ast_format_ilbc;
205 /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
206 case AST_FORMAT_G726:
207 return ast_format_g726;
208 /*! G.722 */
209 case AST_FORMAT_G722:
210 return ast_format_g722;
211 /*! G.722.1 (also known as Siren7, 32kbps assumed) */
213 return ast_format_siren7;
214 /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
216 return ast_format_siren14;
217 /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
219 return ast_format_slin16;
220 /*! G.719 (64 kbps assumed) */
221 case AST_FORMAT_G719:
222 return ast_format_g719;
223 /*! SpeeX Wideband (16kHz) Free Compression */
225 return ast_format_speex16;
226 /*! Opus audio (8kHz, 16kHz, 24kHz, 48Khz) */
227 case AST_FORMAT_OPUS:
228 return ast_format_opus;
229
230 /*! H.261 Video */
231 case AST_FORMAT_H261:
232 return ast_format_h261;
233 /*! H.263 Video */
234 case AST_FORMAT_H263:
235 return ast_format_h263;
236 /*! H.263+ Video */
237 case AST_FORMAT_H263P:
238 return ast_format_h263p;
239 /*! H.264 Video */
240 case AST_FORMAT_H264:
241 return ast_format_h264;
242 /*! MPEG4 Video */
243 case AST_FORMAT_MP4:
244 return ast_format_mp4;
245 /*! VP8 Video */
246 case AST_FORMAT_VP8:
247 return ast_format_vp8;
248
249 /*! JPEG Images */
250 case AST_FORMAT_JPEG:
251 return ast_format_jpeg;
252 /*! PNG Images */
253 case AST_FORMAT_PNG:
254 return ast_format_png;
255
256 /*! T.140 RED Text format RFC 4103 */
258 return ast_format_t140_red;
259 /*! T.140 Text format - ITU T.140, RFC 4103 */
260 case AST_FORMAT_T140:
261 return ast_format_t140;
262 }
263 return NULL;
264}
Asterisk main include file. File version handling, generic pbx functions.
Codec API.
Media Format API.
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
Media Format Cache API.
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:136
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:176
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:101
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_siren14
Built-in cached siren14 format.
Definition: format_cache.c:211
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:131
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:166
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:186
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:121
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:111
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:126
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:146
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
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_h261
Built-in cached h261 format.
Definition: format_cache.c:161
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:236
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:171
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:206
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:106
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:231
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:151
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:201
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:191
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:156
Media Format Bitfield Compatibility API.
Support for logging to various files, console and syslog Configuration in file logger....
uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format)
Convert a format structure to its respective bitfield.
struct ast_format * ast_format_compatibility_bitfield2format(uint64_t bitfield)
Convert a bitfield to its respective format structure.
uint64_t ast_format_compatibility_codec2bitfield(const struct ast_codec *codec)
Convert a codec structure to its respective bitfield.
#define NULL
Definition: resample.c:96
Represents a media codec within Asterisk.
Definition: codec.h:42
unsigned int id
Internal unique identifier for this codec, set at registration time (starts at 1)
Definition: codec.h:44
Definition of a media format.
Definition: format.c:43