Debian Codegraph @

debian/patches/2012_amr_codec.patch

raw symbols SCIP
1 Description: integrate amr module with asterisk
2 Original patch adapted by Jonas Smedegaard to fit Debian packaging,
3 and to remove original patch file to help detect later upstream changes.
4 Author: Alexander Traud <[email protected]>
5 Author: Jonas Smedegaard <[email protected]>
6 Source: https://github.com/traud/asterisk-amr/blob/master/codec_amr.patch
7 Forwarded: not-needed
8 Last-Update: 2023-08-27
9 ---
10 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
11 --- a/include/asterisk/format_cache.h
12 +++ b/include/asterisk/format_cache.h
13 @@ -247,6 +247,16 @@
14 extern struct ast_format *ast_format_silk24;
15
16 /*!
17 + * \brief Built-in cached AMR format.
18 + */
19 +extern struct ast_format *ast_format_amr;
20 +
21 +/*!
22 + * \brief Built-in cached AMR-WB format.
23 + */
24 +extern struct ast_format *ast_format_amrwb;
25 +
26 +/*!
27 * \brief Initialize format cache support within the core.
28 *
29 * \retval 0 success
30 --- a/main/codec_builtin.c
31 +++ b/main/codec_builtin.c
32 @@ -925,6 +925,54 @@
33 .samples_count = silk_samples
34 };
35
36 +static int amr_samples(struct ast_frame *frame)
37 +{
38 + return 160;
39 +}
40 +
41 +static int amr_length(unsigned int samples)
42 +{
43 + ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 8;
44 +}
45 +
46 +static struct ast_codec amr = {
47 + .name = "amr",
48 + .description = "AMR",
49 + .type = AST_MEDIA_TYPE_AUDIO,
50 + .sample_rate = 8000,
51 + .minimum_ms = 20,
52 + .maximum_ms = 20,
53 + .default_ms = 20,
54 + .minimum_bytes = 0, /* no smooth */
55 + .samples_count = amr_samples,
56 + .get_length = amr_length,
57 + .smooth = 0,
58 +};
59 +
60 +static int amrwb_samples(struct ast_frame *frame)
61 +{
62 + return 320;
63 +}
64 +
65 +static int amrwb_length(unsigned int samples)
66 +{
67 + ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 16;
68 +}
69 +
70 +static struct ast_codec amrwb = {
71 + .name = "amrwb",
72 + .description = "AMR-WB",
73 + .type = AST_MEDIA_TYPE_AUDIO,
74 + .sample_rate = 16000,
75 + .minimum_ms = 20,
76 + .maximum_ms = 20,
77 + .default_ms = 20,
78 + .minimum_bytes = 0, /* no smooth */
79 + .samples_count = amrwb_samples,
80 + .get_length = amrwb_length,
81 + .smooth = 0,
82 +};
83 +
84 #define CODEC_REGISTER_AND_CACHE(codec) \
85 ({ \
86 int __res_ ## __LINE__ = 0; \
87 @@ -957,6 +1005,9 @@
88 {
89 int res = 0;
90
91 + res |= CODEC_REGISTER_AND_CACHE(amr);
92 + res |= CODEC_REGISTER_AND_CACHE(amrwb);
93 +
94 res |= CODEC_REGISTER_AND_CACHE(codec2);
95 res |= CODEC_REGISTER_AND_CACHE(g723);
96 res |= CODEC_REGISTER_AND_CACHE(ulaw);
97 --- a/main/format_cache.c
98 +++ b/main/format_cache.c
99 @@ -226,6 +226,16 @@
100 struct ast_format *ast_format_codec2;
101
102 /*!
103 + * \brief Built-in cached AMR format.
104 + */
105 +struct ast_format *ast_format_amr;
106 +
107 +/*!
108 + * \brief Built-in cached AMR-WB format.
109 + */
110 +struct ast_format *ast_format_amrwb;
111 +
112 +/*!
113 * \brief Built-in cached t140 format.
114 */
115 struct ast_format *ast_format_t140;
116 @@ -313,6 +323,9 @@
117 ao2_cleanup(formats);
118 formats = NULL;
119
120 + ao2_replace(ast_format_amr, NULL);
121 + ao2_replace(ast_format_amrwb, NULL);
122 +
123 ao2_replace(ast_format_g723, NULL);
124 ao2_replace(ast_format_ulaw, NULL);
125 ao2_replace(ast_format_alaw, NULL);
126 @@ -432,6 +445,10 @@
127 ao2_replace(ast_format_g719, format);
128 } else if (!strcmp(name, "opus")) {
129 ao2_replace(ast_format_opus, format);
130 + } else if (!strcmp(name, "amr")) {
131 + ao2_replace(ast_format_amr, format);
132 + } else if (!strcmp(name, "amrwb")) {
133 + ao2_replace(ast_format_amrwb, format);
134 } else if (!strcmp(name, "jpeg")) {
135 ao2_replace(ast_format_jpeg, format);
136 } else if (!strcmp(name, "png")) {
137 --- a/main/rtp_engine.c
138 +++ b/main/rtp_engine.c
139 @@ -3961,6 +3961,9 @@
140 set_next_mime_type(ast_format_vp8, 0, "video", "VP8", 90000);
141 set_next_mime_type(ast_format_vp9, 0, "video", "VP9", 90000);
142
143 + set_next_mime_type(ast_format_amr, 0, "audio", "AMR", 8000);
144 + set_next_mime_type(ast_format_amrwb, 0, "audio", "AMR-WB", 16000);
145 +
146 /* Define the static rtp payload mappings */
147 add_static_payload(0, ast_format_ulaw, 0);
148 #ifdef USE_DEPRECATED_G726
149 @@ -4004,6 +4007,9 @@
150 add_static_payload(109, ast_format_h265, 0);
151
152 add_static_payload(110, ast_format_speex, 0);
153 +
154 + add_static_payload(-1, ast_format_amr, 0);
155 + add_static_payload(-1, ast_format_amrwb, 0);
156 add_static_payload(111, ast_format_g726, 0);
157 add_static_payload(112, ast_format_g726_aal2, 0);
158
159 --- a/Xamr/codec_amr.patch
160 +++ /dev/null
161 @@ -1,116 +0,0 @@
162 ---- include/asterisk/format_cache.h (Asterisk 13.10.0)
163 -+++ include/asterisk/format_cache.h (working copy)
164 -@@ -226,2 +226,12 @@
165 - /*!
166 -+ * \brief Built-in cached AMR format.
167 -+ */
168 -+extern struct ast_format *ast_format_amr;
169 -+
170 -+/*!
171 -+ * \brief Built-in cached AMR-WB format.
172 -+ */
173 -+extern struct ast_format *ast_format_amrwb;
174 -+
175 -+/*!
176 - * \brief Initialize format cache support within the core.
177 ---- main/codec_builtin.c (Asterisk 13.10.0)
178 -+++ main/codec_builtin.c (working copy)
179 -@@ -774,2 +774,50 @@
180 -
181 -+static int amr_samples(struct ast_frame *frame)
182 -+{
183 -+ return 160;
184 -+}
185 -+
186 -+static int amr_length(unsigned int samples)
187 -+{
188 -+ ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 8;
189 -+}
190 -+
191 -+static struct ast_codec amr = {
192 -+ .name = "amr",
193 -+ .description = "AMR",
194 -+ .type = AST_MEDIA_TYPE_AUDIO,
195 -+ .sample_rate = 8000,
196 -+ .minimum_ms = 20,
197 -+ .maximum_ms = 20,
198 -+ .default_ms = 20,
199 -+ .minimum_bytes = 0, /* no smooth */
200 -+ .samples_count = amr_samples,
201 -+ .get_length = amr_length,
202 -+ .smooth = 0,
203 -+};
204 -+
205 -+static int amrwb_samples(struct ast_frame *frame)
206 -+{
207 -+ return 320;
208 -+}
209 -+
210 -+static int amrwb_length(unsigned int samples)
211 -+{
212 -+ ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 16;
213 -+}
214 -+
215 -+static struct ast_codec amrwb = {
216 -+ .name = "amrwb",
217 -+ .description = "AMR-WB",
218 -+ .type = AST_MEDIA_TYPE_AUDIO,
219 -+ .sample_rate = 16000,
220 -+ .minimum_ms = 20,
221 -+ .maximum_ms = 20,
222 -+ .default_ms = 20,
223 -+ .minimum_bytes = 0, /* no smooth */
224 -+ .samples_count = amrwb_samples,
225 -+ .get_length = amrwb_length,
226 -+ .smooth = 0,
227 -+};
228 -+
229 - #define CODEC_REGISTER_AND_CACHE(codec) \
230 -@@ -806,2 +854,5 @@
231 -
232 -+ res |= CODEC_REGISTER_AND_CACHE(amr);
233 -+ res |= CODEC_REGISTER_AND_CACHE(amrwb);
234 -+
235 - res |= CODEC_REGISTER_AND_CACHE(g723);
236 ---- main/format_cache.c (Asterisk 13.10.0)
237 -+++ main/format_cache.c (working copy)
238 -@@ -220,2 +220,12 @@
239 - /*!
240 -+ * \brief Built-in cached AMR format.
241 -+ */
242 -+struct ast_format *ast_format_amr;
243 -+
244 -+/*!
245 -+ * \brief Built-in cached AMR-WB format.
246 -+ */
247 -+struct ast_format *ast_format_amrwb;
248 -+
249 -+/*!
250 - * \brief Built-in cached t140 format.
251 -@@ -294,2 +304,5 @@
252 -
253 -+ ao2_replace(ast_format_amr, NULL);
254 -+ ao2_replace(ast_format_amrwb, NULL);
255 -+
256 - ao2_replace(ast_format_g723, NULL);
257 -@@ -406,2 +419,6 @@
258 - ao2_replace(ast_format_opus, format);
259 -+ } else if (!strcmp(name, "amr")) {
260 -+ ao2_replace(ast_format_amr, format);
261 -+ } else if (!strcmp(name, "amrwb")) {
262 -+ ao2_replace(ast_format_amrwb, format);
263 - } else if (!strcmp(name, "jpeg")) {
264 ---- main/rtp_engine.c (Asterisk 13.10.0)
265 -+++ main/rtp_engine.c (working copy)
266 -@@ -2201,2 +2201,5 @@
267 -
268 -+ set_next_mime_type(ast_format_amr, 0, "audio", "AMR", 8000);
269 -+ set_next_mime_type(ast_format_amrwb, 0, "audio", "AMR-WB", 16000);
270 -+
271 - /* Define the static rtp payload mappings */
272 -@@ -2244,2 +2247,5 @@
273 - add_static_payload(107, ast_format_opus, 0);
274 -+
275 -+ add_static_payload(-1, ast_format_amr, 0);
276 -+ add_static_payload(-1, ast_format_amrwb, 0);
277 -