aboutsummaryrefslogtreecommitdiffstats
path: root/testing/asterisk-dongle/issue46.patch
blob: 1bc0056e9d2bde50802e212cf144813182726744 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Issue 46 from asterisk-chan-dongle bug tracker

Fixes to build with Asterisk 10+

http://asterisk-chan-dongle.googlecode.com/issues/attachment?aid=460006000&name=patch3.patch.txt&token=VQW7Irk8LNc422UzWgcczezUNaY%3A1341828783939

--- a/chan_dongle_o.c	2011-11-23 14:04:57.270633822 +0200
+++ b/chan_dongle.c	2011-11-23 14:07:05.740251209 +0200
@@ -43,6 +43,7 @@
 #include <asterisk.h>
 ASTERISK_FILE_VERSION(__FILE__, "$Rev: " PACKAGE_REVISION " $")
 
+#include <asterisk/version.h>
 #include <asterisk/stringfields.h>	/* AST_DECLARE_STRING_FIELDS for asterisk/manager.h */
 #include <asterisk/manager.h>
 #include <asterisk/dsp.h>
@@ -71,6 +72,8 @@
 
 EXPORT_DEF const char * const dev_state_strs[4] = { "stop", "restart", "remove", "start" };
 EXPORT_DEF public_state_t * gpublic;
+EXPORT_DEF struct ast_format chan_dongle_format;
+EXPORT_DEF struct ast_format_cap * chan_dongle_format_cap;
 
 
 static int public_state_init(struct public_state * state);
