forked from traud/asterisk-amr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_amr.patch
116 lines (111 loc) · 2.87 KB
/
codec_amr.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--- include/asterisk/format_cache.h (Asterisk 13.10.0)
+++ include/asterisk/format_cache.h (working copy)
@@ -226,2 +226,12 @@
/*!
+ * \brief Built-in cached AMR format.
+ */
+extern struct ast_format *ast_format_amr;
+
+/*!
+ * \brief Built-in cached AMR-WB format.
+ */
+extern struct ast_format *ast_format_amrwb;
+
+/*!
* \brief Initialize format cache support within the core.
--- main/codec_builtin.c (Asterisk 13.10.0)
+++ main/codec_builtin.c (working copy)
@@ -774,2 +774,50 @@
+static int amr_samples(struct ast_frame *frame)
+{
+ return 160;
+}
+
+static int amr_length(unsigned int samples)
+{
+ ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 8;
+}
+
+static struct ast_codec amr = {
+ .name = "amr",
+ .description = "AMR",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 8000,
+ .minimum_ms = 20,
+ .maximum_ms = 20,
+ .default_ms = 20,
+ .minimum_bytes = 0, /* no smooth */
+ .samples_count = amr_samples,
+ .get_length = amr_length,
+ .smooth = 0,
+};
+
+static int amrwb_samples(struct ast_frame *frame)
+{
+ return 320;
+}
+
+static int amrwb_length(unsigned int samples)
+{
+ ast_log(LOG_NOTICE, "untested; please report failure or success: %u\n", samples); return samples / 16;
+}
+
+static struct ast_codec amrwb = {
+ .name = "amrwb",
+ .description = "AMR-WB",
+ .type = AST_MEDIA_TYPE_AUDIO,
+ .sample_rate = 16000,
+ .minimum_ms = 20,
+ .maximum_ms = 20,
+ .default_ms = 20,
+ .minimum_bytes = 0, /* no smooth */
+ .samples_count = amrwb_samples,
+ .get_length = amrwb_length,
+ .smooth = 0,
+};
+
#define CODEC_REGISTER_AND_CACHE(codec) \
@@ -806,2 +854,5 @@
+ res |= CODEC_REGISTER_AND_CACHE(amr);
+ res |= CODEC_REGISTER_AND_CACHE(amrwb);
+
res |= CODEC_REGISTER_AND_CACHE(g723);
--- main/format_cache.c (Asterisk 13.10.0)
+++ main/format_cache.c (working copy)
@@ -220,2 +220,12 @@
/*!
+ * \brief Built-in cached AMR format.
+ */
+struct ast_format *ast_format_amr;
+
+/*!
+ * \brief Built-in cached AMR-WB format.
+ */
+struct ast_format *ast_format_amrwb;
+
+/*!
* \brief Built-in cached t140 format.
@@ -294,2 +304,5 @@
+ ao2_replace(ast_format_amr, NULL);
+ ao2_replace(ast_format_amrwb, NULL);
+
ao2_replace(ast_format_g723, NULL);
@@ -406,2 +419,6 @@
ao2_replace(ast_format_opus, format);
+ } else if (!strcmp(name, "amr")) {
+ ao2_replace(ast_format_amr, format);
+ } else if (!strcmp(name, "amrwb")) {
+ ao2_replace(ast_format_amrwb, format);
} else if (!strcmp(name, "jpeg")) {
--- main/rtp_engine.c (Asterisk 13.10.0)
+++ main/rtp_engine.c (working copy)
@@ -2201,2 +2201,5 @@
+ set_next_mime_type(ast_format_amr, 0, "audio", "AMR", 8000);
+ set_next_mime_type(ast_format_amrwb, 0, "audio", "AMR-WB", 16000);
+
/* Define the static rtp payload mappings */
@@ -2244,2 +2247,5 @@
add_static_payload(107, ast_format_opus, 0);
+
+ add_static_payload(-1, ast_format_amr, 0);
+ add_static_payload(-1, ast_format_amrwb, 0);