@@ -1640,6 +1643,16 @@
 		rv = AST_MODULE_LOAD_FAILURE;
 		if(discovery_restart(state) == 0)
 		{
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+			/* set preferred capabilities */
+		        ast_format_set(&chan_dongle_format, AST_FORMAT_SLINEAR, 0);
+		        if (!(channel_tech.capabilities = ast_format_cap_alloc())) {
+                		return AST_MODULE_LOAD_FAILURE;
+		        }
+		        ast_format_cap_add(channel_tech.capabilities, &chan_dongle_format);
+			chan_dongle_format_cap = channel_tech.capabilities;
+#endif
+
 			/* register our channel type */
 			if(ast_channel_register(&channel_tech) == 0)
 			{
@@ -1652,6 +1665,9 @@
 			}
 			else
 			{
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+				channel_tech.capabilities = ast_format_cap_destroy(channel_tech.capabilities);
+#endif
 				ast_log (LOG_ERROR, "Unable to register channel class %s\n", channel_tech.type);
 			}
 			discovery_stop(state);
@@ -1679,6 +1695,9 @@
 {
 	/* First, take us out of the channel loop */
 	ast_channel_unregister (&channel_tech);
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+	channel_tech.capabilities = ast_format_cap_destroy(channel_tech.capabilities);
+#endif
 
 	/* Unregister the CLI & APP & MANAGER */
 
--- a/han_dongle_o.h	2011-11-23 14:05:35.031639222 +0200
+++ b/chan_dongle.h	2011-11-23 14:06:24.608334634 +0200
@@ -33,6 +33,9 @@
 	return enum2str(state, states, ITEMS_OF(states));
 }
 
+/* Only linear is allowed */
+EXPORT_DECL struct ast_format chan_dongle_format;
+EXPORT_DECL struct ast_format_cap * chan_dongle_format_cap;
 
 typedef enum {
 	RESTATE_TIME_NOW	= 0,
--- a/channel_o.c	2011-11-23 14:05:08.279344414 +0200
+++ b/channel.c	2011-11-23 14:06:24.610334645 +0200
@@ -95,20 +95,24 @@
 	return 0;
 }
 
-#if ASTERISK_VERSION_NUM >= 10800
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+
+static struct ast_channel * channel_request (attribute_unused const char * type, struct ast_format_cap * cap, const struct ast_channel *requestor, void * data, int * cause)
+
+#elif ASTERISK_VERSION_NUM >= 10800 /* 1.8+ */
 //   TODO: simplify by move common code to functions
 static struct ast_channel * channel_request (attribute_unused const char * type, format_t format, const struct ast_channel * requestor, void * data, int * cause)
 
-#else /* #if ASTERISK_VERSION_NUM >= 10800 */
+#else /* 1.8- */
 /* TODO: add check when request 'holdother' what requestor is not on same device for 1.6 */
 
 static struct ast_channel * channel_request (attribute_unused const char * type, int format, void * data, int * cause)
 
-#endif /* #if ASTERISK_VERSION_NUM >= 10800 */
+#endif
 {
-#if ASTERISK_VERSION_NUM >= 10800
+#if ASTERISK_VERSION_NUM >= 10800 && ASTERISK_VERSION_NUM < 100000 /* 1.8+ .. 10- */
 	format_t oldformat;
-#else
+#elif ASTERISK_VERSION_NUM < 10800 /* 1.8- */
 	int oldformat;
 	const struct ast_channel * requestor = NULL;
 #endif
@@ -126,11 +130,18 @@
 		return NULL;
 	}
 
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+	if (!ast_format_cap_iscompatible(cap, &chan_dongle_format))
+#else
 	oldformat = format;
 	format &= AST_FORMAT_SLINEAR;
 	if (!format)
+#endif
 	{
-#if ASTERISK_VERSION_NUM >= 10800
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+		char buf[255];
+		ast_log (LOG_WARNING, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple (buf, 255, cap));
+#elif ASTERISK_VERSION_NUM >= 10800 /* 1.8+ */
 		ast_log (LOG_WARNING, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname (oldformat));
 #else
 		ast_log (LOG_WARNING, "Asked to get a channel of unsupported format '%d'\n", oldformat);
@@ -571,10 +582,12 @@
 
 }
 
-#if ASTERISK_VERSION_NUM >= 10800
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+#define subclass_integer	subclass.integer
+#elif ASTERISK_VERSION_NUM >= 10800 /* 1.8+ */
 #define subclass_codec		subclass.codec
 #define subclass_integer	subclass.integer
-#else
+#else /* 1.8- */
 #define subclass_codec		subclass
 #define subclass_integer	subclass
 #endif
@@ -618,7 +631,11 @@
 		memset (&cpvt->a_read_frame, 0, sizeof (cpvt->a_read_frame));
 
 		cpvt->a_read_frame.frametype = AST_FRAME_VOICE;
-		cpvt->a_read_frame.subclass_codec= AST_FORMAT_SLINEAR;
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+		ast_format_copy(&cpvt->a_read_frame.subclass.format, &chan_dongle_format);
+#else
+		cpvt->a_read_frame.subclass_codec = AST_FORMAT_SLINEAR;
+#endif
 		cpvt->a_read_frame.data.ptr = cpvt->a_read_buf + AST_FRIENDLY_OFFSET;
 		cpvt->a_read_frame.offset = AST_FRIENDLY_OFFSET;
 		cpvt->a_read_frame.src = AST_MODULE;
@@ -732,7 +749,11 @@
 	size_t count;
 	int gains[2];
 
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+	if (f->frametype != AST_FRAME_VOICE || f->subclass.format.id != AST_FORMAT_SLINEAR)
+#else /* 10- */
 	if (f->frametype != AST_FRAME_VOICE || f->subclass_codec != AST_FORMAT_SLINEAR)
+#endif
 	{
 		return 0;
 	}
@@ -1148,9 +1169,15 @@
 
 			channel->tech_pvt	= cpvt;
 			channel->tech		= &channel_tech;
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+			ast_format_cap_add(channel->nativeformats, &chan_dongle_format);
+			ast_format_copy(&channel->writeformat, &chan_dongle_format);
+			ast_format_copy(&channel->readformat, &chan_dongle_format);
+#else /* 10- */
 			channel->nativeformats	= AST_FORMAT_SLINEAR;
 			channel->writeformat	= AST_FORMAT_SLINEAR;
 			channel->readformat	= AST_FORMAT_SLINEAR;
+#endif
 
 			if (ast_state == AST_STATE_RING)
 			{
@@ -1238,9 +1265,11 @@
 
 	snprintf (channel_name, sizeof (channel_name), "%s@%s", exten, CONF_SHARED(pvt, context));
 
-#if ASTERISK_VERSION_NUM >= 10800
+#if ASTERISK_VERSION_NUM >= 100000 /* 10+ */
+	channel = ast_request ("Local", chan_dongle_format_cap, NULL, channel_name, &cause);
+#elif ASTERISK_VERSION_NUM >= 10800 /* 1.8+ */
 	channel = ast_request ("Local", AST_FORMAT_AUDIO_MASK, NULL, channel_name, &cause);
-#else
+#else /* 1.8- */
 	channel = ast_request ("Local", AST_FORMAT_AUDIO_MASK, channel_name, &cause);
 #endif
 	if (channel)
@@ -1314,7 +1343,6 @@
 static int channel_func_write(struct ast_channel* channel, const char* function, char* data, const char* value)
 {
 	struct cpvt* cpvt = channel->tech_pvt;
-	struct pvt* pvt;
 	call_state_t newstate, oldstate;
 	int ret = 0;
 
@@ -1323,7 +1351,6 @@
 		ast_log (LOG_WARNING, "call on unreferenced %s\n", channel->name);
 		return -1;
 	}
-	pvt = cpvt->pvt;
 
 	if (!strcasecmp(data, "callstate"))
 	{
@@ -1366,11 +1393,13 @@
 	return ret;
 }
 
-EXPORT_DEF const struct ast_channel_tech channel_tech =
+EXPORT_DEF struct ast_channel_tech channel_tech =
 {
 	.type			= "Dongle",
 	.description		= MODULE_DESCRIPTION,
+#if ASTERISK_VERSION_NUM < 100000 /* 10- */
 	.capabilities		= AST_FORMAT_SLINEAR,
+#endif
 	.requester		= channel_request,
 	.call			= channel_call,
 	.hangup			= channel_hangup,
--- a/channel_o.h	2011-11-23 14:05:43.206424916 +0200
+++ b/channel.h	2011-11-23 14:06:24.611334658 +0200
@@ -19,7 +19,7 @@
 struct pvt;
 struct cpvt;
 
-EXPORT_DECL const struct ast_channel_tech channel_tech;
+EXPORT_DECL struct ast_channel_tech channel_tech;
 
 EXPORT_DECL struct ast_channel* new_channel (struct pvt * pvt, int ast_state, const char * cid_num, int call_idx, unsigned dir, unsigned state, const char * exten, const struct ast_channel * requestor);
 EXPORT_DECL int queue_control_channel (struct cpvt * cpvt, enum ast_control_frame_type control);