diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/conversation | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/conversation')
20 files changed, 5186 insertions, 5082 deletions
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h index 69f868e6c..0a9e2b5fb 100644 --- a/src/conversation/conversation.h +++ b/src/conversation/conversation.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file conversation/conversation.h | 22 | * @file conversation/conversation.h |
@@ -30,13 +30,13 @@ | |||
30 | #ifdef __cplusplus | 30 | #ifdef __cplusplus |
31 | extern "C" | 31 | extern "C" |
32 | { | 32 | { |
33 | #if 0 /* keep Emacsens' auto-indent happy */ | 33 | #if 0 /* keep Emacsens' auto-indent happy */ |
34 | } | 34 | } |
35 | #endif | 35 | #endif |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | 38 | ||
39 | #define MAX_TRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 39 | #define MAX_TRANSMIT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
@@ -44,7 +44,7 @@ extern "C" | |||
44 | * bit set if we are making an outgoing call, | 44 | * bit set if we are making an outgoing call, |
45 | * bit unset for local lines. | 45 | * bit unset for local lines. |
46 | */ | 46 | */ |
47 | #define HIGH_BIT ((uint32_t) (1LL << 31)) | 47 | #define HIGH_BIT ((uint32_t)(1LL << 31)) |
48 | 48 | ||
49 | GNUNET_NETWORK_STRUCT_BEGIN | 49 | GNUNET_NETWORK_STRUCT_BEGIN |
50 | 50 | ||
@@ -52,23 +52,20 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
52 | /** | 52 | /** |
53 | * Message to transmit the audio (between client and helpers). | 53 | * Message to transmit the audio (between client and helpers). |
54 | */ | 54 | */ |
55 | struct AudioMessage | 55 | struct AudioMessage { |
56 | { | ||
57 | /** | 56 | /** |
58 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO | 57 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO |
59 | */ | 58 | */ |
60 | struct GNUNET_MessageHeader header; | 59 | struct GNUNET_MessageHeader header; |
61 | 60 | ||
62 | /* followed by audio data */ | 61 | /* followed by audio data */ |
63 | |||
64 | }; | 62 | }; |
65 | 63 | ||
66 | 64 | ||
67 | /** | 65 | /** |
68 | * Client -> Service message to register a phone. | 66 | * Client -> Service message to register a phone. |
69 | */ | 67 | */ |
70 | struct ClientPhoneRegisterMessage | 68 | struct ClientPhoneRegisterMessage { |
71 | { | ||
72 | /** | 69 | /** |
73 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER | 70 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER |
74 | */ | 71 | */ |
@@ -89,8 +86,7 @@ struct ClientPhoneRegisterMessage | |||
89 | /** | 86 | /** |
90 | * Service -> Client message for phone is ringing. | 87 | * Service -> Client message for phone is ringing. |
91 | */ | 88 | */ |
92 | struct ClientPhoneRingMessage | 89 | struct ClientPhoneRingMessage { |
93 | { | ||
94 | /** | 90 | /** |
95 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING | 91 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING |
96 | */ | 92 | */ |
@@ -106,15 +102,13 @@ struct ClientPhoneRingMessage | |||
106 | * Who is calling us? | 102 | * Who is calling us? |
107 | */ | 103 | */ |
108 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; | 104 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; |
109 | |||
110 | }; | 105 | }; |
111 | 106 | ||
112 | 107 | ||
113 | /** | 108 | /** |
114 | * Service <-> Client message for phone was suspended. | 109 | * Service <-> Client message for phone was suspended. |
115 | */ | 110 | */ |
116 | struct ClientPhoneSuspendMessage | 111 | struct ClientPhoneSuspendMessage { |
117 | { | ||
118 | /** | 112 | /** |
119 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND | 113 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND |
120 | */ | 114 | */ |
@@ -125,15 +119,13 @@ struct ClientPhoneSuspendMessage | |||
125 | * talking about. | 119 | * talking about. |
126 | */ | 120 | */ |
127 | uint32_t cid GNUNET_PACKED; | 121 | uint32_t cid GNUNET_PACKED; |
128 | |||
129 | }; | 122 | }; |
130 | 123 | ||
131 | 124 | ||
132 | /** | 125 | /** |
133 | * Service <-> Client message for phone was resumed. | 126 | * Service <-> Client message for phone was resumed. |
134 | */ | 127 | */ |
135 | struct ClientPhoneResumeMessage | 128 | struct ClientPhoneResumeMessage { |
136 | { | ||
137 | /** | 129 | /** |
138 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME | 130 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME |
139 | */ | 131 | */ |
@@ -144,15 +136,13 @@ struct ClientPhoneResumeMessage | |||
144 | * talking about. | 136 | * talking about. |
145 | */ | 137 | */ |
146 | uint32_t cid GNUNET_PACKED; | 138 | uint32_t cid GNUNET_PACKED; |
147 | |||
148 | }; | 139 | }; |
149 | 140 | ||
150 | 141 | ||
151 | /** | 142 | /** |
152 | * Client -> Service pick up phone that is ringing. | 143 | * Client -> Service pick up phone that is ringing. |
153 | */ | 144 | */ |
154 | struct ClientPhonePickupMessage | 145 | struct ClientPhonePickupMessage { |
155 | { | ||
156 | /** | 146 | /** |
157 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP | 147 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP |
158 | */ | 148 | */ |
@@ -163,7 +153,6 @@ struct ClientPhonePickupMessage | |||
163 | * talking about. | 153 | * talking about. |
164 | */ | 154 | */ |
165 | uint32_t cid GNUNET_PACKED; | 155 | uint32_t cid GNUNET_PACKED; |
166 | |||
167 | }; | 156 | }; |
168 | 157 | ||
169 | 158 | ||
@@ -171,8 +160,7 @@ struct ClientPhonePickupMessage | |||
171 | * Client <-> Service hang up phone that may or may not be ringing. | 160 | * Client <-> Service hang up phone that may or may not be ringing. |
172 | * Also sent in response to a (failed) `struct ClientCallMessage`. | 161 | * Also sent in response to a (failed) `struct ClientCallMessage`. |
173 | */ | 162 | */ |
174 | struct ClientPhoneHangupMessage | 163 | struct ClientPhoneHangupMessage { |
175 | { | ||
176 | /** | 164 | /** |
177 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP | 165 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP |
178 | */ | 166 | */ |
@@ -183,15 +171,13 @@ struct ClientPhoneHangupMessage | |||
183 | * talking about. | 171 | * talking about. |
184 | */ | 172 | */ |
185 | uint32_t cid GNUNET_PACKED; | 173 | uint32_t cid GNUNET_PACKED; |
186 | |||
187 | }; | 174 | }; |
188 | 175 | ||
189 | 176 | ||
190 | /** | 177 | /** |
191 | * Message Client <-> Service to transmit the audio. | 178 | * Message Client <-> Service to transmit the audio. |
192 | */ | 179 | */ |
193 | struct ClientAudioMessage | 180 | struct ClientAudioMessage { |
194 | { | ||
195 | /** | 181 | /** |
196 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO | 182 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO |
197 | */ | 183 | */ |
@@ -204,15 +190,13 @@ struct ClientAudioMessage | |||
204 | uint32_t cid GNUNET_PACKED; | 190 | uint32_t cid GNUNET_PACKED; |
205 | 191 | ||
206 | /* followed by audio data */ | 192 | /* followed by audio data */ |
207 | |||
208 | }; | 193 | }; |
209 | 194 | ||
210 | 195 | ||
211 | /** | 196 | /** |
212 | * Client -> Service message to call a phone. | 197 | * Client -> Service message to call a phone. |
213 | */ | 198 | */ |
214 | struct ClientCallMessage | 199 | struct ClientCallMessage { |
215 | { | ||
216 | /** | 200 | /** |
217 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL | 201 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL |
218 | */ | 202 | */ |
@@ -244,8 +228,7 @@ struct ClientCallMessage | |||
244 | * Service -> Client: other peer has picked up the phone, we are | 228 | * Service -> Client: other peer has picked up the phone, we are |
245 | * now talking. | 229 | * now talking. |
246 | */ | 230 | */ |
247 | struct ClientPhonePickedupMessage | 231 | struct ClientPhonePickedupMessage { |
248 | { | ||
249 | /** | 232 | /** |
250 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP | 233 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP |
251 | */ | 234 | */ |
@@ -256,7 +239,6 @@ struct ClientPhonePickedupMessage | |||
256 | * #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL | 239 | * #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL |
257 | */ | 240 | */ |
258 | uint32_t cid GNUNET_PACKED; | 241 | uint32_t cid GNUNET_PACKED; |
259 | |||
260 | }; | 242 | }; |
261 | 243 | ||
262 | 244 | ||
@@ -264,8 +246,7 @@ struct ClientPhonePickedupMessage | |||
264 | * Information signed in a `struct CadetPhoneRingMessage` | 246 | * Information signed in a `struct CadetPhoneRingMessage` |
265 | * whereby the caller self-identifies to the receiver. | 247 | * whereby the caller self-identifies to the receiver. |
266 | */ | 248 | */ |
267 | struct CadetPhoneRingInfoPS | 249 | struct CadetPhoneRingInfoPS { |
268 | { | ||
269 | /** | 250 | /** |
270 | * Purpose for the signature, must be | 251 | * Purpose for the signature, must be |
271 | * #GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING. | 252 | * #GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING. |
@@ -293,8 +274,7 @@ struct CadetPhoneRingInfoPS | |||
293 | * Cadet message to make a phone ring. Sent to the port | 274 | * Cadet message to make a phone ring. Sent to the port |
294 | * of the respective phone. | 275 | * of the respective phone. |
295 | */ | 276 | */ |
296 | struct CadetPhoneRingMessage | 277 | struct CadetPhoneRingMessage { |
297 | { | ||
298 | /** | 278 | /** |
299 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING | 279 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING |
300 | */ | 280 | */ |
@@ -319,81 +299,70 @@ struct CadetPhoneRingMessage | |||
319 | * Signature over a `struct CadetPhoneRingInfoPS` | 299 | * Signature over a `struct CadetPhoneRingInfoPS` |
320 | */ | 300 | */ |
321 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 301 | struct GNUNET_CRYPTO_EcdsaSignature signature; |
322 | |||
323 | }; | 302 | }; |
324 | 303 | ||
325 | 304 | ||
326 | /** | 305 | /** |
327 | * Cadet message for hanging up. | 306 | * Cadet message for hanging up. |
328 | */ | 307 | */ |
329 | struct CadetPhoneHangupMessage | 308 | struct CadetPhoneHangupMessage { |
330 | { | ||
331 | /** | 309 | /** |
332 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP | 310 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP |
333 | */ | 311 | */ |
334 | struct GNUNET_MessageHeader header; | 312 | struct GNUNET_MessageHeader header; |
335 | |||
336 | }; | 313 | }; |
337 | 314 | ||
338 | 315 | ||
339 | /** | 316 | /** |
340 | * Cadet message for picking up. | 317 | * Cadet message for picking up. |
341 | */ | 318 | */ |
342 | struct CadetPhonePickupMessage | 319 | struct CadetPhonePickupMessage { |
343 | { | ||
344 | /** | 320 | /** |
345 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP | 321 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP |
346 | */ | 322 | */ |
347 | struct GNUNET_MessageHeader header; | 323 | struct GNUNET_MessageHeader header; |
348 | |||
349 | }; | 324 | }; |
350 | 325 | ||
351 | 326 | ||
352 | /** | 327 | /** |
353 | * Cadet message for phone suspended. | 328 | * Cadet message for phone suspended. |
354 | */ | 329 | */ |
355 | struct CadetPhoneSuspendMessage | 330 | struct CadetPhoneSuspendMessage { |
356 | { | ||
357 | /** | 331 | /** |
358 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND | 332 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND |
359 | */ | 333 | */ |
360 | struct GNUNET_MessageHeader header; | 334 | struct GNUNET_MessageHeader header; |
361 | |||
362 | }; | 335 | }; |
363 | 336 | ||
364 | 337 | ||
365 | /** | 338 | /** |
366 | * Cadet message for phone resumed. | 339 | * Cadet message for phone resumed. |
367 | */ | 340 | */ |
368 | struct CadetPhoneResumeMessage | 341 | struct CadetPhoneResumeMessage { |
369 | { | ||
370 | /** | 342 | /** |
371 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME | 343 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME |
372 | */ | 344 | */ |
373 | struct GNUNET_MessageHeader header; | 345 | struct GNUNET_MessageHeader header; |
374 | |||
375 | }; | 346 | }; |
376 | 347 | ||
377 | 348 | ||
378 | /** | 349 | /** |
379 | * Cadet message to transmit the audio. | 350 | * Cadet message to transmit the audio. |
380 | */ | 351 | */ |
381 | struct CadetAudioMessage | 352 | struct CadetAudioMessage { |
382 | { | ||
383 | /** | 353 | /** |
384 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO | 354 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO |
385 | */ | 355 | */ |
386 | struct GNUNET_MessageHeader header; | 356 | struct GNUNET_MessageHeader header; |
387 | 357 | ||
388 | /* followed by audio data */ | 358 | /* followed by audio data */ |
389 | |||
390 | }; | 359 | }; |
391 | 360 | ||
392 | 361 | ||
393 | GNUNET_NETWORK_STRUCT_END | 362 | GNUNET_NETWORK_STRUCT_END |
394 | 363 | ||
395 | 364 | ||
396 | #if 0 /* keep Emacsens' auto-indent happy */ | 365 | #if 0 /* keep Emacsens' auto-indent happy */ |
397 | { | 366 | { |
398 | #endif | 367 | #endif |
399 | #ifdef __cplusplus | 368 | #ifdef __cplusplus |
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index cd777c285..4c19a7d2d 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2013, 2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -33,8 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Possible states of a caller. | 34 | * Possible states of a caller. |
35 | */ | 35 | */ |
36 | enum CallerState | 36 | enum CallerState { |
37 | { | ||
38 | /** | 37 | /** |
39 | * The phone is ringing (user knows about incoming call). | 38 | * The phone is ringing (user knows about incoming call). |
40 | */ | 39 | */ |
@@ -66,9 +65,7 @@ enum CallerState | |||
66 | /** | 65 | /** |
67 | * A caller is the handle we have for an incoming call. | 66 | * A caller is the handle we have for an incoming call. |
68 | */ | 67 | */ |
69 | struct GNUNET_CONVERSATION_Caller | 68 | struct GNUNET_CONVERSATION_Caller { |
70 | { | ||
71 | |||
72 | /** | 69 | /** |
73 | * We keep all callers in a DLL. | 70 | * We keep all callers in a DLL. |
74 | */ | 71 | */ |
@@ -118,15 +115,13 @@ struct GNUNET_CONVERSATION_Caller | |||
118 | * State machine for the phone. | 115 | * State machine for the phone. |
119 | */ | 116 | */ |
120 | enum CallerState state; | 117 | enum CallerState state; |
121 | |||
122 | }; | 118 | }; |
123 | 119 | ||
124 | 120 | ||
125 | /** | 121 | /** |
126 | * Possible states of a phone. | 122 | * Possible states of a phone. |
127 | */ | 123 | */ |
128 | enum PhoneState | 124 | enum PhoneState { |
129 | { | ||
130 | /** | 125 | /** |
131 | * We still need to register the phone. | 126 | * We still need to register the phone. |
132 | */ | 127 | */ |
@@ -136,7 +131,6 @@ enum PhoneState | |||
136 | * We are waiting for calls. | 131 | * We are waiting for calls. |
137 | */ | 132 | */ |
138 | PS_READY | 133 | PS_READY |
139 | |||
140 | }; | 134 | }; |
141 | 135 | ||
142 | 136 | ||
@@ -151,8 +145,7 @@ enum PhoneState | |||
151 | * something rather internal to a phone and not obvious from it). | 145 | * something rather internal to a phone and not obvious from it). |
152 | * You can only have one conversation per phone at any time. | 146 | * You can only have one conversation per phone at any time. |
153 | */ | 147 | */ |
154 | struct GNUNET_CONVERSATION_Phone | 148 | struct GNUNET_CONVERSATION_Phone { |
155 | { | ||
156 | /** | 149 | /** |
157 | * Our configuration. | 150 | * Our configuration. |
158 | */ | 151 | */ |
@@ -202,7 +195,6 @@ struct GNUNET_CONVERSATION_Phone | |||
202 | * State machine for the phone. | 195 | * State machine for the phone. |
203 | */ | 196 | */ |
204 | enum PhoneState state; | 197 | enum PhoneState state; |
205 | |||
206 | }; | 198 | }; |
207 | 199 | ||
208 | 200 | ||
@@ -212,7 +204,7 @@ struct GNUNET_CONVERSATION_Phone | |||
212 | * @param phone phone to reconnect | 204 | * @param phone phone to reconnect |
213 | */ | 205 | */ |
214 | static void | 206 | static void |
215 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone); | 207 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone); |
216 | 208 | ||
217 | 209 | ||
218 | /** | 210 | /** |
@@ -223,24 +215,24 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone); | |||
223 | * @param data audio data to play | 215 | * @param data audio data to play |
224 | */ | 216 | */ |
225 | static void | 217 | static void |
226 | transmit_phone_audio (void *cls, | 218 | transmit_phone_audio(void *cls, |
227 | size_t data_size, | 219 | size_t data_size, |
228 | const void *data) | 220 | const void *data) |
229 | { | 221 | { |
230 | struct GNUNET_CONVERSATION_Caller *caller = cls; | 222 | struct GNUNET_CONVERSATION_Caller *caller = cls; |
231 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 223 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
232 | struct GNUNET_MQ_Envelope *e; | 224 | struct GNUNET_MQ_Envelope *e; |
233 | struct ClientAudioMessage *am; | 225 | struct ClientAudioMessage *am; |
234 | 226 | ||
235 | e = GNUNET_MQ_msg_extra (am, | 227 | e = GNUNET_MQ_msg_extra(am, |
236 | data_size, | 228 | data_size, |
237 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 229 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
238 | am->cid = caller->cid; | 230 | am->cid = caller->cid; |
239 | GNUNET_memcpy (&am[1], | 231 | GNUNET_memcpy(&am[1], |
240 | data, | 232 | data, |
241 | data_size); | 233 | data_size); |
242 | GNUNET_MQ_send (phone->mq, | 234 | GNUNET_MQ_send(phone->mq, |
243 | e); | 235 | e); |
244 | } | 236 | } |
245 | 237 | ||
246 | 238 | ||
@@ -251,32 +243,33 @@ transmit_phone_audio (void *cls, | |||
251 | * @param ring the message | 243 | * @param ring the message |
252 | */ | 244 | */ |
253 | static void | 245 | static void |
254 | handle_phone_ring (void *cls, | 246 | handle_phone_ring(void *cls, |
255 | const struct ClientPhoneRingMessage *ring) | 247 | const struct ClientPhoneRingMessage *ring) |
256 | { | 248 | { |
257 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 249 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
258 | struct GNUNET_CONVERSATION_Caller *caller; | 250 | struct GNUNET_CONVERSATION_Caller *caller; |
259 | 251 | ||
260 | switch (phone->state) | 252 | switch (phone->state) |
261 | { | 253 | { |
262 | case PS_REGISTER: | 254 | case PS_REGISTER: |
263 | GNUNET_assert (0); | 255 | GNUNET_assert(0); |
264 | break; | 256 | break; |
265 | case PS_READY: | 257 | |
266 | caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller); | 258 | case PS_READY: |
267 | caller->phone = phone; | 259 | caller = GNUNET_new(struct GNUNET_CONVERSATION_Caller); |
268 | GNUNET_CONTAINER_DLL_insert (phone->caller_head, | 260 | caller->phone = phone; |
269 | phone->caller_tail, | 261 | GNUNET_CONTAINER_DLL_insert(phone->caller_head, |
270 | caller); | 262 | phone->caller_tail, |
271 | caller->caller_id = ring->caller_id; | 263 | caller); |
272 | caller->cid = ring->cid; | 264 | caller->caller_id = ring->caller_id; |
273 | caller->state = CS_RINGING; | 265 | caller->cid = ring->cid; |
274 | phone->event_handler (phone->event_handler_cls, | 266 | caller->state = CS_RINGING; |
275 | GNUNET_CONVERSATION_EC_PHONE_RING, | 267 | phone->event_handler(phone->event_handler_cls, |
276 | caller, | 268 | GNUNET_CONVERSATION_EC_PHONE_RING, |
277 | &caller->caller_id); | 269 | caller, |
278 | break; | 270 | &caller->caller_id); |
279 | } | 271 | break; |
272 | } | ||
280 | } | 273 | } |
281 | 274 | ||
282 | 275 | ||
@@ -288,12 +281,12 @@ handle_phone_ring (void *cls, | |||
288 | * @return NULL if @a cid was not found | 281 | * @return NULL if @a cid was not found |
289 | */ | 282 | */ |
290 | static struct GNUNET_CONVERSATION_Caller * | 283 | static struct GNUNET_CONVERSATION_Caller * |
291 | find_caller (struct GNUNET_CONVERSATION_Phone *phone, | 284 | find_caller(struct GNUNET_CONVERSATION_Phone *phone, |
292 | uint32_t cid) | 285 | uint32_t cid) |
293 | { | 286 | { |
294 | struct GNUNET_CONVERSATION_Caller *caller; | 287 | struct GNUNET_CONVERSATION_Caller *caller; |
295 | 288 | ||
296 | for (caller = phone->caller_head;NULL != caller;caller = caller->next) | 289 | for (caller = phone->caller_head; NULL != caller; caller = caller->next) |
297 | if (cid == caller->cid) | 290 | if (cid == caller->cid) |
298 | return caller; | 291 | return caller; |
299 | return NULL; | 292 | return NULL; |
@@ -307,54 +300,56 @@ find_caller (struct GNUNET_CONVERSATION_Phone *phone, | |||
307 | * @param msg the message | 300 | * @param msg the message |
308 | */ | 301 | */ |
309 | static void | 302 | static void |
310 | handle_phone_hangup (void *cls, | 303 | handle_phone_hangup(void *cls, |
311 | const struct ClientPhoneHangupMessage *hang) | 304 | const struct ClientPhoneHangupMessage *hang) |
312 | { | 305 | { |
313 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 306 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
314 | struct GNUNET_CONVERSATION_Caller *caller; | 307 | struct GNUNET_CONVERSATION_Caller *caller; |
315 | 308 | ||
316 | caller = find_caller (phone, | 309 | caller = find_caller(phone, |
317 | hang->cid); | 310 | hang->cid); |
318 | if (NULL == caller) | 311 | if (NULL == caller) |
319 | { | 312 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
321 | "Received HANG_UP message for unknown caller ID %u\n", | 314 | "Received HANG_UP message for unknown caller ID %u\n", |
322 | (unsigned int) hang->cid); | 315 | (unsigned int)hang->cid); |
323 | return; | 316 | return; |
324 | } | 317 | } |
325 | 318 | ||
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
327 | "Received HANG_UP message, terminating call with `%s'\n", | 320 | "Received HANG_UP message, terminating call with `%s'\n", |
328 | GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id)); | 321 | GNUNET_GNSRECORD_pkey_to_zkey(&caller->caller_id)); |
329 | switch (caller->state) | 322 | switch (caller->state) |
330 | { | 323 | { |
331 | case CS_RINGING: | 324 | case CS_RINGING: |
332 | phone->event_handler (phone->event_handler_cls, | 325 | phone->event_handler(phone->event_handler_cls, |
333 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 326 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
334 | caller, | 327 | caller, |
335 | &caller->caller_id); | 328 | &caller->caller_id); |
336 | break; | 329 | break; |
337 | case CS_ACTIVE: | 330 | |
338 | caller->speaker->disable_speaker (caller->speaker->cls); | 331 | case CS_ACTIVE: |
339 | caller->mic->disable_microphone (caller->mic->cls); | 332 | caller->speaker->disable_speaker(caller->speaker->cls); |
340 | phone->event_handler (phone->event_handler_cls, | 333 | caller->mic->disable_microphone(caller->mic->cls); |
341 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 334 | phone->event_handler(phone->event_handler_cls, |
342 | caller, | 335 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
343 | &caller->caller_id); | 336 | caller, |
344 | break; | 337 | &caller->caller_id); |
345 | case CS_CALLEE_SUSPENDED: | 338 | break; |
346 | case CS_CALLER_SUSPENDED: | 339 | |
347 | case CS_BOTH_SUSPENDED: | 340 | case CS_CALLEE_SUSPENDED: |
348 | phone->event_handler (phone->event_handler_cls, | 341 | case CS_CALLER_SUSPENDED: |
349 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 342 | case CS_BOTH_SUSPENDED: |
350 | caller, | 343 | phone->event_handler(phone->event_handler_cls, |
351 | &caller->caller_id); | 344 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
352 | break; | 345 | caller, |
353 | } | 346 | &caller->caller_id); |
354 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, | 347 | break; |
355 | phone->caller_tail, | 348 | } |
356 | caller); | 349 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, |
357 | GNUNET_free (caller); | 350 | phone->caller_tail, |
351 | caller); | ||
352 | GNUNET_free(caller); | ||
358 | } | 353 | } |
359 | 354 | ||
360 | 355 | ||
@@ -365,38 +360,41 @@ handle_phone_hangup (void *cls, | |||
365 | * @param suspend the message | 360 | * @param suspend the message |
366 | */ | 361 | */ |
367 | static void | 362 | static void |
368 | handle_phone_suspend (void *cls, | 363 | handle_phone_suspend(void *cls, |
369 | const struct ClientPhoneSuspendMessage *suspend) | 364 | const struct ClientPhoneSuspendMessage *suspend) |
370 | { | 365 | { |
371 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 366 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
372 | struct GNUNET_CONVERSATION_Caller *caller; | 367 | struct GNUNET_CONVERSATION_Caller *caller; |
373 | 368 | ||
374 | caller = find_caller (phone, | 369 | caller = find_caller(phone, |
375 | suspend->cid); | 370 | suspend->cid); |
376 | if (NULL == caller) | 371 | if (NULL == caller) |
377 | return; | 372 | return; |
378 | switch (caller->state) | 373 | switch (caller->state) |
379 | { | 374 | { |
380 | case CS_RINGING: | 375 | case CS_RINGING: |
381 | GNUNET_break_op (0); | 376 | GNUNET_break_op(0); |
382 | break; | 377 | break; |
383 | case CS_ACTIVE: | 378 | |
384 | caller->state = CS_CALLER_SUSPENDED; | 379 | case CS_ACTIVE: |
385 | caller->speaker->disable_speaker (caller->speaker->cls); | 380 | caller->state = CS_CALLER_SUSPENDED; |
386 | caller->mic->disable_microphone (caller->mic->cls); | 381 | caller->speaker->disable_speaker(caller->speaker->cls); |
387 | caller->event_handler (caller->event_handler_cls, | 382 | caller->mic->disable_microphone(caller->mic->cls); |
388 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 383 | caller->event_handler(caller->event_handler_cls, |
389 | break; | 384 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
390 | case CS_CALLEE_SUSPENDED: | 385 | break; |
391 | caller->state = CS_BOTH_SUSPENDED; | 386 | |
392 | caller->event_handler (caller->event_handler_cls, | 387 | case CS_CALLEE_SUSPENDED: |
393 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 388 | caller->state = CS_BOTH_SUSPENDED; |
394 | break; | 389 | caller->event_handler(caller->event_handler_cls, |
395 | case CS_CALLER_SUSPENDED: | 390 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
396 | case CS_BOTH_SUSPENDED: | 391 | break; |
397 | GNUNET_break_op (0); | 392 | |
398 | break; | 393 | case CS_CALLER_SUSPENDED: |
399 | } | 394 | case CS_BOTH_SUSPENDED: |
395 | GNUNET_break_op(0); | ||
396 | break; | ||
397 | } | ||
400 | } | 398 | } |
401 | 399 | ||
402 | 400 | ||
@@ -407,40 +405,43 @@ handle_phone_suspend (void *cls, | |||
407 | * @param resume the message | 405 | * @param resume the message |
408 | */ | 406 | */ |
409 | static void | 407 | static void |
410 | handle_phone_resume (void *cls, | 408 | handle_phone_resume(void *cls, |
411 | const struct ClientPhoneResumeMessage *resume) | 409 | const struct ClientPhoneResumeMessage *resume) |
412 | { | 410 | { |
413 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 411 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
414 | struct GNUNET_CONVERSATION_Caller *caller; | 412 | struct GNUNET_CONVERSATION_Caller *caller; |
415 | 413 | ||
416 | caller = find_caller (phone, | 414 | caller = find_caller(phone, |
417 | resume->cid); | 415 | resume->cid); |
418 | if (NULL == caller) | 416 | if (NULL == caller) |
419 | return; | 417 | return; |
420 | switch (caller->state) | 418 | switch (caller->state) |
421 | { | 419 | { |
422 | case CS_RINGING: | 420 | case CS_RINGING: |
423 | GNUNET_break_op (0); | 421 | GNUNET_break_op(0); |
424 | break; | 422 | break; |
425 | case CS_ACTIVE: | 423 | |
426 | case CS_CALLEE_SUSPENDED: | 424 | case CS_ACTIVE: |
427 | GNUNET_break_op (0); | 425 | case CS_CALLEE_SUSPENDED: |
428 | break; | 426 | GNUNET_break_op(0); |
429 | case CS_CALLER_SUSPENDED: | 427 | break; |
430 | caller->state = CS_ACTIVE; | 428 | |
431 | caller->speaker->enable_speaker (caller->speaker->cls); | 429 | case CS_CALLER_SUSPENDED: |
432 | caller->mic->enable_microphone (caller->mic->cls, | 430 | caller->state = CS_ACTIVE; |
433 | &transmit_phone_audio, | 431 | caller->speaker->enable_speaker(caller->speaker->cls); |
434 | caller); | 432 | caller->mic->enable_microphone(caller->mic->cls, |
435 | caller->event_handler (caller->event_handler_cls, | 433 | &transmit_phone_audio, |
436 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 434 | caller); |
437 | break; | 435 | caller->event_handler(caller->event_handler_cls, |
438 | case CS_BOTH_SUSPENDED: | 436 | GNUNET_CONVERSATION_EC_CALLER_RESUME); |
439 | caller->state = CS_CALLEE_SUSPENDED; | 437 | break; |
440 | caller->event_handler (caller->event_handler_cls, | 438 | |
441 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 439 | case CS_BOTH_SUSPENDED: |
442 | break; | 440 | caller->state = CS_CALLEE_SUSPENDED; |
443 | } | 441 | caller->event_handler(caller->event_handler_cls, |
442 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | ||
443 | break; | ||
444 | } | ||
444 | } | 445 | } |
445 | 446 | ||
446 | 447 | ||
@@ -452,12 +453,12 @@ handle_phone_resume (void *cls, | |||
452 | * @return #GNUNET_OK if @a am is well-formed | 453 | * @return #GNUNET_OK if @a am is well-formed |
453 | */ | 454 | */ |
454 | static int | 455 | static int |
455 | check_phone_audio (void *cls, | 456 | check_phone_audio(void *cls, |
456 | const struct ClientAudioMessage *am) | 457 | const struct ClientAudioMessage *am) |
457 | { | 458 | { |
458 | (void) cls; | 459 | (void)cls; |
459 | (void) am; | 460 | (void)am; |
460 | 461 | ||
461 | /* any variable-size payload is OK */ | 462 | /* any variable-size payload is OK */ |
462 | return GNUNET_OK; | 463 | return GNUNET_OK; |
463 | } | 464 | } |
@@ -470,31 +471,33 @@ check_phone_audio (void *cls, | |||
470 | * @param am the message | 471 | * @param am the message |
471 | */ | 472 | */ |
472 | static void | 473 | static void |
473 | handle_phone_audio (void *cls, | 474 | handle_phone_audio(void *cls, |
474 | const struct ClientAudioMessage *am) | 475 | const struct ClientAudioMessage *am) |
475 | { | 476 | { |
476 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 477 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
477 | struct GNUNET_CONVERSATION_Caller *caller; | 478 | struct GNUNET_CONVERSATION_Caller *caller; |
478 | 479 | ||
479 | caller = find_caller (phone, | 480 | caller = find_caller(phone, |
480 | am->cid); | 481 | am->cid); |
481 | if (NULL == caller) | 482 | if (NULL == caller) |
482 | return; | 483 | return; |
483 | switch (caller->state) | 484 | switch (caller->state) |
484 | { | 485 | { |
485 | case CS_RINGING: | 486 | case CS_RINGING: |
486 | GNUNET_break_op (0); | 487 | GNUNET_break_op(0); |
487 | break; | 488 | break; |
488 | case CS_ACTIVE: | 489 | |
489 | caller->speaker->play (caller->speaker->cls, | 490 | case CS_ACTIVE: |
490 | ntohs (am->header.size) - sizeof (struct ClientAudioMessage), | 491 | caller->speaker->play(caller->speaker->cls, |
491 | &am[1]); | 492 | ntohs(am->header.size) - sizeof(struct ClientAudioMessage), |
492 | break; | 493 | &am[1]); |
493 | case CS_CALLEE_SUSPENDED: | 494 | break; |
494 | case CS_CALLER_SUSPENDED: | 495 | |
495 | case CS_BOTH_SUSPENDED: | 496 | case CS_CALLEE_SUSPENDED: |
496 | break; | 497 | case CS_CALLER_SUSPENDED: |
497 | } | 498 | case CS_BOTH_SUSPENDED: |
499 | break; | ||
500 | } | ||
498 | } | 501 | } |
499 | 502 | ||
500 | 503 | ||
@@ -505,15 +508,15 @@ handle_phone_audio (void *cls, | |||
505 | * @param error details about the error | 508 | * @param error details about the error |
506 | */ | 509 | */ |
507 | static void | 510 | static void |
508 | phone_error_handler (void *cls, | 511 | phone_error_handler(void *cls, |
509 | enum GNUNET_MQ_Error error) | 512 | enum GNUNET_MQ_Error error) |
510 | { | 513 | { |
511 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 514 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
512 | 515 | ||
513 | (void) error; | 516 | (void)error; |
514 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 517 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
515 | _("Connection to conversation service lost, trying to reconnect\n")); | 518 | _("Connection to conversation service lost, trying to reconnect\n")); |
516 | reconnect_phone (phone); | 519 | reconnect_phone(phone); |
517 | } | 520 | } |
518 | 521 | ||
519 | 522 | ||
@@ -523,25 +526,25 @@ phone_error_handler (void *cls, | |||
523 | * @param phone phone to clean up callers for | 526 | * @param phone phone to clean up callers for |
524 | */ | 527 | */ |
525 | static void | 528 | static void |
526 | clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone) | 529 | clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone) |
527 | { | 530 | { |
528 | struct GNUNET_CONVERSATION_Caller *caller; | 531 | struct GNUNET_CONVERSATION_Caller *caller; |
529 | 532 | ||
530 | while (NULL != (caller = phone->caller_head)) | 533 | while (NULL != (caller = phone->caller_head)) |
531 | { | ||
532 | /* make sure mic/speaker are disabled *before* callback */ | ||
533 | if (CS_ACTIVE == caller->state) | ||
534 | { | 534 | { |
535 | caller->speaker->disable_speaker (caller->speaker->cls); | 535 | /* make sure mic/speaker are disabled *before* callback */ |
536 | caller->mic->disable_microphone (caller->mic->cls); | 536 | if (CS_ACTIVE == caller->state) |
537 | caller->state = CS_CALLER_SUSPENDED; | 537 | { |
538 | caller->speaker->disable_speaker(caller->speaker->cls); | ||
539 | caller->mic->disable_microphone(caller->mic->cls); | ||
540 | caller->state = CS_CALLER_SUSPENDED; | ||
541 | } | ||
542 | phone->event_handler(phone->event_handler_cls, | ||
543 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | ||
544 | caller, | ||
545 | &caller->caller_id); | ||
546 | GNUNET_CONVERSATION_caller_hang_up(caller); | ||
538 | } | 547 | } |
539 | phone->event_handler (phone->event_handler_cls, | ||
540 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | ||
541 | caller, | ||
542 | &caller->caller_id); | ||
543 | GNUNET_CONVERSATION_caller_hang_up (caller); | ||
544 | } | ||
545 | } | 548 | } |
546 | 549 | ||
547 | 550 | ||
@@ -551,53 +554,53 @@ clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone) | |||
551 | * @param phone phone to reconnect | 554 | * @param phone phone to reconnect |
552 | */ | 555 | */ |
553 | static void | 556 | static void |
554 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) | 557 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone) |
555 | { | 558 | { |
556 | struct GNUNET_MQ_MessageHandler handlers[] = { | 559 | struct GNUNET_MQ_MessageHandler handlers[] = { |
557 | GNUNET_MQ_hd_fixed_size (phone_ring, | 560 | GNUNET_MQ_hd_fixed_size(phone_ring, |
558 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, | 561 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, |
559 | struct ClientPhoneRingMessage, | 562 | struct ClientPhoneRingMessage, |
560 | phone), | 563 | phone), |
561 | GNUNET_MQ_hd_fixed_size (phone_hangup, | 564 | GNUNET_MQ_hd_fixed_size(phone_hangup, |
562 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 565 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
563 | struct ClientPhoneHangupMessage, | 566 | struct ClientPhoneHangupMessage, |
564 | phone), | 567 | phone), |
565 | GNUNET_MQ_hd_fixed_size (phone_suspend, | 568 | GNUNET_MQ_hd_fixed_size(phone_suspend, |
566 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 569 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
567 | struct ClientPhoneSuspendMessage, | 570 | struct ClientPhoneSuspendMessage, |
568 | phone), | 571 | phone), |
569 | GNUNET_MQ_hd_fixed_size (phone_resume, | 572 | GNUNET_MQ_hd_fixed_size(phone_resume, |
570 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 573 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
571 | struct ClientPhoneResumeMessage, | 574 | struct ClientPhoneResumeMessage, |
572 | phone), | 575 | phone), |
573 | GNUNET_MQ_hd_var_size (phone_audio, | 576 | GNUNET_MQ_hd_var_size(phone_audio, |
574 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 577 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
575 | struct ClientAudioMessage, | 578 | struct ClientAudioMessage, |
576 | phone), | 579 | phone), |
577 | GNUNET_MQ_handler_end () | 580 | GNUNET_MQ_handler_end() |
578 | }; | 581 | }; |
579 | struct GNUNET_MQ_Envelope *e; | 582 | struct GNUNET_MQ_Envelope *e; |
580 | struct ClientPhoneRegisterMessage *reg; | 583 | struct ClientPhoneRegisterMessage *reg; |
581 | 584 | ||
582 | clean_up_callers (phone); | 585 | clean_up_callers(phone); |
583 | if (NULL != phone->mq) | 586 | if (NULL != phone->mq) |
584 | { | 587 | { |
585 | GNUNET_MQ_destroy (phone->mq); | 588 | GNUNET_MQ_destroy(phone->mq); |
586 | phone->mq = NULL; | 589 | phone->mq = NULL; |
587 | } | 590 | } |
588 | phone->state = PS_REGISTER; | 591 | phone->state = PS_REGISTER; |
589 | phone->mq = GNUNET_CLIENT_connect (phone->cfg, | 592 | phone->mq = GNUNET_CLIENT_connect(phone->cfg, |
590 | "conversation", | 593 | "conversation", |
591 | handlers, | 594 | handlers, |
592 | &phone_error_handler, | 595 | &phone_error_handler, |
593 | phone); | 596 | phone); |
594 | if (NULL == phone->mq) | 597 | if (NULL == phone->mq) |
595 | return; | 598 | return; |
596 | e = GNUNET_MQ_msg (reg, | 599 | e = GNUNET_MQ_msg(reg, |
597 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); | 600 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); |
598 | reg->line_port = phone->my_record.line_port; | 601 | reg->line_port = phone->my_record.line_port; |
599 | GNUNET_MQ_send (phone->mq, | 602 | GNUNET_MQ_send(phone->mq, |
600 | e); | 603 | e); |
601 | phone->state = PS_READY; | 604 | phone->state = PS_READY; |
602 | } | 605 | } |
603 | 606 | ||
@@ -613,54 +616,54 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) | |||
613 | * @return NULL on error (no valid line configured) | 616 | * @return NULL on error (no valid line configured) |
614 | */ | 617 | */ |
615 | struct GNUNET_CONVERSATION_Phone * | 618 | struct GNUNET_CONVERSATION_Phone * |
616 | GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | 619 | GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, |
617 | const struct GNUNET_IDENTITY_Ego *ego, | 620 | const struct GNUNET_IDENTITY_Ego *ego, |
618 | GNUNET_CONVERSATION_PhoneEventHandler event_handler, | 621 | GNUNET_CONVERSATION_PhoneEventHandler event_handler, |
619 | void *event_handler_cls) | 622 | void *event_handler_cls) |
620 | { | 623 | { |
621 | struct GNUNET_CONVERSATION_Phone *phone; | 624 | struct GNUNET_CONVERSATION_Phone *phone; |
622 | char *line; | 625 | char *line; |
623 | struct GNUNET_HashCode line_port; | 626 | struct GNUNET_HashCode line_port; |
624 | 627 | ||
625 | if (GNUNET_OK != | 628 | if (GNUNET_OK != |
626 | GNUNET_CONFIGURATION_get_value_string (cfg, | 629 | GNUNET_CONFIGURATION_get_value_string(cfg, |
627 | "CONVERSATION", | 630 | "CONVERSATION", |
628 | "LINE", | 631 | "LINE", |
629 | &line)) | 632 | &line)) |
630 | { | 633 | { |
631 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 634 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
632 | "CONVERSATION", | 635 | "CONVERSATION", |
633 | "LINE"); | 636 | "LINE"); |
634 | return NULL; | 637 | return NULL; |
635 | } | 638 | } |
636 | GNUNET_CRYPTO_hash (line, | 639 | GNUNET_CRYPTO_hash(line, |
637 | strlen (line), | 640 | strlen(line), |
638 | &line_port); | 641 | &line_port); |
639 | phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone); | 642 | phone = GNUNET_new(struct GNUNET_CONVERSATION_Phone); |
640 | if (GNUNET_OK != | 643 | if (GNUNET_OK != |
641 | GNUNET_CRYPTO_get_peer_identity (cfg, | 644 | GNUNET_CRYPTO_get_peer_identity(cfg, |
642 | &phone->my_record.peer)) | 645 | &phone->my_record.peer)) |
643 | { | 646 | { |
644 | GNUNET_break (0); | 647 | GNUNET_break(0); |
645 | GNUNET_free (phone); | 648 | GNUNET_free(phone); |
646 | return NULL; | 649 | return NULL; |
647 | } | 650 | } |
648 | phone->cfg = cfg; | 651 | phone->cfg = cfg; |
649 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key (ego); | 652 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key(ego); |
650 | phone->event_handler = event_handler; | 653 | phone->event_handler = event_handler; |
651 | phone->event_handler_cls = event_handler_cls; | 654 | phone->event_handler_cls = event_handler_cls; |
652 | phone->ns = GNUNET_NAMESTORE_connect (cfg); | 655 | phone->ns = GNUNET_NAMESTORE_connect(cfg); |
653 | phone->my_record.version = htonl (1); | 656 | phone->my_record.version = htonl(1); |
654 | phone->my_record.reserved = htonl (0); | 657 | phone->my_record.reserved = htonl(0); |
655 | phone->my_record.line_port = line_port; | 658 | phone->my_record.line_port = line_port; |
656 | reconnect_phone (phone); | 659 | reconnect_phone(phone); |
657 | if ( (NULL == phone->mq) || | 660 | if ((NULL == phone->mq) || |
658 | (NULL == phone->ns) ) | 661 | (NULL == phone->ns)) |
659 | { | 662 | { |
660 | GNUNET_break (0); | 663 | GNUNET_break(0); |
661 | GNUNET_CONVERSATION_phone_destroy (phone); | 664 | GNUNET_CONVERSATION_phone_destroy(phone); |
662 | return NULL; | 665 | return NULL; |
663 | } | 666 | } |
664 | return phone; | 667 | return phone; |
665 | } | 668 | } |
666 | 669 | ||
@@ -674,12 +677,12 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
674 | * @param rd namestore record to fill in | 677 | * @param rd namestore record to fill in |
675 | */ | 678 | */ |
676 | void | 679 | void |
677 | GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, | 680 | GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, |
678 | struct GNUNET_GNSRECORD_Data *rd) | 681 | struct GNUNET_GNSRECORD_Data *rd) |
679 | { | 682 | { |
680 | rd->data = &phone->my_record; | 683 | rd->data = &phone->my_record; |
681 | rd->expiration_time = 0; | 684 | rd->expiration_time = 0; |
682 | rd->data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord); | 685 | rd->data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord); |
683 | rd->record_type = GNUNET_GNSRECORD_TYPE_PHONE; | 686 | rd->record_type = GNUNET_GNSRECORD_TYPE_PHONE; |
684 | rd->flags = GNUNET_GNSRECORD_RF_NONE; | 687 | rd->flags = GNUNET_GNSRECORD_RF_NONE; |
685 | } | 688 | } |
@@ -696,31 +699,31 @@ GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, | |||
696 | * @param mic microphone to use | 699 | * @param mic microphone to use |
697 | */ | 700 | */ |
698 | void | 701 | void |
699 | GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, | 702 | GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, |
700 | GNUNET_CONVERSATION_CallerEventHandler event_handler, | 703 | GNUNET_CONVERSATION_CallerEventHandler event_handler, |
701 | void *event_handler_cls, | 704 | void *event_handler_cls, |
702 | struct GNUNET_SPEAKER_Handle *speaker, | 705 | struct GNUNET_SPEAKER_Handle *speaker, |
703 | struct GNUNET_MICROPHONE_Handle *mic) | 706 | struct GNUNET_MICROPHONE_Handle *mic) |
704 | { | 707 | { |
705 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 708 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
706 | struct GNUNET_MQ_Envelope *e; | 709 | struct GNUNET_MQ_Envelope *e; |
707 | struct ClientPhonePickupMessage *pick; | 710 | struct ClientPhonePickupMessage *pick; |
708 | 711 | ||
709 | GNUNET_assert (CS_RINGING == caller->state); | 712 | GNUNET_assert(CS_RINGING == caller->state); |
710 | caller->speaker = speaker; | 713 | caller->speaker = speaker; |
711 | caller->mic = mic; | 714 | caller->mic = mic; |
712 | e = GNUNET_MQ_msg (pick, | 715 | e = GNUNET_MQ_msg(pick, |
713 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); | 716 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); |
714 | pick->cid = caller->cid; | 717 | pick->cid = caller->cid; |
715 | GNUNET_MQ_send (phone->mq, | 718 | GNUNET_MQ_send(phone->mq, |
716 | e); | 719 | e); |
717 | caller->state = CS_ACTIVE; | 720 | caller->state = CS_ACTIVE; |
718 | caller->event_handler = event_handler; | 721 | caller->event_handler = event_handler; |
719 | caller->event_handler_cls = event_handler_cls; | 722 | caller->event_handler_cls = event_handler_cls; |
720 | caller->speaker->enable_speaker (caller->speaker->cls); | 723 | caller->speaker->enable_speaker(caller->speaker->cls); |
721 | caller->mic->enable_microphone (caller->mic->cls, | 724 | caller->mic->enable_microphone(caller->mic->cls, |
722 | &transmit_phone_audio, | 725 | &transmit_phone_audio, |
723 | caller); | 726 | caller); |
724 | } | 727 | } |
725 | 728 | ||
726 | 729 | ||
@@ -731,30 +734,31 @@ GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, | |||
731 | * @param caller conversation to hang up on | 734 | * @param caller conversation to hang up on |
732 | */ | 735 | */ |
733 | void | 736 | void |
734 | GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) | 737 | GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller) |
735 | { | 738 | { |
736 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 739 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
737 | struct GNUNET_MQ_Envelope *e; | 740 | struct GNUNET_MQ_Envelope *e; |
738 | struct ClientPhoneHangupMessage *hang; | 741 | struct ClientPhoneHangupMessage *hang; |
739 | 742 | ||
740 | switch (caller->state) | 743 | switch (caller->state) |
741 | { | 744 | { |
742 | case CS_ACTIVE: | 745 | case CS_ACTIVE: |
743 | caller->speaker->disable_speaker (caller->speaker->cls); | 746 | caller->speaker->disable_speaker(caller->speaker->cls); |
744 | caller->mic->disable_microphone (caller->mic->cls); | 747 | caller->mic->disable_microphone(caller->mic->cls); |
745 | break; | 748 | break; |
746 | default: | 749 | |
747 | break; | 750 | default: |
748 | } | 751 | break; |
749 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, | 752 | } |
750 | phone->caller_tail, | 753 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, |
751 | caller); | 754 | phone->caller_tail, |
752 | e = GNUNET_MQ_msg (hang, | 755 | caller); |
753 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 756 | e = GNUNET_MQ_msg(hang, |
757 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
754 | hang->cid = caller->cid; | 758 | hang->cid = caller->cid; |
755 | GNUNET_MQ_send (phone->mq, | 759 | GNUNET_MQ_send(phone->mq, |
756 | e); | 760 | e); |
757 | GNUNET_free (caller); | 761 | GNUNET_free(caller); |
758 | } | 762 | } |
759 | 763 | ||
760 | 764 | ||
@@ -764,20 +768,20 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) | |||
764 | * @param phone phone to destroy | 768 | * @param phone phone to destroy |
765 | */ | 769 | */ |
766 | void | 770 | void |
767 | GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) | 771 | GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone) |
768 | { | 772 | { |
769 | clean_up_callers (phone); | 773 | clean_up_callers(phone); |
770 | if (NULL != phone->ns) | 774 | if (NULL != phone->ns) |
771 | { | 775 | { |
772 | GNUNET_NAMESTORE_disconnect (phone->ns); | 776 | GNUNET_NAMESTORE_disconnect(phone->ns); |
773 | phone->ns = NULL; | 777 | phone->ns = NULL; |
774 | } | 778 | } |
775 | if (NULL != phone->mq) | 779 | if (NULL != phone->mq) |
776 | { | 780 | { |
777 | GNUNET_MQ_destroy (phone->mq); | 781 | GNUNET_MQ_destroy(phone->mq); |
778 | phone->mq = NULL; | 782 | phone->mq = NULL; |
779 | } | 783 | } |
780 | GNUNET_free (phone); | 784 | GNUNET_free(phone); |
781 | } | 785 | } |
782 | 786 | ||
783 | 787 | ||
@@ -789,26 +793,26 @@ GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) | |||
789 | * @param caller call to suspend | 793 | * @param caller call to suspend |
790 | */ | 794 | */ |
791 | void | 795 | void |
792 | GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller) | 796 | GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller) |
793 | { | 797 | { |
794 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 798 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
795 | struct GNUNET_MQ_Envelope *e; | 799 | struct GNUNET_MQ_Envelope *e; |
796 | struct ClientPhoneSuspendMessage *suspend; | 800 | struct ClientPhoneSuspendMessage *suspend; |
797 | 801 | ||
798 | GNUNET_assert ( (CS_ACTIVE == caller->state) || | 802 | GNUNET_assert((CS_ACTIVE == caller->state) || |
799 | (CS_CALLER_SUSPENDED == caller->state) ); | 803 | (CS_CALLER_SUSPENDED == caller->state)); |
800 | if (CS_ACTIVE == caller->state) | 804 | if (CS_ACTIVE == caller->state) |
801 | { | 805 | { |
802 | caller->speaker->disable_speaker (caller->speaker->cls); | 806 | caller->speaker->disable_speaker(caller->speaker->cls); |
803 | caller->mic->disable_microphone (caller->mic->cls); | 807 | caller->mic->disable_microphone(caller->mic->cls); |
804 | } | 808 | } |
805 | caller->speaker = NULL; | 809 | caller->speaker = NULL; |
806 | caller->mic = NULL; | 810 | caller->mic = NULL; |
807 | e = GNUNET_MQ_msg (suspend, | 811 | e = GNUNET_MQ_msg(suspend, |
808 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 812 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
809 | suspend->cid = caller->cid; | 813 | suspend->cid = caller->cid; |
810 | GNUNET_MQ_send (phone->mq, | 814 | GNUNET_MQ_send(phone->mq, |
811 | e); | 815 | e); |
812 | if (CS_ACTIVE == caller->state) | 816 | if (CS_ACTIVE == caller->state) |
813 | caller->state = CS_CALLEE_SUSPENDED; | 817 | caller->state = CS_CALLEE_SUSPENDED; |
814 | else | 818 | else |
@@ -824,35 +828,35 @@ GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller) | |||
824 | * @param mic microphone to use | 828 | * @param mic microphone to use |
825 | */ | 829 | */ |
826 | void | 830 | void |
827 | GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller, | 831 | GNUNET_CONVERSATION_caller_resume(struct GNUNET_CONVERSATION_Caller *caller, |
828 | struct GNUNET_SPEAKER_Handle *speaker, | 832 | struct GNUNET_SPEAKER_Handle *speaker, |
829 | struct GNUNET_MICROPHONE_Handle *mic) | 833 | struct GNUNET_MICROPHONE_Handle *mic) |
830 | { | 834 | { |
831 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 835 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
832 | struct GNUNET_MQ_Envelope *e; | 836 | struct GNUNET_MQ_Envelope *e; |
833 | struct ClientPhoneResumeMessage *resume; | 837 | struct ClientPhoneResumeMessage *resume; |
834 | 838 | ||
835 | GNUNET_assert ( (CS_CALLEE_SUSPENDED == caller->state) || | 839 | GNUNET_assert((CS_CALLEE_SUSPENDED == caller->state) || |
836 | (CS_BOTH_SUSPENDED == caller->state) ); | 840 | (CS_BOTH_SUSPENDED == caller->state)); |
837 | caller->speaker = speaker; | 841 | caller->speaker = speaker; |
838 | caller->mic = mic; | 842 | caller->mic = mic; |
839 | e = GNUNET_MQ_msg (resume, | 843 | e = GNUNET_MQ_msg(resume, |
840 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 844 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
841 | resume->cid = caller->cid; | 845 | resume->cid = caller->cid; |
842 | GNUNET_MQ_send (phone->mq, | 846 | GNUNET_MQ_send(phone->mq, |
843 | e); | 847 | e); |
844 | if (CS_CALLEE_SUSPENDED == caller->state) | 848 | if (CS_CALLEE_SUSPENDED == caller->state) |
845 | { | 849 | { |
846 | caller->state = CS_ACTIVE; | 850 | caller->state = CS_ACTIVE; |
847 | caller->speaker->enable_speaker (caller->speaker->cls); | 851 | caller->speaker->enable_speaker(caller->speaker->cls); |
848 | caller->mic->enable_microphone (caller->mic->cls, | 852 | caller->mic->enable_microphone(caller->mic->cls, |
849 | &transmit_phone_audio, | 853 | &transmit_phone_audio, |
850 | caller); | 854 | caller); |
851 | } | 855 | } |
852 | else | 856 | else |
853 | { | 857 | { |
854 | caller->state = CS_CALLER_SUSPENDED; | 858 | caller->state = CS_CALLER_SUSPENDED; |
855 | } | 859 | } |
856 | } | 860 | } |
857 | 861 | ||
858 | /* end of conversation_api.c */ | 862 | /* end of conversation_api.c */ |
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c index 5353c3e2d..08fab57b4 100644 --- a/src/conversation/conversation_api_call.c +++ b/src/conversation/conversation_api_call.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -35,8 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Possible states of the phone. | 36 | * Possible states of the phone. |
37 | */ | 37 | */ |
38 | enum CallState | 38 | enum CallState { |
39 | { | ||
40 | /** | 39 | /** |
41 | * We still need to lookup the callee. | 40 | * We still need to lookup the callee. |
42 | */ | 41 | */ |
@@ -77,9 +76,7 @@ enum CallState | |||
77 | /** | 76 | /** |
78 | * Handle for an outgoing call. | 77 | * Handle for an outgoing call. |
79 | */ | 78 | */ |
80 | struct GNUNET_CONVERSATION_Call | 79 | struct GNUNET_CONVERSATION_Call { |
81 | { | ||
82 | |||
83 | /** | 80 | /** |
84 | * Our configuration. | 81 | * Our configuration. |
85 | */ | 82 | */ |
@@ -139,7 +136,6 @@ struct GNUNET_CONVERSATION_Call | |||
139 | * State machine for the call. | 136 | * State machine for the call. |
140 | */ | 137 | */ |
141 | enum CallState state; | 138 | enum CallState state; |
142 | |||
143 | }; | 139 | }; |
144 | 140 | ||
145 | 141 | ||
@@ -149,7 +145,7 @@ struct GNUNET_CONVERSATION_Call | |||
149 | * @param call call to reconnect | 145 | * @param call call to reconnect |
150 | */ | 146 | */ |
151 | static void | 147 | static void |
152 | fail_call (struct GNUNET_CONVERSATION_Call *call); | 148 | fail_call(struct GNUNET_CONVERSATION_Call *call); |
153 | 149 | ||
154 | 150 | ||
155 | /** | 151 | /** |
@@ -160,23 +156,23 @@ fail_call (struct GNUNET_CONVERSATION_Call *call); | |||
160 | * @param data audio data to play | 156 | * @param data audio data to play |
161 | */ | 157 | */ |
162 | static void | 158 | static void |
163 | transmit_call_audio (void *cls, | 159 | transmit_call_audio(void *cls, |
164 | size_t data_size, | 160 | size_t data_size, |
165 | const void *data) | 161 | const void *data) |
166 | { | 162 | { |
167 | struct GNUNET_CONVERSATION_Call *call = cls; | 163 | struct GNUNET_CONVERSATION_Call *call = cls; |
168 | struct GNUNET_MQ_Envelope *e; | 164 | struct GNUNET_MQ_Envelope *e; |
169 | struct ClientAudioMessage *am; | 165 | struct ClientAudioMessage *am; |
170 | 166 | ||
171 | GNUNET_assert (CS_ACTIVE == call->state); | 167 | GNUNET_assert(CS_ACTIVE == call->state); |
172 | e = GNUNET_MQ_msg_extra (am, | 168 | e = GNUNET_MQ_msg_extra(am, |
173 | data_size, | 169 | data_size, |
174 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 170 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
175 | GNUNET_memcpy (&am[1], | 171 | GNUNET_memcpy(&am[1], |
176 | data, | 172 | data, |
177 | data_size); | 173 | data_size); |
178 | GNUNET_MQ_send (call->mq, | 174 | GNUNET_MQ_send(call->mq, |
179 | e); | 175 | e); |
180 | } | 176 | } |
181 | 177 | ||
182 | 178 | ||
@@ -187,42 +183,47 @@ transmit_call_audio (void *cls, | |||
187 | * @param msg the message | 183 | * @param msg the message |
188 | */ | 184 | */ |
189 | static void | 185 | static void |
190 | handle_call_suspend (void *cls, | 186 | handle_call_suspend(void *cls, |
191 | const struct ClientPhoneSuspendMessage *msg) | 187 | const struct ClientPhoneSuspendMessage *msg) |
192 | { | 188 | { |
193 | struct GNUNET_CONVERSATION_Call *call = cls; | 189 | struct GNUNET_CONVERSATION_Call *call = cls; |
194 | 190 | ||
195 | (void) msg; | 191 | (void)msg; |
196 | switch (call->state) | 192 | switch (call->state) |
197 | { | 193 | { |
198 | case CS_LOOKUP: | 194 | case CS_LOOKUP: |
199 | GNUNET_break (0); | 195 | GNUNET_break(0); |
200 | fail_call (call); | 196 | fail_call(call); |
201 | break; | 197 | break; |
202 | case CS_RINGING: | 198 | |
203 | GNUNET_break_op (0); | 199 | case CS_RINGING: |
204 | fail_call (call); | 200 | GNUNET_break_op(0); |
205 | break; | 201 | fail_call(call); |
206 | case CS_SUSPENDED_CALLER: | 202 | break; |
207 | call->state = CS_SUSPENDED_BOTH; | 203 | |
208 | call->event_handler (call->event_handler_cls, | 204 | case CS_SUSPENDED_CALLER: |
209 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); | 205 | call->state = CS_SUSPENDED_BOTH; |
210 | break; | 206 | call->event_handler(call->event_handler_cls, |
211 | case CS_SUSPENDED_CALLEE: | 207 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); |
212 | case CS_SUSPENDED_BOTH: | 208 | break; |
213 | GNUNET_break_op (0); | 209 | |
214 | break; | 210 | case CS_SUSPENDED_CALLEE: |
215 | case CS_ACTIVE: | 211 | case CS_SUSPENDED_BOTH: |
216 | call->state = CS_SUSPENDED_CALLEE; | 212 | GNUNET_break_op(0); |
217 | call->speaker->disable_speaker (call->speaker->cls); | 213 | break; |
218 | call->mic->disable_microphone (call->mic->cls); | 214 | |
219 | call->event_handler (call->event_handler_cls, | 215 | case CS_ACTIVE: |
220 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); | 216 | call->state = CS_SUSPENDED_CALLEE; |
221 | break; | 217 | call->speaker->disable_speaker(call->speaker->cls); |
222 | case CS_SHUTDOWN: | 218 | call->mic->disable_microphone(call->mic->cls); |
223 | GNUNET_CONVERSATION_call_stop (call); | 219 | call->event_handler(call->event_handler_cls, |
224 | break; | 220 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); |
225 | } | 221 | break; |
222 | |||
223 | case CS_SHUTDOWN: | ||
224 | GNUNET_CONVERSATION_call_stop(call); | ||
225 | break; | ||
226 | } | ||
226 | } | 227 | } |
227 | 228 | ||
228 | 229 | ||
@@ -233,46 +234,52 @@ handle_call_suspend (void *cls, | |||
233 | * @param msg the message | 234 | * @param msg the message |
234 | */ | 235 | */ |
235 | static void | 236 | static void |
236 | handle_call_resume (void *cls, | 237 | handle_call_resume(void *cls, |
237 | const struct ClientPhoneResumeMessage *msg) | 238 | const struct ClientPhoneResumeMessage *msg) |
238 | { | 239 | { |
239 | struct GNUNET_CONVERSATION_Call *call = cls; | 240 | struct GNUNET_CONVERSATION_Call *call = cls; |
240 | 241 | ||
241 | (void) msg; | 242 | (void)msg; |
242 | switch (call->state) | 243 | switch (call->state) |
243 | { | 244 | { |
244 | case CS_LOOKUP: | 245 | case CS_LOOKUP: |
245 | GNUNET_break (0); | 246 | GNUNET_break(0); |
246 | fail_call (call); | 247 | fail_call(call); |
247 | break; | 248 | break; |
248 | case CS_RINGING: | 249 | |
249 | GNUNET_break_op (0); | 250 | case CS_RINGING: |
250 | fail_call (call); | 251 | GNUNET_break_op(0); |
251 | break; | 252 | fail_call(call); |
252 | case CS_SUSPENDED_CALLER: | 253 | break; |
253 | GNUNET_break_op (0); | 254 | |
254 | break; | 255 | case CS_SUSPENDED_CALLER: |
255 | case CS_SUSPENDED_CALLEE: | 256 | GNUNET_break_op(0); |
256 | call->state = CS_ACTIVE; | 257 | break; |
257 | call->speaker->enable_speaker (call->speaker->cls); | 258 | |
258 | call->mic->enable_microphone (call->mic->cls, | 259 | case CS_SUSPENDED_CALLEE: |
259 | &transmit_call_audio, | 260 | call->state = CS_ACTIVE; |
260 | call); | 261 | call->speaker->enable_speaker(call->speaker->cls); |
261 | call->event_handler (call->event_handler_cls, | 262 | call->mic->enable_microphone(call->mic->cls, |
262 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | 263 | &transmit_call_audio, |
263 | break; | 264 | call); |
264 | case CS_SUSPENDED_BOTH: | 265 | call->event_handler(call->event_handler_cls, |
265 | call->state = CS_SUSPENDED_CALLER; | 266 | GNUNET_CONVERSATION_EC_CALL_RESUMED); |
266 | call->event_handler (call->event_handler_cls, | 267 | break; |
267 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | 268 | |
268 | break; | 269 | case CS_SUSPENDED_BOTH: |
269 | case CS_ACTIVE: | 270 | call->state = CS_SUSPENDED_CALLER; |
270 | GNUNET_break_op (0); | 271 | call->event_handler(call->event_handler_cls, |
271 | break; | 272 | GNUNET_CONVERSATION_EC_CALL_RESUMED); |
272 | case CS_SHUTDOWN: | 273 | break; |
273 | GNUNET_CONVERSATION_call_stop (call); | 274 | |
274 | break; | 275 | case CS_ACTIVE: |
275 | } | 276 | GNUNET_break_op(0); |
277 | break; | ||
278 | |||
279 | case CS_SHUTDOWN: | ||
280 | GNUNET_CONVERSATION_call_stop(call); | ||
281 | break; | ||
282 | } | ||
276 | } | 283 | } |
277 | 284 | ||
278 | 285 | ||
@@ -283,38 +290,41 @@ handle_call_resume (void *cls, | |||
283 | * @param msg the message | 290 | * @param msg the message |
284 | */ | 291 | */ |
285 | static void | 292 | static void |
286 | handle_call_picked_up (void *cls, | 293 | handle_call_picked_up(void *cls, |
287 | const struct ClientPhonePickedupMessage *msg) | 294 | const struct ClientPhonePickedupMessage *msg) |
288 | { | 295 | { |
289 | struct GNUNET_CONVERSATION_Call *call = cls; | 296 | struct GNUNET_CONVERSATION_Call *call = cls; |
290 | 297 | ||
291 | (void) msg; | 298 | (void)msg; |
292 | switch (call->state) | 299 | switch (call->state) |
293 | { | 300 | { |
294 | case CS_LOOKUP: | 301 | case CS_LOOKUP: |
295 | GNUNET_break (0); | 302 | GNUNET_break(0); |
296 | fail_call (call); | 303 | fail_call(call); |
297 | break; | 304 | break; |
298 | case CS_RINGING: | 305 | |
299 | call->state = CS_ACTIVE; | 306 | case CS_RINGING: |
300 | call->speaker->enable_speaker (call->speaker->cls); | 307 | call->state = CS_ACTIVE; |
301 | call->mic->enable_microphone (call->mic->cls, | 308 | call->speaker->enable_speaker(call->speaker->cls); |
302 | &transmit_call_audio, | 309 | call->mic->enable_microphone(call->mic->cls, |
303 | call); | 310 | &transmit_call_audio, |
304 | call->event_handler (call->event_handler_cls, | 311 | call); |
305 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); | 312 | call->event_handler(call->event_handler_cls, |
306 | break; | 313 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); |
307 | case CS_SUSPENDED_CALLER: | 314 | break; |
308 | case CS_SUSPENDED_CALLEE: | 315 | |
309 | case CS_SUSPENDED_BOTH: | 316 | case CS_SUSPENDED_CALLER: |
310 | case CS_ACTIVE: | 317 | case CS_SUSPENDED_CALLEE: |
311 | GNUNET_break (0); | 318 | case CS_SUSPENDED_BOTH: |
312 | fail_call (call); | 319 | case CS_ACTIVE: |
313 | break; | 320 | GNUNET_break(0); |
314 | case CS_SHUTDOWN: | 321 | fail_call(call); |
315 | GNUNET_CONVERSATION_call_stop (call); | 322 | break; |
316 | break; | 323 | |
317 | } | 324 | case CS_SHUTDOWN: |
325 | GNUNET_CONVERSATION_call_stop(call); | ||
326 | break; | ||
327 | } | ||
318 | } | 328 | } |
319 | 329 | ||
320 | 330 | ||
@@ -325,35 +335,37 @@ handle_call_picked_up (void *cls, | |||
325 | * @param msg the message | 335 | * @param msg the message |
326 | */ | 336 | */ |
327 | static void | 337 | static void |
328 | handle_call_hangup (void *cls, | 338 | handle_call_hangup(void *cls, |
329 | const struct ClientPhoneHangupMessage *msg) | 339 | const struct ClientPhoneHangupMessage *msg) |
330 | { | 340 | { |
331 | struct GNUNET_CONVERSATION_Call *call = cls; | 341 | struct GNUNET_CONVERSATION_Call *call = cls; |
332 | GNUNET_CONVERSATION_CallEventHandler eh; | 342 | GNUNET_CONVERSATION_CallEventHandler eh; |
333 | void *eh_cls; | 343 | void *eh_cls; |
334 | 344 | ||
335 | (void) msg; | 345 | (void)msg; |
336 | switch (call->state) | 346 | switch (call->state) |
337 | { | 347 | { |
338 | case CS_LOOKUP: | 348 | case CS_LOOKUP: |
339 | GNUNET_break (0); | 349 | GNUNET_break(0); |
340 | fail_call (call); | 350 | fail_call(call); |
341 | break; | 351 | break; |
342 | case CS_RINGING: | 352 | |
343 | case CS_SUSPENDED_CALLER: | 353 | case CS_RINGING: |
344 | case CS_SUSPENDED_CALLEE: | 354 | case CS_SUSPENDED_CALLER: |
345 | case CS_SUSPENDED_BOTH: | 355 | case CS_SUSPENDED_CALLEE: |
346 | case CS_ACTIVE: | 356 | case CS_SUSPENDED_BOTH: |
347 | eh = call->event_handler; | 357 | case CS_ACTIVE: |
348 | eh_cls = call->event_handler_cls; | 358 | eh = call->event_handler; |
349 | GNUNET_CONVERSATION_call_stop (call); | 359 | eh_cls = call->event_handler_cls; |
350 | eh (eh_cls, | 360 | GNUNET_CONVERSATION_call_stop(call); |
351 | GNUNET_CONVERSATION_EC_CALL_HUNG_UP); | 361 | eh(eh_cls, |
352 | return; | 362 | GNUNET_CONVERSATION_EC_CALL_HUNG_UP); |
353 | case CS_SHUTDOWN: | 363 | return; |
354 | GNUNET_CONVERSATION_call_stop (call); | 364 | |
355 | break; | 365 | case CS_SHUTDOWN: |
356 | } | 366 | GNUNET_CONVERSATION_call_stop(call); |
367 | break; | ||
368 | } | ||
357 | } | 369 | } |
358 | 370 | ||
359 | 371 | ||
@@ -365,11 +377,11 @@ handle_call_hangup (void *cls, | |||
365 | * @return #GNUNET_OK (always well-formed) | 377 | * @return #GNUNET_OK (always well-formed) |
366 | */ | 378 | */ |
367 | static int | 379 | static int |
368 | check_call_audio (void *cls, | 380 | check_call_audio(void *cls, |
369 | const struct ClientAudioMessage *am) | 381 | const struct ClientAudioMessage *am) |
370 | { | 382 | { |
371 | (void) cls; | 383 | (void)cls; |
372 | (void) am; | 384 | (void)am; |
373 | /* any payload is OK */ | 385 | /* any payload is OK */ |
374 | return GNUNET_OK; | 386 | return GNUNET_OK; |
375 | } | 387 | } |
@@ -382,39 +394,44 @@ check_call_audio (void *cls, | |||
382 | * @param msg the message | 394 | * @param msg the message |
383 | */ | 395 | */ |
384 | static void | 396 | static void |
385 | handle_call_audio (void *cls, | 397 | handle_call_audio(void *cls, |
386 | const struct ClientAudioMessage *am) | 398 | const struct ClientAudioMessage *am) |
387 | { | 399 | { |
388 | struct GNUNET_CONVERSATION_Call *call = cls; | 400 | struct GNUNET_CONVERSATION_Call *call = cls; |
389 | 401 | ||
390 | switch (call->state) | 402 | switch (call->state) |
391 | { | 403 | { |
392 | case CS_LOOKUP: | 404 | case CS_LOOKUP: |
393 | GNUNET_break (0); | 405 | GNUNET_break(0); |
394 | fail_call (call); | 406 | fail_call(call); |
395 | break; | 407 | break; |
396 | case CS_RINGING: | 408 | |
397 | GNUNET_break (0); | 409 | case CS_RINGING: |
398 | fail_call (call); | 410 | GNUNET_break(0); |
399 | break; | 411 | fail_call(call); |
400 | case CS_SUSPENDED_CALLER: | 412 | break; |
401 | /* can happen: we suspended, other peer did not yet | 413 | |
402 | learn about this. */ | 414 | case CS_SUSPENDED_CALLER: |
403 | break; | 415 | /* can happen: we suspended, other peer did not yet |
404 | case CS_SUSPENDED_CALLEE: | 416 | learn about this. */ |
405 | case CS_SUSPENDED_BOTH: | 417 | break; |
406 | /* can (rarely) also happen: other peer suspended, but cadet might | 418 | |
407 | have had delayed data on the unreliable channel */ | 419 | case CS_SUSPENDED_CALLEE: |
408 | break; | 420 | case CS_SUSPENDED_BOTH: |
409 | case CS_ACTIVE: | 421 | /* can (rarely) also happen: other peer suspended, but cadet might |
410 | call->speaker->play (call->speaker->cls, | 422 | have had delayed data on the unreliable channel */ |
411 | ntohs (am->header.size) - sizeof (struct ClientAudioMessage), | 423 | break; |
412 | &am[1]); | 424 | |
413 | break; | 425 | case CS_ACTIVE: |
414 | case CS_SHUTDOWN: | 426 | call->speaker->play(call->speaker->cls, |
415 | GNUNET_CONVERSATION_call_stop (call); | 427 | ntohs(am->header.size) - sizeof(struct ClientAudioMessage), |
416 | break; | 428 | &am[1]); |
417 | } | 429 | break; |
430 | |||
431 | case CS_SHUTDOWN: | ||
432 | GNUNET_CONVERSATION_call_stop(call); | ||
433 | break; | ||
434 | } | ||
418 | } | 435 | } |
419 | 436 | ||
420 | 437 | ||
@@ -427,48 +444,48 @@ handle_call_audio (void *cls, | |||
427 | * @param rd the records in reply | 444 | * @param rd the records in reply |
428 | */ | 445 | */ |
429 | static void | 446 | static void |
430 | handle_gns_response (void *cls, | 447 | handle_gns_response(void *cls, |
431 | int was_gns, | 448 | int was_gns, |
432 | uint32_t rd_count, | 449 | uint32_t rd_count, |
433 | const struct GNUNET_GNSRECORD_Data *rd) | 450 | const struct GNUNET_GNSRECORD_Data *rd) |
434 | { | 451 | { |
435 | struct GNUNET_CONVERSATION_Call *call = cls; | 452 | struct GNUNET_CONVERSATION_Call *call = cls; |
436 | struct GNUNET_MQ_Envelope *e; | 453 | struct GNUNET_MQ_Envelope *e; |
437 | struct ClientCallMessage *ccm; | 454 | struct ClientCallMessage *ccm; |
438 | 455 | ||
439 | (void) was_gns; | 456 | (void)was_gns; |
440 | GNUNET_break (NULL != call->gns_lookup); | 457 | GNUNET_break(NULL != call->gns_lookup); |
441 | GNUNET_break (CS_LOOKUP == call->state); | 458 | GNUNET_break(CS_LOOKUP == call->state); |
442 | call->gns_lookup = NULL; | 459 | call->gns_lookup = NULL; |
443 | for (uint32_t i=0;i<rd_count;i++) | 460 | for (uint32_t i = 0; i < rd_count; i++) |
444 | { | ||
445 | if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type) | ||
446 | { | 461 | { |
447 | if (rd[i].data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord)) | 462 | if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type) |
448 | { | 463 | { |
449 | GNUNET_break_op (0); | 464 | if (rd[i].data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord)) |
450 | continue; | 465 | { |
451 | } | 466 | GNUNET_break_op(0); |
452 | GNUNET_memcpy (&call->phone_record, | 467 | continue; |
453 | rd[i].data, | 468 | } |
454 | rd[i].data_size); | 469 | GNUNET_memcpy(&call->phone_record, |
455 | e = GNUNET_MQ_msg (ccm, | 470 | rd[i].data, |
456 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); | 471 | rd[i].data_size); |
457 | ccm->line_port = call->phone_record.line_port; | 472 | e = GNUNET_MQ_msg(ccm, |
458 | ccm->target = call->phone_record.peer; | 473 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); |
459 | ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key (call->caller_id); | 474 | ccm->line_port = call->phone_record.line_port; |
460 | GNUNET_MQ_send (call->mq, | 475 | ccm->target = call->phone_record.peer; |
461 | e); | 476 | ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key(call->caller_id); |
462 | call->state = CS_RINGING; | 477 | GNUNET_MQ_send(call->mq, |
463 | call->event_handler (call->event_handler_cls, | 478 | e); |
464 | GNUNET_CONVERSATION_EC_CALL_RINGING); | 479 | call->state = CS_RINGING; |
465 | return; | 480 | call->event_handler(call->event_handler_cls, |
481 | GNUNET_CONVERSATION_EC_CALL_RINGING); | ||
482 | return; | ||
483 | } | ||
466 | } | 484 | } |
467 | } | ||
468 | /* not found */ | 485 | /* not found */ |
469 | call->event_handler (call->event_handler_cls, | 486 | call->event_handler(call->event_handler_cls, |
470 | GNUNET_CONVERSATION_EC_CALL_GNS_FAIL); | 487 | GNUNET_CONVERSATION_EC_CALL_GNS_FAIL); |
471 | GNUNET_CONVERSATION_call_stop (call); | 488 | GNUNET_CONVERSATION_call_stop(call); |
472 | } | 489 | } |
473 | 490 | ||
474 | 491 | ||
@@ -479,20 +496,20 @@ handle_gns_response (void *cls, | |||
479 | * @param error details about the error | 496 | * @param error details about the error |
480 | */ | 497 | */ |
481 | static void | 498 | static void |
482 | call_error_handler (void *cls, | 499 | call_error_handler(void *cls, |
483 | enum GNUNET_MQ_Error error) | 500 | enum GNUNET_MQ_Error error) |
484 | { | 501 | { |
485 | struct GNUNET_CONVERSATION_Call *call = cls; | 502 | struct GNUNET_CONVERSATION_Call *call = cls; |
486 | 503 | ||
487 | (void) error; | 504 | (void)error; |
488 | if (CS_SHUTDOWN == call->state) | 505 | if (CS_SHUTDOWN == call->state) |
489 | { | 506 | { |
490 | GNUNET_CONVERSATION_call_stop (call); | 507 | GNUNET_CONVERSATION_call_stop(call); |
491 | return; | 508 | return; |
492 | } | 509 | } |
493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 510 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
494 | _("Connection to conversation service lost, trying to reconnect\n")); | 511 | _("Connection to conversation service lost, trying to reconnect\n")); |
495 | fail_call (call); | 512 | fail_call(call); |
496 | } | 513 | } |
497 | 514 | ||
498 | 515 | ||
@@ -502,22 +519,22 @@ call_error_handler (void *cls, | |||
502 | * @param call call to reconnect | 519 | * @param call call to reconnect |
503 | */ | 520 | */ |
504 | static void | 521 | static void |
505 | fail_call (struct GNUNET_CONVERSATION_Call *call) | 522 | fail_call(struct GNUNET_CONVERSATION_Call *call) |
506 | { | 523 | { |
507 | if (CS_ACTIVE == call->state) | 524 | if (CS_ACTIVE == call->state) |
508 | { | 525 | { |
509 | call->speaker->disable_speaker (call->speaker->cls); | 526 | call->speaker->disable_speaker(call->speaker->cls); |
510 | call->mic->disable_microphone (call->mic->cls); | 527 | call->mic->disable_microphone(call->mic->cls); |
511 | } | 528 | } |
512 | if (NULL != call->mq) | 529 | if (NULL != call->mq) |
513 | { | 530 | { |
514 | GNUNET_MQ_destroy (call->mq); | 531 | GNUNET_MQ_destroy(call->mq); |
515 | call->mq = NULL; | 532 | call->mq = NULL; |
516 | } | 533 | } |
517 | call->state = CS_SHUTDOWN; | 534 | call->state = CS_SHUTDOWN; |
518 | call->event_handler (call->event_handler_cls, | 535 | call->event_handler(call->event_handler_cls, |
519 | GNUNET_CONVERSATION_EC_CALL_ERROR); | 536 | GNUNET_CONVERSATION_EC_CALL_ERROR); |
520 | GNUNET_CONVERSATION_call_stop (call); | 537 | GNUNET_CONVERSATION_call_stop(call); |
521 | } | 538 | } |
522 | 539 | ||
523 | 540 | ||
@@ -537,76 +554,76 @@ fail_call (struct GNUNET_CONVERSATION_Call *call) | |||
537 | * @return handle for the call, NULL on hard errors | 554 | * @return handle for the call, NULL on hard errors |
538 | */ | 555 | */ |
539 | struct GNUNET_CONVERSATION_Call * | 556 | struct GNUNET_CONVERSATION_Call * |
540 | GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 557 | GNUNET_CONVERSATION_call_start(const struct GNUNET_CONFIGURATION_Handle *cfg, |
541 | struct GNUNET_IDENTITY_Ego *caller_id, | 558 | struct GNUNET_IDENTITY_Ego *caller_id, |
542 | const char *callee, | 559 | const char *callee, |
543 | struct GNUNET_SPEAKER_Handle *speaker, | 560 | struct GNUNET_SPEAKER_Handle *speaker, |
544 | struct GNUNET_MICROPHONE_Handle *mic, | 561 | struct GNUNET_MICROPHONE_Handle *mic, |
545 | GNUNET_CONVERSATION_CallEventHandler event_handler, | 562 | GNUNET_CONVERSATION_CallEventHandler event_handler, |
546 | void *event_handler_cls) | 563 | void *event_handler_cls) |
547 | { | 564 | { |
548 | struct GNUNET_CONVERSATION_Call *call | 565 | struct GNUNET_CONVERSATION_Call *call |
549 | = GNUNET_new (struct GNUNET_CONVERSATION_Call); | 566 | = GNUNET_new(struct GNUNET_CONVERSATION_Call); |
550 | struct GNUNET_MQ_MessageHandler handlers[] = { | 567 | struct GNUNET_MQ_MessageHandler handlers[] = { |
551 | GNUNET_MQ_hd_fixed_size (call_suspend, | 568 | GNUNET_MQ_hd_fixed_size(call_suspend, |
552 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 569 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
553 | struct ClientPhoneSuspendMessage, | 570 | struct ClientPhoneSuspendMessage, |
554 | call), | 571 | call), |
555 | GNUNET_MQ_hd_fixed_size (call_resume, | 572 | GNUNET_MQ_hd_fixed_size(call_resume, |
556 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 573 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
557 | struct ClientPhoneResumeMessage, | 574 | struct ClientPhoneResumeMessage, |
558 | call), | 575 | call), |
559 | GNUNET_MQ_hd_fixed_size (call_picked_up, | 576 | GNUNET_MQ_hd_fixed_size(call_picked_up, |
560 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, | 577 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, |
561 | struct ClientPhonePickedupMessage, | 578 | struct ClientPhonePickedupMessage, |
562 | call), | 579 | call), |
563 | GNUNET_MQ_hd_fixed_size (call_hangup, | 580 | GNUNET_MQ_hd_fixed_size(call_hangup, |
564 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 581 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
565 | struct ClientPhoneHangupMessage, | 582 | struct ClientPhoneHangupMessage, |
566 | call), | 583 | call), |
567 | GNUNET_MQ_hd_var_size (call_audio, | 584 | GNUNET_MQ_hd_var_size(call_audio, |
568 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 585 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
569 | struct ClientAudioMessage, | 586 | struct ClientAudioMessage, |
570 | call), | 587 | call), |
571 | GNUNET_MQ_handler_end () | 588 | GNUNET_MQ_handler_end() |
572 | }; | 589 | }; |
573 | 590 | ||
574 | call->mq = GNUNET_CLIENT_connect (cfg, | 591 | call->mq = GNUNET_CLIENT_connect(cfg, |
575 | "conversation", | 592 | "conversation", |
576 | handlers, | 593 | handlers, |
577 | &call_error_handler, | 594 | &call_error_handler, |
578 | call); | 595 | call); |
579 | if (NULL == call->mq) | 596 | if (NULL == call->mq) |
580 | { | 597 | { |
581 | GNUNET_break (0); | 598 | GNUNET_break(0); |
582 | GNUNET_free (call); | 599 | GNUNET_free(call); |
583 | return NULL; | 600 | return NULL; |
584 | } | 601 | } |
585 | call->cfg = cfg; | 602 | call->cfg = cfg; |
586 | call->caller_id = caller_id; | 603 | call->caller_id = caller_id; |
587 | call->callee = GNUNET_strdup (callee); | 604 | call->callee = GNUNET_strdup(callee); |
588 | call->speaker = speaker; | 605 | call->speaker = speaker; |
589 | call->mic = mic; | 606 | call->mic = mic; |
590 | call->event_handler = event_handler; | 607 | call->event_handler = event_handler; |
591 | call->event_handler_cls = event_handler_cls; | 608 | call->event_handler_cls = event_handler_cls; |
592 | call->gns = GNUNET_GNS_connect (cfg); | 609 | call->gns = GNUNET_GNS_connect(cfg); |
593 | if (NULL == call->gns) | 610 | if (NULL == call->gns) |
594 | { | 611 | { |
595 | GNUNET_CONVERSATION_call_stop (call); | 612 | GNUNET_CONVERSATION_call_stop(call); |
596 | return NULL; | 613 | return NULL; |
597 | } | 614 | } |
598 | call->state = CS_LOOKUP; | 615 | call->state = CS_LOOKUP; |
599 | call->gns_lookup = GNUNET_GNS_lookup_with_tld (call->gns, | 616 | call->gns_lookup = GNUNET_GNS_lookup_with_tld(call->gns, |
600 | call->callee, | 617 | call->callee, |
601 | GNUNET_GNSRECORD_TYPE_PHONE, | 618 | GNUNET_GNSRECORD_TYPE_PHONE, |
602 | GNUNET_NO, | 619 | GNUNET_NO, |
603 | &handle_gns_response, | 620 | &handle_gns_response, |
604 | call); | 621 | call); |
605 | if (NULL == call->gns_lookup) | 622 | if (NULL == call->gns_lookup) |
606 | { | 623 | { |
607 | GNUNET_CONVERSATION_call_stop (call); | 624 | GNUNET_CONVERSATION_call_stop(call); |
608 | return NULL; | 625 | return NULL; |
609 | } | 626 | } |
610 | return call; | 627 | return call; |
611 | } | 628 | } |
612 | 629 | ||
@@ -617,35 +634,35 @@ GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
617 | * @param call call to terminate | 634 | * @param call call to terminate |
618 | */ | 635 | */ |
619 | void | 636 | void |
620 | GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call) | 637 | GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call) |
621 | { | 638 | { |
622 | if ( (NULL != call->speaker) && | 639 | if ((NULL != call->speaker) && |
623 | (CS_ACTIVE == call->state) ) | 640 | (CS_ACTIVE == call->state)) |
624 | call->speaker->disable_speaker (call->speaker->cls); | 641 | call->speaker->disable_speaker(call->speaker->cls); |
625 | if ( (NULL != call->mic) && | 642 | if ((NULL != call->mic) && |
626 | (CS_ACTIVE == call->state) ) | 643 | (CS_ACTIVE == call->state)) |
627 | call->mic->disable_microphone (call->mic->cls); | 644 | call->mic->disable_microphone(call->mic->cls); |
628 | if (CS_SHUTDOWN != call->state) | 645 | if (CS_SHUTDOWN != call->state) |
629 | { | 646 | { |
630 | call->state = CS_SHUTDOWN; | 647 | call->state = CS_SHUTDOWN; |
631 | } | 648 | } |
632 | if (NULL != call->mq) | 649 | if (NULL != call->mq) |
633 | { | 650 | { |
634 | GNUNET_MQ_destroy (call->mq); | 651 | GNUNET_MQ_destroy(call->mq); |
635 | call->mq = NULL; | 652 | call->mq = NULL; |
636 | } | 653 | } |
637 | if (NULL != call->gns_lookup) | 654 | if (NULL != call->gns_lookup) |
638 | { | 655 | { |
639 | GNUNET_GNS_lookup_with_tld_cancel (call->gns_lookup); | 656 | GNUNET_GNS_lookup_with_tld_cancel(call->gns_lookup); |
640 | call->gns_lookup = NULL; | 657 | call->gns_lookup = NULL; |
641 | } | 658 | } |
642 | if (NULL != call->gns) | 659 | if (NULL != call->gns) |
643 | { | 660 | { |
644 | GNUNET_GNS_disconnect (call->gns); | 661 | GNUNET_GNS_disconnect(call->gns); |
645 | call->gns = NULL; | 662 | call->gns = NULL; |
646 | } | 663 | } |
647 | GNUNET_free (call->callee); | 664 | GNUNET_free(call->callee); |
648 | GNUNET_free (call); | 665 | GNUNET_free(call); |
649 | } | 666 | } |
650 | 667 | ||
651 | 668 | ||
@@ -656,24 +673,24 @@ GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call) | |||
656 | * @param call call to pause | 673 | * @param call call to pause |
657 | */ | 674 | */ |
658 | void | 675 | void |
659 | GNUNET_CONVERSATION_call_suspend (struct GNUNET_CONVERSATION_Call *call) | 676 | GNUNET_CONVERSATION_call_suspend(struct GNUNET_CONVERSATION_Call *call) |
660 | { | 677 | { |
661 | struct GNUNET_MQ_Envelope *e; | 678 | struct GNUNET_MQ_Envelope *e; |
662 | struct ClientPhoneSuspendMessage *suspend; | 679 | struct ClientPhoneSuspendMessage *suspend; |
663 | 680 | ||
664 | GNUNET_assert ( (CS_SUSPENDED_CALLEE == call->state) || | 681 | GNUNET_assert((CS_SUSPENDED_CALLEE == call->state) || |
665 | (CS_ACTIVE == call->state) ); | 682 | (CS_ACTIVE == call->state)); |
666 | if (CS_ACTIVE == call->state) | 683 | if (CS_ACTIVE == call->state) |
667 | { | 684 | { |
668 | call->speaker->disable_speaker (call->speaker->cls); | 685 | call->speaker->disable_speaker(call->speaker->cls); |
669 | call->mic->disable_microphone (call->mic->cls); | 686 | call->mic->disable_microphone(call->mic->cls); |
670 | } | 687 | } |
671 | call->speaker = NULL; | 688 | call->speaker = NULL; |
672 | call->mic = NULL; | 689 | call->mic = NULL; |
673 | e = GNUNET_MQ_msg (suspend, | 690 | e = GNUNET_MQ_msg(suspend, |
674 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 691 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
675 | GNUNET_MQ_send (call->mq, | 692 | GNUNET_MQ_send(call->mq, |
676 | e); | 693 | e); |
677 | if (CS_SUSPENDED_CALLER == call->state) | 694 | if (CS_SUSPENDED_CALLER == call->state) |
678 | call->state = CS_SUSPENDED_BOTH; | 695 | call->state = CS_SUSPENDED_BOTH; |
679 | else | 696 | else |
@@ -690,31 +707,31 @@ GNUNET_CONVERSATION_call_suspend (struct GNUNET_CONVERSATION_Call *call) | |||
690 | * @param mic microphone to use | 707 | * @param mic microphone to use |
691 | */ | 708 | */ |
692 | void | 709 | void |
693 | GNUNET_CONVERSATION_call_resume (struct GNUNET_CONVERSATION_Call *call, | 710 | GNUNET_CONVERSATION_call_resume(struct GNUNET_CONVERSATION_Call *call, |
694 | struct GNUNET_SPEAKER_Handle *speaker, | 711 | struct GNUNET_SPEAKER_Handle *speaker, |
695 | struct GNUNET_MICROPHONE_Handle *mic) | 712 | struct GNUNET_MICROPHONE_Handle *mic) |
696 | { | 713 | { |
697 | struct GNUNET_MQ_Envelope *e; | 714 | struct GNUNET_MQ_Envelope *e; |
698 | struct ClientPhoneResumeMessage *resume; | 715 | struct ClientPhoneResumeMessage *resume; |
699 | 716 | ||
700 | GNUNET_assert ( (CS_SUSPENDED_CALLER == call->state) || | 717 | GNUNET_assert((CS_SUSPENDED_CALLER == call->state) || |
701 | (CS_SUSPENDED_BOTH == call->state) ); | 718 | (CS_SUSPENDED_BOTH == call->state)); |
702 | e = GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 719 | e = GNUNET_MQ_msg(resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
703 | GNUNET_MQ_send (call->mq, e); | 720 | GNUNET_MQ_send(call->mq, e); |
704 | call->speaker = speaker; | 721 | call->speaker = speaker; |
705 | call->mic = mic; | 722 | call->mic = mic; |
706 | if (CS_SUSPENDED_CALLER == call->state) | 723 | if (CS_SUSPENDED_CALLER == call->state) |
707 | { | 724 | { |
708 | call->state = CS_ACTIVE; | 725 | call->state = CS_ACTIVE; |
709 | call->speaker->enable_speaker (call->speaker->cls); | 726 | call->speaker->enable_speaker(call->speaker->cls); |
710 | call->mic->enable_microphone (call->mic->cls, | 727 | call->mic->enable_microphone(call->mic->cls, |
711 | &transmit_call_audio, | 728 | &transmit_call_audio, |
712 | call); | 729 | call); |
713 | } | 730 | } |
714 | else | 731 | else |
715 | { | 732 | { |
716 | call->state = CS_SUSPENDED_CALLEE; | 733 | call->state = CS_SUSPENDED_CALLEE; |
717 | } | 734 | } |
718 | } | 735 | } |
719 | 736 | ||
720 | 737 | ||
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c index 201156f7f..871058233 100644 --- a/src/conversation/gnunet-conversation-test.c +++ b/src/conversation/gnunet-conversation-test.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file conversation/gnunet-conversation-test.c | 22 | * @file conversation/gnunet-conversation-test.c |
@@ -31,14 +31,13 @@ | |||
31 | /** | 31 | /** |
32 | * How long do we record before we replay? | 32 | * How long do we record before we replay? |
33 | */ | 33 | */ |
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * A recording we made. | 38 | * A recording we made. |
39 | */ | 39 | */ |
40 | struct Recording | 40 | struct Recording { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Kept in a DLL. | 42 | * Kept in a DLL. |
44 | */ | 43 | */ |
@@ -98,26 +97,26 @@ static struct Recording *rec_tail; | |||
98 | * @param cls NULL | 97 | * @param cls NULL |
99 | */ | 98 | */ |
100 | static void | 99 | static void |
101 | do_shutdown (void *cls) | 100 | do_shutdown(void *cls) |
102 | { | 101 | { |
103 | struct Recording *rec; | 102 | struct Recording *rec; |
104 | 103 | ||
105 | (void) cls; | 104 | (void)cls; |
106 | if (NULL != switch_task) | 105 | if (NULL != switch_task) |
107 | GNUNET_SCHEDULER_cancel (switch_task); | 106 | GNUNET_SCHEDULER_cancel(switch_task); |
108 | if (NULL != microphone) | 107 | if (NULL != microphone) |
109 | GNUNET_MICROPHONE_destroy (microphone); | 108 | GNUNET_MICROPHONE_destroy(microphone); |
110 | if (NULL != speaker) | 109 | if (NULL != speaker) |
111 | GNUNET_SPEAKER_destroy (speaker); | 110 | GNUNET_SPEAKER_destroy(speaker); |
112 | while (NULL != (rec = rec_head)) | 111 | while (NULL != (rec = rec_head)) |
113 | { | 112 | { |
114 | GNUNET_CONTAINER_DLL_remove (rec_head, | 113 | GNUNET_CONTAINER_DLL_remove(rec_head, |
115 | rec_tail, | 114 | rec_tail, |
116 | rec); | 115 | rec); |
117 | GNUNET_free (rec); | 116 | GNUNET_free(rec); |
118 | } | 117 | } |
119 | fprintf (stderr, | 118 | fprintf(stderr, |
120 | _("\nEnd of transmission. Have a GNU day.\n")); | 119 | _("\nEnd of transmission. Have a GNU day.\n")); |
121 | } | 120 | } |
122 | 121 | ||
123 | 122 | ||
@@ -127,35 +126,35 @@ do_shutdown (void *cls) | |||
127 | * @param cls NULL | 126 | * @param cls NULL |
128 | */ | 127 | */ |
129 | static void | 128 | static void |
130 | switch_to_speaker (void *cls) | 129 | switch_to_speaker(void *cls) |
131 | { | 130 | { |
132 | (void) cls; | 131 | (void)cls; |
133 | switch_task = NULL; | 132 | switch_task = NULL; |
134 | microphone->disable_microphone (microphone->cls); | 133 | microphone->disable_microphone(microphone->cls); |
135 | if (GNUNET_OK != | 134 | if (GNUNET_OK != |
136 | speaker->enable_speaker (speaker->cls)) | 135 | speaker->enable_speaker(speaker->cls)) |
137 | { | 136 | { |
138 | fprintf (stderr, | 137 | fprintf(stderr, |
139 | "Failed to enable microphone\n"); | 138 | "Failed to enable microphone\n"); |
140 | ret = 1; | 139 | ret = 1; |
141 | GNUNET_SCHEDULER_shutdown (); | 140 | GNUNET_SCHEDULER_shutdown(); |
142 | return; | 141 | return; |
143 | } | 142 | } |
144 | fprintf (stderr, | 143 | fprintf(stderr, |
145 | _("\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); | 144 | _("\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); |
146 | for (struct Recording *rec=rec_head; NULL != rec; rec = rec->next) | 145 | for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next) |
147 | { | 146 | { |
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Replaying %u bytes\n", | 148 | "Replaying %u bytes\n", |
150 | (unsigned int) rec->size); | 149 | (unsigned int)rec->size); |
151 | speaker->play (speaker->cls, | 150 | speaker->play(speaker->cls, |
152 | rec->size, | 151 | rec->size, |
153 | &rec[1]); | 152 | &rec[1]); |
154 | } | 153 | } |
155 | GNUNET_SCHEDULER_cancel (st); | 154 | GNUNET_SCHEDULER_cancel(st); |
156 | st = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 155 | st = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
157 | &do_shutdown, | 156 | &do_shutdown, |
158 | NULL); | 157 | NULL); |
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
@@ -167,22 +166,22 @@ switch_to_speaker (void *cls) | |||
167 | * @param data audio data to play | 166 | * @param data audio data to play |
168 | */ | 167 | */ |
169 | static void | 168 | static void |
170 | record (void *cls, | 169 | record(void *cls, |
171 | size_t data_size, | 170 | size_t data_size, |
172 | const void *data) | 171 | const void *data) |
173 | { | 172 | { |
174 | struct Recording *rec; | 173 | struct Recording *rec; |
175 | 174 | ||
176 | (void) cls; | 175 | (void)cls; |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
178 | "Recorded %u bytes\n", | 177 | "Recorded %u bytes\n", |
179 | (unsigned int) data_size); | 178 | (unsigned int)data_size); |
180 | rec = GNUNET_malloc (sizeof (struct Recording) + data_size); | 179 | rec = GNUNET_malloc(sizeof(struct Recording) + data_size); |
181 | rec->size = data_size; | 180 | rec->size = data_size; |
182 | GNUNET_memcpy (&rec[1], data, data_size); | 181 | GNUNET_memcpy(&rec[1], data, data_size); |
183 | GNUNET_CONTAINER_DLL_insert_tail (rec_head, | 182 | GNUNET_CONTAINER_DLL_insert_tail(rec_head, |
184 | rec_tail, | 183 | rec_tail, |
185 | rec); | 184 | rec); |
186 | } | 185 | } |
187 | 186 | ||
188 | 187 | ||
@@ -195,36 +194,36 @@ record (void *cls, | |||
195 | * @param cfg configuration | 194 | * @param cfg configuration |
196 | */ | 195 | */ |
197 | static void | 196 | static void |
198 | run (void *cls, | 197 | run(void *cls, |
199 | char *const *args, | 198 | char *const *args, |
200 | const char *cfgfile, | 199 | const char *cfgfile, |
201 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 200 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
202 | { | 201 | { |
203 | (void) cls; | 202 | (void)cls; |
204 | (void) args; | 203 | (void)args; |
205 | (void) cfgfile; | 204 | (void)cfgfile; |
206 | microphone = GNUNET_MICROPHONE_create_from_hardware (cfg); | 205 | microphone = GNUNET_MICROPHONE_create_from_hardware(cfg); |
207 | GNUNET_assert (NULL != microphone); | 206 | GNUNET_assert(NULL != microphone); |
208 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); | 207 | speaker = GNUNET_SPEAKER_create_from_hardware(cfg); |
209 | GNUNET_assert (NULL != speaker); | 208 | GNUNET_assert(NULL != speaker); |
210 | switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 209 | switch_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
211 | &switch_to_speaker, | 210 | &switch_to_speaker, |
212 | NULL); | 211 | NULL); |
213 | st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 212 | st = GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
214 | NULL); | 213 | NULL); |
215 | fprintf (stderr, | 214 | fprintf(stderr, |
216 | _("We will now be recording you for %s. After that time, the recording will be played back to you..."), | 215 | _("We will now be recording you for %s. After that time, the recording will be played back to you..."), |
217 | GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES)); | 216 | GNUNET_STRINGS_relative_time_to_string(TIMEOUT, GNUNET_YES)); |
218 | if (GNUNET_OK != | 217 | if (GNUNET_OK != |
219 | microphone->enable_microphone (microphone->cls, | 218 | microphone->enable_microphone(microphone->cls, |
220 | &record, NULL)) | 219 | &record, NULL)) |
221 | { | 220 | { |
222 | fprintf (stderr, | 221 | fprintf(stderr, |
223 | "Failed to enable microphone\n"); | 222 | "Failed to enable microphone\n"); |
224 | ret = 1; | 223 | ret = 1; |
225 | GNUNET_SCHEDULER_shutdown (); | 224 | GNUNET_SCHEDULER_shutdown(); |
226 | return; | 225 | return; |
227 | } | 226 | } |
228 | } | 227 | } |
229 | 228 | ||
230 | 229 | ||
@@ -236,26 +235,26 @@ run (void *cls, | |||
236 | * @return 0 ok, 1 on error | 235 | * @return 0 ok, 1 on error |
237 | */ | 236 | */ |
238 | int | 237 | int |
239 | main (int argc, | 238 | main(int argc, |
240 | char *const *argv) | 239 | char *const *argv) |
241 | { | 240 | { |
242 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 241 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
243 | GNUNET_GETOPT_OPTION_END | 242 | GNUNET_GETOPT_OPTION_END |
244 | }; | 243 | }; |
245 | 244 | ||
246 | if (GNUNET_OK != | 245 | if (GNUNET_OK != |
247 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 246 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
248 | &argc, &argv)) | 247 | &argc, &argv)) |
249 | return 2; | 248 | return 2; |
250 | 249 | ||
251 | ret = (GNUNET_OK == | 250 | ret = (GNUNET_OK == |
252 | GNUNET_PROGRAM_run (argc, argv, | 251 | GNUNET_PROGRAM_run(argc, argv, |
253 | "gnunet-conversation-test", | 252 | "gnunet-conversation-test", |
254 | gettext_noop ("help text"), | 253 | gettext_noop("help text"), |
255 | options, | 254 | options, |
256 | &run, | 255 | &run, |
257 | NULL)) ? ret : 1; | 256 | NULL)) ? ret : 1; |
258 | GNUNET_free ((void*) argv); | 257 | GNUNET_free((void*)argv); |
259 | return ret; | 258 | return ret; |
260 | } | 259 | } |
261 | 260 | ||
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index 4c5407cd7..20765bbf6 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-conversation.c | 21 | * @file conversation/gnunet-conversation.c |
22 | * @brief conversation implementation | 22 | * @brief conversation implementation |
@@ -38,7 +38,7 @@ | |||
38 | */ | 38 | */ |
39 | #define MAX_MESSAGE_LENGTH 1024 | 39 | #define MAX_MESSAGE_LENGTH 1024 |
40 | 40 | ||
41 | #define XSTRINGIFY(x) STRINGIFY (x) | 41 | #define XSTRINGIFY(x) STRINGIFY(x) |
42 | 42 | ||
43 | #define STRINGIFY(x) (#x) | 43 | #define STRINGIFY(x) (#x) |
44 | 44 | ||
@@ -52,8 +52,7 @@ struct GNUNET_HELPER_Handle *stdin_hlp; | |||
52 | /** | 52 | /** |
53 | * Possible states of the phone. | 53 | * Possible states of the phone. |
54 | */ | 54 | */ |
55 | enum PhoneState | 55 | enum PhoneState { |
56 | { | ||
57 | /** | 56 | /** |
58 | * We're waiting for our own idenitty. | 57 | * We're waiting for our own idenitty. |
59 | */ | 58 | */ |
@@ -79,8 +78,7 @@ enum PhoneState | |||
79 | /** | 78 | /** |
80 | * States for current outgoing call. | 79 | * States for current outgoing call. |
81 | */ | 80 | */ |
82 | enum CallState | 81 | enum CallState { |
83 | { | ||
84 | /** | 82 | /** |
85 | * We are looking up some other participant. | 83 | * We are looking up some other participant. |
86 | */ | 84 | */ |
@@ -100,16 +98,13 @@ enum CallState | |||
100 | * The call is currently suspended (by us). | 98 | * The call is currently suspended (by us). |
101 | */ | 99 | */ |
102 | CS_SUSPENDED | 100 | CS_SUSPENDED |
103 | |||
104 | }; | 101 | }; |
105 | 102 | ||
106 | 103 | ||
107 | /** | 104 | /** |
108 | * List of incoming calls | 105 | * List of incoming calls |
109 | */ | 106 | */ |
110 | struct CallList | 107 | struct CallList { |
111 | { | ||
112 | |||
113 | /** | 108 | /** |
114 | * A DLL. | 109 | * A DLL. |
115 | */ | 110 | */ |
@@ -253,63 +248,64 @@ static int verbose; | |||
253 | * @param caller_id public key of the caller (in GNS) | 248 | * @param caller_id public key of the caller (in GNS) |
254 | */ | 249 | */ |
255 | static void | 250 | static void |
256 | phone_event_handler (void *cls, | 251 | phone_event_handler(void *cls, |
257 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 252 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
258 | struct GNUNET_CONVERSATION_Caller *caller, | 253 | struct GNUNET_CONVERSATION_Caller *caller, |
259 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 254 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
260 | { | 255 | { |
261 | struct CallList *cl; | 256 | struct CallList *cl; |
262 | 257 | ||
263 | (void) cls; | 258 | (void)cls; |
264 | switch (code) | 259 | switch (code) |
265 | { | ||
266 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
267 | /* | ||
268 | * FIXME: we should be playing our ringtones from contrib/sounds now! | ||
269 | * | ||
270 | ring_my_bell(); | ||
271 | * | ||
272 | * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here | ||
273 | */ | ||
274 | fprintf ( | ||
275 | stdout, | ||
276 | _ ( | ||
277 | "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), | ||
278 | GNUNET_GNSRECORD_pkey_to_zkey (caller_id), | ||
279 | caller_num_gen, | ||
280 | caller_num_gen); | ||
281 | cl = GNUNET_new (struct CallList); | ||
282 | cl->caller = caller; | ||
283 | cl->caller_id = *caller_id; | ||
284 | cl->caller_num = caller_num_gen++; | ||
285 | GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl); | ||
286 | break; | ||
287 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
288 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
289 | if (caller == cl->caller) | ||
290 | break; | ||
291 | if ((NULL == cl) && (caller == cl_active->caller)) | ||
292 | cl = cl_active; | ||
293 | if (NULL == cl) | ||
294 | { | ||
295 | GNUNET_break (0); | ||
296 | return; | ||
297 | } | ||
298 | fprintf (stdout, | ||
299 | _ ("Call from `%s' terminated\n"), | ||
300 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); | ||
301 | if (cl == cl_active) | ||
302 | { | 260 | { |
303 | cl_active = NULL; | 261 | case GNUNET_CONVERSATION_EC_PHONE_RING: |
304 | phone_state = PS_LISTEN; | 262 | /* |
305 | } | 263 | * FIXME: we should be playing our ringtones from contrib/sounds now! |
306 | else | 264 | * |
307 | { | 265 | ring_my_bell(); |
308 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); | 266 | * |
267 | * see https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html on how to play a wav using the gst framework being used here | ||
268 | */ | ||
269 | fprintf( | ||
270 | stdout, | ||
271 | _( | ||
272 | "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), | ||
273 | GNUNET_GNSRECORD_pkey_to_zkey(caller_id), | ||
274 | caller_num_gen, | ||
275 | caller_num_gen); | ||
276 | cl = GNUNET_new(struct CallList); | ||
277 | cl->caller = caller; | ||
278 | cl->caller_id = *caller_id; | ||
279 | cl->caller_num = caller_num_gen++; | ||
280 | GNUNET_CONTAINER_DLL_insert(cl_head, cl_tail, cl); | ||
281 | break; | ||
282 | |||
283 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
284 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
285 | if (caller == cl->caller) | ||
286 | break; | ||
287 | if ((NULL == cl) && (caller == cl_active->caller)) | ||
288 | cl = cl_active; | ||
289 | if (NULL == cl) | ||
290 | { | ||
291 | GNUNET_break(0); | ||
292 | return; | ||
293 | } | ||
294 | fprintf(stdout, | ||
295 | _("Call from `%s' terminated\n"), | ||
296 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | ||
297 | if (cl == cl_active) | ||
298 | { | ||
299 | cl_active = NULL; | ||
300 | phone_state = PS_LISTEN; | ||
301 | } | ||
302 | else | ||
303 | { | ||
304 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); | ||
305 | } | ||
306 | GNUNET_free(cl); | ||
307 | break; | ||
309 | } | 308 | } |
310 | GNUNET_free (cl); | ||
311 | break; | ||
312 | } | ||
313 | } | 309 | } |
314 | 310 | ||
315 | 311 | ||
@@ -320,23 +316,24 @@ phone_event_handler (void *cls, | |||
320 | * @param code type of the event issued by the caller | 316 | * @param code type of the event issued by the caller |
321 | */ | 317 | */ |
322 | static void | 318 | static void |
323 | caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | 319 | caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) |
324 | { | 320 | { |
325 | struct CallList *cl = cls; | 321 | struct CallList *cl = cls; |
326 | 322 | ||
327 | switch (code) | 323 | switch (code) |
328 | { | 324 | { |
329 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | 325 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: |
330 | fprintf (stdout, | 326 | fprintf(stdout, |
331 | _ ("Call from `%s' suspended by other user\n"), | 327 | _("Call from `%s' suspended by other user\n"), |
332 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); | 328 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); |
333 | break; | 329 | break; |
334 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | 330 | |
335 | fprintf (stdout, | 331 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: |
336 | _ ("Call from `%s' resumed by other user\n"), | 332 | fprintf(stdout, |
337 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); | 333 | _("Call from `%s' resumed by other user\n"), |
338 | break; | 334 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); |
339 | } | 335 | break; |
336 | } | ||
340 | } | 337 | } |
341 | 338 | ||
342 | 339 | ||
@@ -344,42 +341,42 @@ caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | |||
344 | * Start our phone. | 341 | * Start our phone. |
345 | */ | 342 | */ |
346 | static void | 343 | static void |
347 | start_phone () | 344 | start_phone() |
348 | { | 345 | { |
349 | struct GNUNET_GNSRECORD_Data rd; | 346 | struct GNUNET_GNSRECORD_Data rd; |
350 | 347 | ||
351 | if (NULL == my_caller_id) | 348 | if (NULL == my_caller_id) |
352 | { | 349 | { |
353 | fprintf (stderr, | 350 | fprintf(stderr, |
354 | _ ("Ego `%s' no longer available, phone is now down.\n"), | 351 | _("Ego `%s' no longer available, phone is now down.\n"), |
355 | ego_name); | 352 | ego_name); |
356 | phone_state = PS_LOOKUP_EGO; | 353 | phone_state = PS_LOOKUP_EGO; |
357 | return; | 354 | return; |
358 | } | 355 | } |
359 | GNUNET_assert (NULL == phone); | 356 | GNUNET_assert(NULL == phone); |
360 | phone = GNUNET_CONVERSATION_phone_create (cfg, | 357 | phone = GNUNET_CONVERSATION_phone_create(cfg, |
361 | my_caller_id, | 358 | my_caller_id, |
362 | &phone_event_handler, | 359 | &phone_event_handler, |
363 | NULL); | 360 | NULL); |
364 | /* FIXME: get record and print full GNS record info later here... */ | 361 | /* FIXME: get record and print full GNS record info later here... */ |
365 | if (NULL == phone) | 362 | if (NULL == phone) |
366 | { | 363 | { |
367 | fprintf (stderr, "%s", _ ("Failed to setup phone (internal error)\n")); | 364 | fprintf(stderr, "%s", _("Failed to setup phone (internal error)\n")); |
368 | phone_state = PS_ERROR; | 365 | phone_state = PS_ERROR; |
369 | } | 366 | } |
370 | else | 367 | else |
371 | { | 368 | { |
372 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | 369 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); |
373 | GNUNET_free_non_null (address); | 370 | GNUNET_free_non_null(address); |
374 | address = | 371 | address = |
375 | GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, rd.data_size); | 372 | GNUNET_GNSRECORD_value_to_string(rd.record_type, rd.data, rd.data_size); |
376 | fprintf ( | 373 | fprintf( |
377 | stdout, | 374 | stdout, |
378 | _ ( | 375 | _( |
379 | "Phone active at `%s'. Type `/help' for a list of available commands\n"), | 376 | "Phone active at `%s'. Type `/help' for a list of available commands\n"), |
380 | address); | 377 | address); |
381 | phone_state = PS_LISTEN; | 378 | phone_state = PS_LISTEN; |
382 | } | 379 | } |
383 | } | 380 | } |
384 | 381 | ||
385 | 382 | ||
@@ -390,56 +387,62 @@ start_phone () | |||
390 | * @param code type of the event on the call | 387 | * @param code type of the event on the call |
391 | */ | 388 | */ |
392 | static void | 389 | static void |
393 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 390 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
394 | { | 391 | { |
395 | (void) cls; | 392 | (void)cls; |
396 | 393 | ||
397 | switch (code) | 394 | switch (code) |
398 | { | 395 | { |
399 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 396 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
400 | GNUNET_break (CS_RESOLVING == call_state); | 397 | GNUNET_break(CS_RESOLVING == call_state); |
401 | fprintf (stdout, | 398 | fprintf(stdout, |
402 | _ ("Resolved address of `%s'. Now ringing other party.\n"), | 399 | _("Resolved address of `%s'. Now ringing other party.\n"), |
403 | peer_name); | 400 | peer_name); |
404 | call_state = CS_RINGING; | 401 | call_state = CS_RINGING; |
405 | break; | 402 | break; |
406 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 403 | |
407 | GNUNET_break (CS_RINGING == call_state); | 404 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
408 | fprintf (stdout, _ ("Connection established to `%s'\n"), peer_name); | 405 | GNUNET_break(CS_RINGING == call_state); |
409 | call_state = CS_CONNECTED; | 406 | fprintf(stdout, _("Connection established to `%s'\n"), peer_name); |
410 | break; | 407 | call_state = CS_CONNECTED; |
411 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 408 | break; |
412 | GNUNET_break (CS_RESOLVING == call_state); | 409 | |
413 | fprintf (stdout, _ ("Failed to resolve `%s'\n"), peer_name); | 410 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
414 | GNUNET_free (peer_name); | 411 | GNUNET_break(CS_RESOLVING == call_state); |
415 | peer_name = NULL; | 412 | fprintf(stdout, _("Failed to resolve `%s'\n"), peer_name); |
416 | call = NULL; | 413 | GNUNET_free(peer_name); |
417 | break; | 414 | peer_name = NULL; |
418 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 415 | call = NULL; |
419 | fprintf (stdout, _ ("Call to `%s' terminated\n"), peer_name); | 416 | break; |
420 | GNUNET_free (peer_name); | 417 | |
421 | peer_name = NULL; | 418 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
422 | call = NULL; | 419 | fprintf(stdout, _("Call to `%s' terminated\n"), peer_name); |
423 | break; | 420 | GNUNET_free(peer_name); |
424 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 421 | peer_name = NULL; |
425 | GNUNET_break (CS_CONNECTED == call_state); | 422 | call = NULL; |
426 | fprintf (stdout, | 423 | break; |
427 | _ ("Connection to `%s' suspended (by other user)\n"), | 424 | |
428 | peer_name); | 425 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
429 | break; | 426 | GNUNET_break(CS_CONNECTED == call_state); |
430 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 427 | fprintf(stdout, |
431 | GNUNET_break (CS_CONNECTED == call_state); | 428 | _("Connection to `%s' suspended (by other user)\n"), |
432 | fprintf (stdout, | 429 | peer_name); |
433 | _ ("Connection to `%s' resumed (by other user)\n"), | 430 | break; |
434 | peer_name); | 431 | |
435 | break; | 432 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
436 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 433 | GNUNET_break(CS_CONNECTED == call_state); |
437 | fprintf (stdout, _ ("Error with the call, restarting it\n")); | 434 | fprintf(stdout, |
438 | GNUNET_free (peer_name); | 435 | _("Connection to `%s' resumed (by other user)\n"), |
439 | peer_name = NULL; | 436 | peer_name); |
440 | call = NULL; | 437 | break; |
441 | break; | 438 | |
442 | } | 439 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
440 | fprintf(stdout, _("Error with the call, restarting it\n")); | ||
441 | GNUNET_free(peer_name); | ||
442 | peer_name = NULL; | ||
443 | call = NULL; | ||
444 | break; | ||
445 | } | ||
443 | } | 446 | } |
444 | 447 | ||
445 | 448 | ||
@@ -454,8 +457,7 @@ typedef void (*ActionFunction) (const char *arguments); | |||
454 | /** | 457 | /** |
455 | * Structure which defines a command | 458 | * Structure which defines a command |
456 | */ | 459 | */ |
457 | struct VoipCommand | 460 | struct VoipCommand { |
458 | { | ||
459 | /** | 461 | /** |
460 | * Command the user needs to enter. | 462 | * Command the user needs to enter. |
461 | */ | 463 | */ |
@@ -479,7 +481,7 @@ struct VoipCommand | |||
479 | * @param args arguments given to the command | 481 | * @param args arguments given to the command |
480 | */ | 482 | */ |
481 | static void | 483 | static void |
482 | do_help (const char *args); | 484 | do_help(const char *args); |
483 | 485 | ||
484 | 486 | ||
485 | /** | 487 | /** |
@@ -488,10 +490,10 @@ do_help (const char *args); | |||
488 | * @param args arguments given to the command | 490 | * @param args arguments given to the command |
489 | */ | 491 | */ |
490 | static void | 492 | static void |
491 | do_quit (const char *args) | 493 | do_quit(const char *args) |
492 | { | 494 | { |
493 | (void) args; | 495 | (void)args; |
494 | GNUNET_SCHEDULER_shutdown (); | 496 | GNUNET_SCHEDULER_shutdown(); |
495 | } | 497 | } |
496 | 498 | ||
497 | 499 | ||
@@ -501,9 +503,9 @@ do_quit (const char *args) | |||
501 | * @param msg arguments given to the command | 503 | * @param msg arguments given to the command |
502 | */ | 504 | */ |
503 | static void | 505 | static void |
504 | do_unknown (const char *msg) | 506 | do_unknown(const char *msg) |
505 | { | 507 | { |
506 | fprintf (stderr, _ ("Unknown command `%s'\n"), msg); | 508 | fprintf(stderr, _("Unknown command `%s'\n"), msg); |
507 | } | 509 | } |
508 | 510 | ||
509 | 511 | ||
@@ -513,54 +515,57 @@ do_unknown (const char *msg) | |||
513 | * @param arg arguments given to the command | 515 | * @param arg arguments given to the command |
514 | */ | 516 | */ |
515 | static void | 517 | static void |
516 | do_call (const char *arg) | 518 | do_call(const char *arg) |
517 | { | 519 | { |
518 | if (NULL == my_caller_id) | 520 | if (NULL == my_caller_id) |
519 | { | 521 | { |
520 | fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name); | 522 | fprintf(stderr, _("Ego `%s' not available\n"), ego_name); |
521 | return; | 523 | return; |
522 | } | 524 | } |
523 | if (NULL != call) | 525 | if (NULL != call) |
524 | { | 526 | { |
525 | fprintf (stderr, | 527 | fprintf(stderr, |
526 | _ ("You are calling someone else already, hang up first!\n")); | 528 | _("You are calling someone else already, hang up first!\n")); |
527 | return; | 529 | return; |
528 | } | 530 | } |
529 | switch (phone_state) | 531 | switch (phone_state) |
530 | { | 532 | { |
531 | case PS_LOOKUP_EGO: | 533 | case PS_LOOKUP_EGO: |
532 | fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name); | 534 | fprintf(stderr, _("Ego `%s' not available\n"), ego_name); |
533 | return; | 535 | return; |
534 | case PS_LISTEN: | 536 | |
535 | /* ok to call! */ | 537 | case PS_LISTEN: |
536 | break; | 538 | /* ok to call! */ |
537 | case PS_ACCEPTED: | 539 | break; |
538 | fprintf ( | 540 | |
539 | stderr, | 541 | case PS_ACCEPTED: |
540 | _ ( | 542 | fprintf( |
541 | "You are answering call from `%s', hang up or suspend that call first!\n"), | 543 | stderr, |
542 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | 544 | _( |
543 | return; | 545 | "You are answering call from `%s', hang up or suspend that call first!\n"), |
544 | case PS_ERROR: | 546 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); |
545 | /* ok to call */ | 547 | return; |
546 | break; | 548 | |
547 | } | 549 | case PS_ERROR: |
550 | /* ok to call */ | ||
551 | break; | ||
552 | } | ||
548 | if (NULL == arg) | 553 | if (NULL == arg) |
549 | { | 554 | { |
550 | fprintf (stderr, _ ("Call recipient missing.\n")); | 555 | fprintf(stderr, _("Call recipient missing.\n")); |
551 | do_help ("/call"); | 556 | do_help("/call"); |
552 | return; | 557 | return; |
553 | } | 558 | } |
554 | peer_name = GNUNET_strdup (arg); | 559 | peer_name = GNUNET_strdup(arg); |
555 | call_state = CS_RESOLVING; | 560 | call_state = CS_RESOLVING; |
556 | GNUNET_assert (NULL == call); | 561 | GNUNET_assert(NULL == call); |
557 | call = GNUNET_CONVERSATION_call_start (cfg, | 562 | call = GNUNET_CONVERSATION_call_start(cfg, |
558 | my_caller_id, | 563 | my_caller_id, |
559 | arg, | 564 | arg, |
560 | speaker, | 565 | speaker, |
561 | mic, | 566 | mic, |
562 | &call_event_handler, | 567 | &call_event_handler, |
563 | NULL); | 568 | NULL); |
564 | } | 569 | } |
565 | 570 | ||
566 | 571 | ||
@@ -570,67 +575,70 @@ do_call (const char *arg) | |||
570 | * @param args arguments given to the command | 575 | * @param args arguments given to the command |
571 | */ | 576 | */ |
572 | static void | 577 | static void |
573 | do_accept (const char *args) | 578 | do_accept(const char *args) |
574 | { | 579 | { |
575 | struct CallList *cl; | 580 | struct CallList *cl; |
576 | char buf[32]; | 581 | char buf[32]; |
577 | 582 | ||
578 | if ((NULL != call) && (CS_SUSPENDED != call_state)) | 583 | if ((NULL != call) && (CS_SUSPENDED != call_state)) |
579 | { | 584 | { |
580 | fprintf (stderr, | 585 | fprintf(stderr, |
581 | _ ("You are calling someone else already, hang up first!\n")); | 586 | _("You are calling someone else already, hang up first!\n")); |
582 | return; | 587 | return; |
583 | } | 588 | } |
584 | switch (phone_state) | 589 | switch (phone_state) |
585 | { | 590 | { |
586 | case PS_LOOKUP_EGO: | 591 | case PS_LOOKUP_EGO: |
587 | GNUNET_break (0); | 592 | GNUNET_break(0); |
588 | break; | 593 | break; |
589 | case PS_LISTEN: | 594 | |
590 | /* this is the expected state */ | 595 | case PS_LISTEN: |
591 | break; | 596 | /* this is the expected state */ |
592 | case PS_ACCEPTED: | 597 | break; |
593 | fprintf ( | 598 | |
594 | stderr, | 599 | case PS_ACCEPTED: |
595 | _ ( | 600 | fprintf( |
596 | "You are answering call from `%s', hang up or suspend that call first!\n"), | 601 | stderr, |
597 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | 602 | _( |
598 | return; | 603 | "You are answering call from `%s', hang up or suspend that call first!\n"), |
599 | case PS_ERROR: | 604 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); |
600 | GNUNET_break (0); | 605 | return; |
601 | break; | 606 | |
602 | } | 607 | case PS_ERROR: |
608 | GNUNET_break(0); | ||
609 | break; | ||
610 | } | ||
603 | cl = cl_head; | 611 | cl = cl_head; |
604 | if (NULL == cl) | 612 | if (NULL == cl) |
605 | { | 613 | { |
606 | fprintf (stderr, _ ("There is no incoming call to accept here!\n")); | 614 | fprintf(stderr, _("There is no incoming call to accept here!\n")); |
607 | return; | 615 | return; |
608 | } | 616 | } |
609 | if ((NULL != cl->next) || (NULL != args)) | 617 | if ((NULL != cl->next) || (NULL != args)) |
610 | { | ||
611 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
612 | { | 618 | { |
613 | GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num); | 619 | for (cl = cl_head; NULL != cl; cl = cl->next) |
614 | if (0 == strcmp (buf, args)) | 620 | { |
615 | break; | 621 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); |
622 | if (0 == strcmp(buf, args)) | ||
623 | break; | ||
624 | } | ||
616 | } | 625 | } |
617 | } | ||
618 | if (NULL == cl) | 626 | if (NULL == cl) |
619 | { | 627 | { |
620 | fprintf (stderr, | 628 | fprintf(stderr, |
621 | _ ("There is no incoming call `%s' to accept right now!\n"), | 629 | _("There is no incoming call `%s' to accept right now!\n"), |
622 | args); | 630 | args); |
623 | return; | 631 | return; |
624 | } | 632 | } |
625 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); | 633 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); |
626 | cl_active = cl; | 634 | cl_active = cl; |
627 | peer_key = cl->caller_id; | 635 | peer_key = cl->caller_id; |
628 | phone_state = PS_ACCEPTED; | 636 | phone_state = PS_ACCEPTED; |
629 | GNUNET_CONVERSATION_caller_pick_up (cl->caller, | 637 | GNUNET_CONVERSATION_caller_pick_up(cl->caller, |
630 | &caller_event_handler, | 638 | &caller_event_handler, |
631 | cl, | 639 | cl, |
632 | speaker, | 640 | speaker, |
633 | mic); | 641 | mic); |
634 | } | 642 | } |
635 | 643 | ||
636 | 644 | ||
@@ -640,15 +648,15 @@ do_accept (const char *args) | |||
640 | * @param args arguments given to the command | 648 | * @param args arguments given to the command |
641 | */ | 649 | */ |
642 | static void | 650 | static void |
643 | do_address (const char *args) | 651 | do_address(const char *args) |
644 | { | 652 | { |
645 | (void) args; | 653 | (void)args; |
646 | if (NULL == address) | 654 | if (NULL == address) |
647 | { | 655 | { |
648 | fprintf (stdout, "%s", _ ("We currently do not have an address.\n")); | 656 | fprintf(stdout, "%s", _("We currently do not have an address.\n")); |
649 | return; | 657 | return; |
650 | } | 658 | } |
651 | fprintf (stdout, "%s\n", address); | 659 | fprintf(stdout, "%s\n", address); |
652 | } | 660 | } |
653 | 661 | ||
654 | 662 | ||
@@ -658,78 +666,84 @@ do_address (const char *args) | |||
658 | * @param args arguments given to the command | 666 | * @param args arguments given to the command |
659 | */ | 667 | */ |
660 | static void | 668 | static void |
661 | do_status (const char *args) | 669 | do_status(const char *args) |
662 | { | 670 | { |
663 | struct CallList *cl; | 671 | struct CallList *cl; |
664 | 672 | ||
665 | (void) args; | 673 | (void)args; |
666 | switch (phone_state) | 674 | switch (phone_state) |
667 | { | ||
668 | case PS_LOOKUP_EGO: | ||
669 | fprintf ( | ||
670 | stdout, | ||
671 | _ ( | ||
672 | "We are currently trying to locate the private key for the ego `%s'.\n"), | ||
673 | ego_name); | ||
674 | break; | ||
675 | case PS_LISTEN: | ||
676 | fprintf (stdout, | ||
677 | _ ( | ||
678 | "We are listening for incoming calls for ego `%s' on line `%s'.\n"), | ||
679 | ego_name, | ||
680 | line); | ||
681 | break; | ||
682 | case PS_ACCEPTED: | ||
683 | fprintf (stdout, | ||
684 | _ ("You are having a conversation with `%s'.\n"), | ||
685 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | ||
686 | ; | ||
687 | break; | ||
688 | case PS_ERROR: | ||
689 | fprintf ( | ||
690 | stdout, | ||
691 | _ ( | ||
692 | "We had an internal error setting up our phone line. You can still make calls.\n")); | ||
693 | break; | ||
694 | } | ||
695 | if (NULL != call) | ||
696 | { | ||
697 | switch (call_state) | ||
698 | { | 675 | { |
699 | case CS_RESOLVING: | 676 | case PS_LOOKUP_EGO: |
700 | fprintf (stdout, | 677 | fprintf( |
701 | _ ("We are trying to find the network address to call `%s'.\n"), | 678 | stdout, |
702 | peer_name); | 679 | _( |
680 | "We are currently trying to locate the private key for the ego `%s'.\n"), | ||
681 | ego_name); | ||
703 | break; | 682 | break; |
704 | case CS_RINGING: | 683 | |
705 | fprintf (stdout, | 684 | case PS_LISTEN: |
706 | _ ("We are calling `%s', their phone should be ringing.\n"), | 685 | fprintf(stdout, |
707 | peer_name); | 686 | _( |
687 | "We are listening for incoming calls for ego `%s' on line `%s'.\n"), | ||
688 | ego_name, | ||
689 | line); | ||
708 | break; | 690 | break; |
709 | case CS_CONNECTED: | 691 | |
710 | fprintf (stdout, | 692 | case PS_ACCEPTED: |
711 | _ ("You are having a conversation with `%s'.\n"), | 693 | fprintf(stdout, |
712 | peer_name); | 694 | _("You are having a conversation with `%s'.\n"), |
695 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | ||
696 | ; | ||
713 | break; | 697 | break; |
714 | case CS_SUSPENDED: | 698 | |
715 | /* ok to accept incoming call right now */ | 699 | case PS_ERROR: |
700 | fprintf( | ||
701 | stdout, | ||
702 | _( | ||
703 | "We had an internal error setting up our phone line. You can still make calls.\n")); | ||
716 | break; | 704 | break; |
717 | } | 705 | } |
718 | } | 706 | if (NULL != call) |
707 | { | ||
708 | switch (call_state) | ||
709 | { | ||
710 | case CS_RESOLVING: | ||
711 | fprintf(stdout, | ||
712 | _("We are trying to find the network address to call `%s'.\n"), | ||
713 | peer_name); | ||
714 | break; | ||
715 | |||
716 | case CS_RINGING: | ||
717 | fprintf(stdout, | ||
718 | _("We are calling `%s', their phone should be ringing.\n"), | ||
719 | peer_name); | ||
720 | break; | ||
721 | |||
722 | case CS_CONNECTED: | ||
723 | fprintf(stdout, | ||
724 | _("You are having a conversation with `%s'.\n"), | ||
725 | peer_name); | ||
726 | break; | ||
727 | |||
728 | case CS_SUSPENDED: | ||
729 | /* ok to accept incoming call right now */ | ||
730 | break; | ||
731 | } | ||
732 | } | ||
719 | if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail))) | 733 | if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail))) |
720 | { | ||
721 | fprintf (stdout, "%s", _ ("Calls waiting:\n")); | ||
722 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
723 | { | 734 | { |
724 | if (cl == cl_active) | 735 | fprintf(stdout, "%s", _("Calls waiting:\n")); |
725 | continue; | 736 | for (cl = cl_head; NULL != cl; cl = cl->next) |
726 | fprintf (stdout, | 737 | { |
727 | _ ("#%u: `%s'\n"), | 738 | if (cl == cl_active) |
728 | cl->caller_num, | 739 | continue; |
729 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); | 740 | fprintf(stdout, |
741 | _("#%u: `%s'\n"), | ||
742 | cl->caller_num, | ||
743 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | ||
744 | } | ||
745 | fprintf(stdout, "%s", "\n"); | ||
730 | } | 746 | } |
731 | fprintf (stdout, "%s", "\n"); | ||
732 | } | ||
733 | } | 747 | } |
734 | 748 | ||
735 | 749 | ||
@@ -739,41 +753,43 @@ do_status (const char *args) | |||
739 | * @param args arguments given to the command | 753 | * @param args arguments given to the command |
740 | */ | 754 | */ |
741 | static void | 755 | static void |
742 | do_suspend (const char *args) | 756 | do_suspend(const char *args) |
743 | { | 757 | { |
744 | (void) args; | 758 | (void)args; |
745 | if (NULL != call) | 759 | if (NULL != call) |
746 | { | ||
747 | switch (call_state) | ||
748 | { | 760 | { |
749 | case CS_RESOLVING: | 761 | switch (call_state) |
750 | case CS_RINGING: | 762 | { |
751 | case CS_SUSPENDED: | 763 | case CS_RESOLVING: |
752 | fprintf (stderr, | 764 | case CS_RINGING: |
753 | "%s", | 765 | case CS_SUSPENDED: |
754 | _ ("There is no call that could be suspended right now.\n")); | 766 | fprintf(stderr, |
755 | return; | 767 | "%s", |
756 | case CS_CONNECTED: | 768 | _("There is no call that could be suspended right now.\n")); |
757 | call_state = CS_SUSPENDED; | 769 | return; |
758 | GNUNET_CONVERSATION_call_suspend (call); | 770 | |
759 | return; | 771 | case CS_CONNECTED: |
772 | call_state = CS_SUSPENDED; | ||
773 | GNUNET_CONVERSATION_call_suspend(call); | ||
774 | return; | ||
775 | } | ||
760 | } | 776 | } |
761 | } | ||
762 | switch (phone_state) | 777 | switch (phone_state) |
763 | { | 778 | { |
764 | case PS_LOOKUP_EGO: | 779 | case PS_LOOKUP_EGO: |
765 | case PS_LISTEN: | 780 | case PS_LISTEN: |
766 | case PS_ERROR: | 781 | case PS_ERROR: |
767 | fprintf (stderr, | 782 | fprintf(stderr, |
768 | "%s", | 783 | "%s", |
769 | _ ("There is no call that could be suspended right now.\n")); | 784 | _("There is no call that could be suspended right now.\n")); |
770 | return; | 785 | return; |
771 | case PS_ACCEPTED: | 786 | |
772 | /* expected state, do rejection logic */ | 787 | case PS_ACCEPTED: |
773 | break; | 788 | /* expected state, do rejection logic */ |
774 | } | 789 | break; |
775 | GNUNET_assert (NULL != cl_active); | 790 | } |
776 | GNUNET_CONVERSATION_caller_suspend (cl_active->caller); | 791 | GNUNET_assert(NULL != cl_active); |
792 | GNUNET_CONVERSATION_caller_suspend(cl_active->caller); | ||
777 | cl_active = NULL; | 793 | cl_active = NULL; |
778 | phone_state = PS_LISTEN; | 794 | phone_state = PS_LISTEN; |
779 | } | 795 | } |
@@ -785,70 +801,73 @@ do_suspend (const char *args) | |||
785 | * @param args arguments given to the command | 801 | * @param args arguments given to the command |
786 | */ | 802 | */ |
787 | static void | 803 | static void |
788 | do_resume (const char *args) | 804 | do_resume(const char *args) |
789 | { | 805 | { |
790 | struct CallList *cl; | 806 | struct CallList *cl; |
791 | char buf[32]; | 807 | char buf[32]; |
792 | 808 | ||
793 | if (NULL != call) | 809 | if (NULL != call) |
794 | { | ||
795 | switch (call_state) | ||
796 | { | 810 | { |
797 | case CS_RESOLVING: | 811 | switch (call_state) |
798 | case CS_RINGING: | 812 | { |
799 | case CS_CONNECTED: | 813 | case CS_RESOLVING: |
800 | fprintf (stderr, | 814 | case CS_RINGING: |
801 | "%s", | 815 | case CS_CONNECTED: |
802 | _ ("There is no call that could be resumed right now.\n")); | 816 | fprintf(stderr, |
817 | "%s", | ||
818 | _("There is no call that could be resumed right now.\n")); | ||
819 | return; | ||
820 | |||
821 | case CS_SUSPENDED: | ||
822 | call_state = CS_CONNECTED; | ||
823 | GNUNET_CONVERSATION_call_resume(call, speaker, mic); | ||
824 | return; | ||
825 | } | ||
826 | } | ||
827 | switch (phone_state) | ||
828 | { | ||
829 | case PS_LOOKUP_EGO: | ||
830 | case PS_ERROR: | ||
831 | fprintf(stderr, | ||
832 | "%s", | ||
833 | _("There is no call that could be resumed right now.\n")); | ||
803 | return; | 834 | return; |
804 | case CS_SUSPENDED: | 835 | |
805 | call_state = CS_CONNECTED; | 836 | case PS_LISTEN: |
806 | GNUNET_CONVERSATION_call_resume (call, speaker, mic); | 837 | /* expected state, do resume logic */ |
838 | break; | ||
839 | |||
840 | case PS_ACCEPTED: | ||
841 | fprintf(stderr, | ||
842 | _("Already talking with `%s', cannot resume a call right now.\n"), | ||
843 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | ||
807 | return; | 844 | return; |
808 | } | 845 | } |
809 | } | 846 | GNUNET_assert(NULL == cl_active); |
810 | switch (phone_state) | ||
811 | { | ||
812 | case PS_LOOKUP_EGO: | ||
813 | case PS_ERROR: | ||
814 | fprintf (stderr, | ||
815 | "%s", | ||
816 | _ ("There is no call that could be resumed right now.\n")); | ||
817 | return; | ||
818 | case PS_LISTEN: | ||
819 | /* expected state, do resume logic */ | ||
820 | break; | ||
821 | case PS_ACCEPTED: | ||
822 | fprintf (stderr, | ||
823 | _ ("Already talking with `%s', cannot resume a call right now.\n"), | ||
824 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | ||
825 | return; | ||
826 | } | ||
827 | GNUNET_assert (NULL == cl_active); | ||
828 | cl = cl_head; | 847 | cl = cl_head; |
829 | if (NULL == cl) | 848 | if (NULL == cl) |
830 | { | 849 | { |
831 | fprintf (stderr, _ ("There is no incoming call to resume here!\n")); | 850 | fprintf(stderr, _("There is no incoming call to resume here!\n")); |
832 | return; | 851 | return; |
833 | } | 852 | } |
834 | if ((NULL != cl->next) || (NULL != args)) | 853 | if ((NULL != cl->next) || (NULL != args)) |
835 | { | ||
836 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
837 | { | 854 | { |
838 | GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num); | 855 | for (cl = cl_head; NULL != cl; cl = cl->next) |
839 | if (0 == strcmp (buf, args)) | 856 | { |
840 | break; | 857 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); |
858 | if (0 == strcmp(buf, args)) | ||
859 | break; | ||
860 | } | ||
841 | } | 861 | } |
842 | } | ||
843 | if (NULL == cl) | 862 | if (NULL == cl) |
844 | { | 863 | { |
845 | fprintf (stderr, | 864 | fprintf(stderr, |
846 | _ ("There is no incoming call `%s' to resume right now!\n"), | 865 | _("There is no incoming call `%s' to resume right now!\n"), |
847 | args); | 866 | args); |
848 | return; | 867 | return; |
849 | } | 868 | } |
850 | cl_active = cl; | 869 | cl_active = cl; |
851 | GNUNET_CONVERSATION_caller_resume (cl_active->caller, speaker, mic); | 870 | GNUNET_CONVERSATION_caller_resume(cl_active->caller, speaker, mic); |
852 | phone_state = PS_ACCEPTED; | 871 | phone_state = PS_ACCEPTED; |
853 | } | 872 | } |
854 | 873 | ||
@@ -859,61 +878,63 @@ do_resume (const char *args) | |||
859 | * @param args arguments given to the command | 878 | * @param args arguments given to the command |
860 | */ | 879 | */ |
861 | static void | 880 | static void |
862 | do_reject (const char *args) | 881 | do_reject(const char *args) |
863 | { | 882 | { |
864 | struct CallList *cl; | 883 | struct CallList *cl; |
865 | char buf[32]; | 884 | char buf[32]; |
866 | 885 | ||
867 | if (NULL != call) | 886 | if (NULL != call) |
868 | { | ||
869 | GNUNET_CONVERSATION_call_stop (call); | ||
870 | call = NULL; | ||
871 | return; | ||
872 | } | ||
873 | switch (phone_state) | ||
874 | { | ||
875 | case PS_LOOKUP_EGO: | ||
876 | case PS_ERROR: | ||
877 | fprintf (stderr, | ||
878 | "%s", | ||
879 | _ ("There is no call that could be cancelled right now.\n")); | ||
880 | return; | ||
881 | case PS_LISTEN: | ||
882 | /* look for active incoming calls to refuse */ | ||
883 | cl = cl_head; | ||
884 | if (NULL == cl) | ||
885 | { | 887 | { |
886 | fprintf (stderr, _ ("There is no incoming call to refuse here!\n")); | 888 | GNUNET_CONVERSATION_call_stop(call); |
889 | call = NULL; | ||
887 | return; | 890 | return; |
888 | } | 891 | } |
889 | if ((NULL != cl->next) || (NULL != args)) | 892 | switch (phone_state) |
890 | { | ||
891 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
892 | { | ||
893 | GNUNET_snprintf (buf, sizeof (buf), "%u", cl->caller_num); | ||
894 | if (0 == strcmp (buf, args)) | ||
895 | break; | ||
896 | } | ||
897 | } | ||
898 | if (NULL == cl) | ||
899 | { | 893 | { |
900 | fprintf (stderr, | 894 | case PS_LOOKUP_EGO: |
901 | _ ("There is no incoming call `%s' to refuse right now!\n"), | 895 | case PS_ERROR: |
902 | args); | 896 | fprintf(stderr, |
897 | "%s", | ||
898 | _("There is no call that could be cancelled right now.\n")); | ||
903 | return; | 899 | return; |
900 | |||
901 | case PS_LISTEN: | ||
902 | /* look for active incoming calls to refuse */ | ||
903 | cl = cl_head; | ||
904 | if (NULL == cl) | ||
905 | { | ||
906 | fprintf(stderr, _("There is no incoming call to refuse here!\n")); | ||
907 | return; | ||
908 | } | ||
909 | if ((NULL != cl->next) || (NULL != args)) | ||
910 | { | ||
911 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
912 | { | ||
913 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); | ||
914 | if (0 == strcmp(buf, args)) | ||
915 | break; | ||
916 | } | ||
917 | } | ||
918 | if (NULL == cl) | ||
919 | { | ||
920 | fprintf(stderr, | ||
921 | _("There is no incoming call `%s' to refuse right now!\n"), | ||
922 | args); | ||
923 | return; | ||
924 | } | ||
925 | GNUNET_CONVERSATION_caller_hang_up(cl->caller); | ||
926 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); | ||
927 | GNUNET_free(cl); | ||
928 | break; | ||
929 | |||
930 | case PS_ACCEPTED: | ||
931 | /* expected state, do rejection logic */ | ||
932 | GNUNET_assert(NULL != cl_active); | ||
933 | GNUNET_CONVERSATION_caller_hang_up(cl_active->caller); | ||
934 | cl_active = NULL; | ||
935 | phone_state = PS_LISTEN; | ||
936 | break; | ||
904 | } | 937 | } |
905 | GNUNET_CONVERSATION_caller_hang_up (cl->caller); | ||
906 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); | ||
907 | GNUNET_free (cl); | ||
908 | break; | ||
909 | case PS_ACCEPTED: | ||
910 | /* expected state, do rejection logic */ | ||
911 | GNUNET_assert (NULL != cl_active); | ||
912 | GNUNET_CONVERSATION_caller_hang_up (cl_active->caller); | ||
913 | cl_active = NULL; | ||
914 | phone_state = PS_LISTEN; | ||
915 | break; | ||
916 | } | ||
917 | } | 938 | } |
918 | 939 | ||
919 | 940 | ||
@@ -921,35 +942,35 @@ do_reject (const char *args) | |||
921 | * List of supported commands. | 942 | * List of supported commands. |
922 | */ | 943 | */ |
923 | static struct VoipCommand commands[] = { | 944 | static struct VoipCommand commands[] = { |
924 | {"/address", | 945 | { "/address", |
925 | &do_address, | 946 | &do_address, |
926 | gettext_noop ( | 947 | gettext_noop( |
927 | "Use `/address' to find out which address this phone should have in GNS")}, | 948 | "Use `/address' to find out which address this phone should have in GNS") }, |
928 | {"/call", &do_call, gettext_noop ("Use `/call USER.gnu' to call USER")}, | 949 | { "/call", &do_call, gettext_noop("Use `/call USER.gnu' to call USER") }, |
929 | {"/accept", | 950 | { "/accept", |
930 | &do_accept, | 951 | &do_accept, |
931 | gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM")}, | 952 | gettext_noop("Use `/accept #NUM' to accept incoming call #NUM") }, |
932 | {"/suspend", | 953 | { "/suspend", |
933 | &do_suspend, | 954 | &do_suspend, |
934 | gettext_noop ("Use `/suspend' to suspend the active call")}, | 955 | gettext_noop("Use `/suspend' to suspend the active call") }, |
935 | {"/resume", | 956 | { "/resume", |
936 | &do_resume, | 957 | &do_resume, |
937 | gettext_noop ( | 958 | gettext_noop( |
938 | "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.")}, | 959 | "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.") }, |
939 | {"/cancel", | 960 | { "/cancel", |
940 | &do_reject, | 961 | &do_reject, |
941 | gettext_noop ("Use `/cancel' to reject or terminate a call")}, | 962 | gettext_noop("Use `/cancel' to reject or terminate a call") }, |
942 | {"/status", | 963 | { "/status", |
943 | &do_status, | 964 | &do_status, |
944 | gettext_noop ("Use `/status' to print status information")}, | 965 | gettext_noop("Use `/status' to print status information") }, |
945 | {"/quit", | 966 | { "/quit", |
946 | &do_quit, | 967 | &do_quit, |
947 | gettext_noop ("Use `/quit' to terminate gnunet-conversation")}, | 968 | gettext_noop("Use `/quit' to terminate gnunet-conversation") }, |
948 | {"/help", | 969 | { "/help", |
949 | &do_help, | 970 | &do_help, |
950 | gettext_noop ("Use `/help command' to get help for a specific command")}, | 971 | gettext_noop("Use `/help command' to get help for a specific command") }, |
951 | {"", &do_unknown, NULL}, | 972 | { "", &do_unknown, NULL }, |
952 | {NULL, NULL, NULL}, | 973 | { NULL, NULL, NULL }, |
953 | }; | 974 | }; |
954 | 975 | ||
955 | 976 | ||
@@ -959,30 +980,30 @@ static struct VoipCommand commands[] = { | |||
959 | * @param args arguments given to the command | 980 | * @param args arguments given to the command |
960 | */ | 981 | */ |
961 | static void | 982 | static void |
962 | do_help (const char *args) | 983 | do_help(const char *args) |
963 | { | 984 | { |
964 | unsigned int i; | 985 | unsigned int i; |
965 | 986 | ||
966 | i = 0; | 987 | i = 0; |
967 | while ((NULL != args) && (0 != strlen (args)) && | 988 | while ((NULL != args) && (0 != strlen(args)) && |
968 | (commands[i].Action != &do_help)) | 989 | (commands[i].Action != &do_help)) |
969 | { | ||
970 | if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) | ||
971 | { | 990 | { |
972 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); | 991 | if (0 == strncasecmp(&args[1], &commands[i].command[1], strlen(args) - 1)) |
973 | return; | 992 | { |
993 | fprintf(stdout, "%s\n", gettext(commands[i].helptext)); | ||
994 | return; | ||
995 | } | ||
996 | i++; | ||
974 | } | 997 | } |
975 | i++; | ||
976 | } | ||
977 | i = 0; | 998 | i = 0; |
978 | fprintf (stdout, "%s", "Available commands:\n"); | 999 | fprintf(stdout, "%s", "Available commands:\n"); |
979 | while (commands[i].Action != &do_help) | 1000 | while (commands[i].Action != &do_help) |
980 | { | 1001 | { |
981 | fprintf (stdout, "%s\n", gettext (commands[i].command)); | 1002 | fprintf(stdout, "%s\n", gettext(commands[i].command)); |
982 | i++; | 1003 | i++; |
983 | } | 1004 | } |
984 | fprintf (stdout, "%s", "\n"); | 1005 | fprintf(stdout, "%s", "\n"); |
985 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); | 1006 | fprintf(stdout, "%s\n", gettext(commands[i].helptext)); |
986 | } | 1007 | } |
987 | 1008 | ||
988 | 1009 | ||
@@ -992,43 +1013,43 @@ do_help (const char *args) | |||
992 | * @param cls NULL | 1013 | * @param cls NULL |
993 | */ | 1014 | */ |
994 | static void | 1015 | static void |
995 | do_stop_task (void *cls) | 1016 | do_stop_task(void *cls) |
996 | { | 1017 | { |
997 | (void) cls; | 1018 | (void)cls; |
998 | #ifdef WINDOWS | 1019 | #ifdef WINDOWS |
999 | if (NULL != stdin_hlp) | 1020 | if (NULL != stdin_hlp) |
1000 | { | 1021 | { |
1001 | GNUNET_HELPER_stop (stdin_hlp, GNUNET_NO); | 1022 | GNUNET_HELPER_stop(stdin_hlp, GNUNET_NO); |
1002 | stdin_hlp = NULL; | 1023 | stdin_hlp = NULL; |
1003 | } | 1024 | } |
1004 | #endif | 1025 | #endif |
1005 | if (NULL != call) | 1026 | if (NULL != call) |
1006 | { | 1027 | { |
1007 | GNUNET_CONVERSATION_call_stop (call); | 1028 | GNUNET_CONVERSATION_call_stop(call); |
1008 | call = NULL; | 1029 | call = NULL; |
1009 | } | 1030 | } |
1010 | if (NULL != phone) | 1031 | if (NULL != phone) |
1011 | { | 1032 | { |
1012 | GNUNET_CONVERSATION_phone_destroy (phone); | 1033 | GNUNET_CONVERSATION_phone_destroy(phone); |
1013 | phone = NULL; | 1034 | phone = NULL; |
1014 | } | 1035 | } |
1015 | if (NULL != handle_cmd_task) | 1036 | if (NULL != handle_cmd_task) |
1016 | { | 1037 | { |
1017 | GNUNET_SCHEDULER_cancel (handle_cmd_task); | 1038 | GNUNET_SCHEDULER_cancel(handle_cmd_task); |
1018 | handle_cmd_task = NULL; | 1039 | handle_cmd_task = NULL; |
1019 | } | 1040 | } |
1020 | if (NULL != id) | 1041 | if (NULL != id) |
1021 | { | 1042 | { |
1022 | GNUNET_IDENTITY_disconnect (id); | 1043 | GNUNET_IDENTITY_disconnect(id); |
1023 | id = NULL; | 1044 | id = NULL; |
1024 | } | 1045 | } |
1025 | GNUNET_SPEAKER_destroy (speaker); | 1046 | GNUNET_SPEAKER_destroy(speaker); |
1026 | speaker = NULL; | 1047 | speaker = NULL; |
1027 | GNUNET_MICROPHONE_destroy (mic); | 1048 | GNUNET_MICROPHONE_destroy(mic); |
1028 | mic = NULL; | 1049 | mic = NULL; |
1029 | GNUNET_free (ego_name); | 1050 | GNUNET_free(ego_name); |
1030 | ego_name = NULL; | 1051 | ego_name = NULL; |
1031 | GNUNET_free_non_null (peer_name); | 1052 | GNUNET_free_non_null(peer_name); |
1032 | peer_name = NULL; | 1053 | peer_name = NULL; |
1033 | phone_state = PS_ERROR; | 1054 | phone_state = PS_ERROR; |
1034 | } | 1055 | } |
@@ -1041,7 +1062,7 @@ do_stop_task (void *cls) | |||
1041 | * @param str_len number of bytes to process in @a message | 1062 | * @param str_len number of bytes to process in @a message |
1042 | */ | 1063 | */ |
1043 | static void | 1064 | static void |
1044 | handle_command_string (char *message, size_t str_len) | 1065 | handle_command_string(char *message, size_t str_len) |
1045 | { | 1066 | { |
1046 | size_t i; | 1067 | size_t i; |
1047 | const char *ptr; | 1068 | const char *ptr; |
@@ -1052,49 +1073,50 @@ handle_command_string (char *message, size_t str_len) | |||
1052 | message[str_len - 1] = '\0'; | 1073 | message[str_len - 1] = '\0'; |
1053 | if (message[str_len - 2] == '\r') | 1074 | if (message[str_len - 2] == '\r') |
1054 | message[str_len - 2] = '\0'; | 1075 | message[str_len - 2] = '\0'; |
1055 | if (0 == strlen (message)) | 1076 | if (0 == strlen(message)) |
1056 | return; | 1077 | return; |
1057 | i = 0; | 1078 | i = 0; |
1058 | while ( | 1079 | while ( |
1059 | (NULL != commands[i].command) && | 1080 | (NULL != commands[i].command) && |
1060 | (0 != | 1081 | (0 != |
1061 | strncasecmp (commands[i].command, message, strlen (commands[i].command)))) | 1082 | strncasecmp(commands[i].command, message, strlen(commands[i].command)))) |
1062 | i++; | 1083 | i++; |
1063 | ptr = &message[strlen (commands[i].command)]; | 1084 | ptr = &message[strlen(commands[i].command)]; |
1064 | while (isspace ((unsigned char) *ptr)) | 1085 | while (isspace((unsigned char)*ptr)) |
1065 | ptr++; | 1086 | ptr++; |
1066 | if ('\0' == *ptr) | 1087 | if ('\0' == *ptr) |
1067 | ptr = NULL; | 1088 | ptr = NULL; |
1068 | commands[i].Action (ptr); | 1089 | commands[i].Action(ptr); |
1069 | } | 1090 | } |
1070 | 1091 | ||
1071 | 1092 | ||
1072 | #ifdef WINDOWS | 1093 | #ifdef WINDOWS |
1073 | static int | 1094 | static int |
1074 | console_reader_chars (void *cls, | 1095 | console_reader_chars(void *cls, |
1075 | void *client, | 1096 | void *client, |
1076 | const struct GNUNET_MessageHeader *message) | 1097 | const struct GNUNET_MessageHeader *message) |
1077 | { | 1098 | { |
1078 | char *chars; | 1099 | char *chars; |
1079 | size_t str_size; | 1100 | size_t str_size; |
1080 | 1101 | ||
1081 | (void) cls; | 1102 | (void)cls; |
1082 | switch (ntohs (message->type)) | 1103 | switch (ntohs(message->type)) |
1083 | { | 1104 | { |
1084 | case GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS: | 1105 | case GNUNET_MESSAGE_TYPE_W32_CONSOLE_HELPER_CHARS: |
1085 | chars = (char *) &message[1]; | 1106 | chars = (char *)&message[1]; |
1086 | str_size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader); | 1107 | str_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); |
1087 | if (chars[str_size - 1] != '\0') | 1108 | if (chars[str_size - 1] != '\0') |
1088 | return GNUNET_SYSERR; | 1109 | return GNUNET_SYSERR; |
1089 | /* FIXME: is it ok that we pass part of a const struct to | 1110 | /* FIXME: is it ok that we pass part of a const struct to |
1090 | * this function that may mangle the contents? | 1111 | * this function that may mangle the contents? |
1091 | */ | 1112 | */ |
1092 | handle_command_string (chars, str_size - 1); | 1113 | handle_command_string(chars, str_size - 1); |
1093 | break; | 1114 | break; |
1094 | default: | 1115 | |
1095 | GNUNET_break (0); | 1116 | default: |
1096 | break; | 1117 | GNUNET_break(0); |
1097 | } | 1118 | break; |
1119 | } | ||
1098 | return GNUNET_OK; | 1120 | return GNUNET_OK; |
1099 | } | 1121 | } |
1100 | #endif | 1122 | #endif |
@@ -1106,21 +1128,21 @@ console_reader_chars (void *cls, | |||
1106 | * @param cls NULL | 1128 | * @param cls NULL |
1107 | */ | 1129 | */ |
1108 | static void | 1130 | static void |
1109 | handle_command (void *cls) | 1131 | handle_command(void *cls) |
1110 | { | 1132 | { |
1111 | char message[MAX_MESSAGE_LENGTH + 1]; | 1133 | char message[MAX_MESSAGE_LENGTH + 1]; |
1112 | 1134 | ||
1113 | (void) cls; | 1135 | (void)cls; |
1114 | handle_cmd_task = | 1136 | handle_cmd_task = |
1115 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 1137 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
1116 | stdin_fh, | 1138 | stdin_fh, |
1117 | &handle_command, | 1139 | &handle_command, |
1118 | NULL); | 1140 | NULL); |
1119 | /* read message from command line and handle it */ | 1141 | /* read message from command line and handle it */ |
1120 | memset (message, 0, MAX_MESSAGE_LENGTH + 1); | 1142 | memset(message, 0, MAX_MESSAGE_LENGTH + 1); |
1121 | if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin)) | 1143 | if (NULL == fgets(message, MAX_MESSAGE_LENGTH, stdin)) |
1122 | return; | 1144 | return; |
1123 | handle_command_string (message, strlen (message)); | 1145 | handle_command_string(message, strlen(message)); |
1124 | } | 1146 | } |
1125 | 1147 | ||
1126 | 1148 | ||
@@ -1133,35 +1155,35 @@ handle_command (void *cls) | |||
1133 | * @param name name of the ego | 1155 | * @param name name of the ego |
1134 | */ | 1156 | */ |
1135 | static void | 1157 | static void |
1136 | identity_cb (void *cls, | 1158 | identity_cb(void *cls, |
1137 | struct GNUNET_IDENTITY_Ego *ego, | 1159 | struct GNUNET_IDENTITY_Ego *ego, |
1138 | void **ctx, | 1160 | void **ctx, |
1139 | const char *name) | 1161 | const char *name) |
1140 | { | 1162 | { |
1141 | (void) cls; | 1163 | (void)cls; |
1142 | (void) ctx; | 1164 | (void)ctx; |
1143 | if (NULL == name) | 1165 | if (NULL == name) |
1144 | return; | 1166 | return; |
1145 | if (ego == my_caller_id) | 1167 | if (ego == my_caller_id) |
1146 | { | 1168 | { |
1147 | if (verbose) | 1169 | if (verbose) |
1148 | fprintf (stdout, _ ("Name of our ego changed to `%s'\n"), name); | 1170 | fprintf(stdout, _("Name of our ego changed to `%s'\n"), name); |
1149 | GNUNET_free (ego_name); | 1171 | GNUNET_free(ego_name); |
1150 | ego_name = GNUNET_strdup (name); | 1172 | ego_name = GNUNET_strdup(name); |
1151 | return; | 1173 | return; |
1152 | } | 1174 | } |
1153 | if (0 != strcmp (name, ego_name)) | 1175 | if (0 != strcmp(name, ego_name)) |
1154 | return; | 1176 | return; |
1155 | if (NULL == ego) | 1177 | if (NULL == ego) |
1156 | { | 1178 | { |
1157 | if (verbose) | 1179 | if (verbose) |
1158 | fprintf (stdout, _ ("Our ego `%s' was deleted!\n"), ego_name); | 1180 | fprintf(stdout, _("Our ego `%s' was deleted!\n"), ego_name); |
1159 | my_caller_id = NULL; | 1181 | my_caller_id = NULL; |
1160 | return; | 1182 | return; |
1161 | } | 1183 | } |
1162 | my_caller_id = ego; | 1184 | my_caller_id = ego; |
1163 | GNUNET_CONFIGURATION_set_value_string (cfg, "CONVERSATION", "LINE", line); | 1185 | GNUNET_CONFIGURATION_set_value_string(cfg, "CONVERSATION", "LINE", line); |
1164 | start_phone (); | 1186 | start_phone(); |
1165 | } | 1187 | } |
1166 | 1188 | ||
1167 | 1189 | ||
@@ -1174,52 +1196,52 @@ identity_cb (void *cls, | |||
1174 | * @param c configuration | 1196 | * @param c configuration |
1175 | */ | 1197 | */ |
1176 | static void | 1198 | static void |
1177 | run (void *cls, | 1199 | run(void *cls, |
1178 | char *const *args, | 1200 | char *const *args, |
1179 | const char *cfgfile, | 1201 | const char *cfgfile, |
1180 | const struct GNUNET_CONFIGURATION_Handle *c) | 1202 | const struct GNUNET_CONFIGURATION_Handle *c) |
1181 | { | 1203 | { |
1182 | (void) cls; | 1204 | (void)cls; |
1183 | (void) args; | 1205 | (void)args; |
1184 | (void) cfgfile; | 1206 | (void)cfgfile; |
1185 | cfg = GNUNET_CONFIGURATION_dup (c); | 1207 | cfg = GNUNET_CONFIGURATION_dup(c); |
1186 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); | 1208 | speaker = GNUNET_SPEAKER_create_from_hardware(cfg); |
1187 | mic = GNUNET_MICROPHONE_create_from_hardware (cfg); | 1209 | mic = GNUNET_MICROPHONE_create_from_hardware(cfg); |
1188 | if (NULL == ego_name) | 1210 | if (NULL == ego_name) |
1189 | { | 1211 | { |
1190 | fprintf (stderr, "%s", _ ("You must specify the NAME of an ego to use\n")); | 1212 | fprintf(stderr, "%s", _("You must specify the NAME of an ego to use\n")); |
1191 | return; | 1213 | return; |
1192 | } | 1214 | } |
1193 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 1215 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); |
1194 | #ifdef WINDOWS | 1216 | #ifdef WINDOWS |
1195 | if (stdin_fh == NULL) | 1217 | if (stdin_fh == NULL) |
1196 | { | ||
1197 | static char cpid[64]; | ||
1198 | static char *args[] = {"gnunet-helper-w32-console.exe", | ||
1199 | "chars", | ||
1200 | XSTRINGIFY (MAX_MESSAGE_LENGTH), | ||
1201 | cpid, | ||
1202 | NULL}; | ||
1203 | snprintf (cpid, 64, "%d", GetCurrentProcessId ()); | ||
1204 | stdin_hlp = GNUNET_HELPER_start (GNUNET_NO, | ||
1205 | "gnunet-helper-w32-console", | ||
1206 | args, | ||
1207 | console_reader_chars, | ||
1208 | NULL, | ||
1209 | NULL); | ||
1210 | if (NULL == stdin_hlp) | ||
1211 | { | 1218 | { |
1212 | fprintf (stderr, "%s", _ ("Failed to start gnunet-helper-w32-console\n")); | 1219 | static char cpid[64]; |
1213 | return; | 1220 | static char *args[] = { "gnunet-helper-w32-console.exe", |
1221 | "chars", | ||
1222 | XSTRINGIFY(MAX_MESSAGE_LENGTH), | ||
1223 | cpid, | ||
1224 | NULL }; | ||
1225 | snprintf(cpid, 64, "%d", GetCurrentProcessId()); | ||
1226 | stdin_hlp = GNUNET_HELPER_start(GNUNET_NO, | ||
1227 | "gnunet-helper-w32-console", | ||
1228 | args, | ||
1229 | console_reader_chars, | ||
1230 | NULL, | ||
1231 | NULL); | ||
1232 | if (NULL == stdin_hlp) | ||
1233 | { | ||
1234 | fprintf(stderr, "%s", _("Failed to start gnunet-helper-w32-console\n")); | ||
1235 | return; | ||
1236 | } | ||
1214 | } | 1237 | } |
1215 | } | ||
1216 | else | 1238 | else |
1217 | #endif | 1239 | #endif |
1218 | handle_cmd_task = | 1240 | handle_cmd_task = |
1219 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, | 1241 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI, |
1220 | &handle_command, | 1242 | &handle_command, |
1221 | NULL); | 1243 | NULL); |
1222 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); | 1244 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); |
1223 | } | 1245 | } |
1224 | 1246 | ||
1225 | 1247 | ||
@@ -1231,56 +1253,57 @@ run (void *cls, | |||
1231 | * @return 0 ok, 1 on error | 1253 | * @return 0 ok, 1 on error |
1232 | */ | 1254 | */ |
1233 | int | 1255 | int |
1234 | main (int argc, char *const *argv) | 1256 | main(int argc, char *const *argv) |
1235 | { | 1257 | { |
1236 | struct GNUNET_GETOPT_CommandLineOption options[] = | 1258 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1237 | {GNUNET_GETOPT_option_string ( | 1259 | { GNUNET_GETOPT_option_string( |
1238 | 'e', | 1260 | 'e', |
1239 | "ego", | 1261 | "ego", |
1240 | "NAME", | 1262 | "NAME", |
1241 | gettext_noop ("sets the NAME of the ego to use for the caller ID"), | 1263 | gettext_noop("sets the NAME of the ego to use for the caller ID"), |
1242 | &ego_name), | 1264 | &ego_name), |
1243 | GNUNET_GETOPT_option_string ('p', | 1265 | GNUNET_GETOPT_option_string('p', |
1244 | "phone", | 1266 | "phone", |
1245 | "LINE", | 1267 | "LINE", |
1246 | gettext_noop ( | 1268 | gettext_noop( |
1247 | "sets the LINE to use for the phone"), | 1269 | "sets the LINE to use for the phone"), |
1248 | &line), | 1270 | &line), |
1249 | GNUNET_GETOPT_OPTION_END}; | 1271 | GNUNET_GETOPT_OPTION_END }; |
1250 | int ret; | 1272 | int ret; |
1273 | |||
1251 | #ifndef WINDOWS | 1274 | #ifndef WINDOWS |
1252 | int flags; | 1275 | int flags; |
1253 | flags = fcntl (0, F_GETFL, 0); | 1276 | flags = fcntl(0, F_GETFL, 0); |
1254 | flags |= O_NONBLOCK; | 1277 | flags |= O_NONBLOCK; |
1255 | if (0 != fcntl (0, F_SETFL, flags)) | 1278 | if (0 != fcntl(0, F_SETFL, flags)) |
1256 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 1279 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
1257 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); | 1280 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); |
1258 | #else | 1281 | #else |
1259 | if (FILE_TYPE_CHAR == GetFileType ((HANDLE) _get_osfhandle (0))) | 1282 | if (FILE_TYPE_CHAR == GetFileType((HANDLE)_get_osfhandle(0))) |
1260 | { | 1283 | { |
1261 | stdin_fh = NULL; | 1284 | stdin_fh = NULL; |
1262 | } | 1285 | } |
1263 | else | 1286 | else |
1264 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); | 1287 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); |
1265 | #endif | 1288 | #endif |
1266 | 1289 | ||
1267 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1290 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
1268 | return 2; | 1291 | return 2; |
1269 | ret = | 1292 | ret = |
1270 | GNUNET_PROGRAM_run (argc, | 1293 | GNUNET_PROGRAM_run(argc, |
1271 | argv, | 1294 | argv, |
1272 | "gnunet-conversation", | 1295 | "gnunet-conversation", |
1273 | gettext_noop ( | 1296 | gettext_noop( |
1274 | "Enables having a conversation with other GNUnet users."), | 1297 | "Enables having a conversation with other GNUnet users."), |
1275 | options, | 1298 | options, |
1276 | &run, | 1299 | &run, |
1277 | NULL); | 1300 | NULL); |
1278 | GNUNET_free ((void *) argv); | 1301 | GNUNET_free((void *)argv); |
1279 | if (NULL != cfg) | 1302 | if (NULL != cfg) |
1280 | { | 1303 | { |
1281 | GNUNET_CONFIGURATION_destroy (cfg); | 1304 | GNUNET_CONFIGURATION_destroy(cfg); |
1282 | cfg = NULL; | 1305 | cfg = NULL; |
1283 | } | 1306 | } |
1284 | return (GNUNET_OK == ret) ? 0 : 1; | 1307 | return (GNUNET_OK == ret) ? 0 : 1; |
1285 | } | 1308 | } |
1286 | 1309 | ||
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c index 51450af90..b268fa215 100644 --- a/src/conversation/gnunet-helper-audio-playback-gst.c +++ b/src/conversation/gnunet-helper-audio-playback-gst.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-helper-audio-playback-gst.c | 21 | * @file conversation/gnunet-helper-audio-playback-gst.c |
22 | * @brief program to playback audio data to the speaker (GStreamer version) | 22 | * @brief program to playback audio data to the speaker (GStreamer version) |
@@ -81,140 +81,144 @@ static int abort_read; | |||
81 | 81 | ||
82 | 82 | ||
83 | static void | 83 | static void |
84 | sink_child_added (GstChildProxy *child_proxy, | 84 | sink_child_added(GstChildProxy *child_proxy, |
85 | GObject *object, | 85 | GObject *object, |
86 | gchar *name, | 86 | gchar *name, |
87 | gpointer user_data) | 87 | gpointer user_data) |
88 | { | 88 | { |
89 | if (GST_IS_AUDIO_BASE_SRC (object)) | 89 | if (GST_IS_AUDIO_BASE_SRC(object)) |
90 | g_object_set (object, | 90 | g_object_set(object, |
91 | "buffer-time", (gint64) BUFFER_TIME, | 91 | "buffer-time", (gint64)BUFFER_TIME, |
92 | "latency-time", (gint64) LATENCY_TIME, | 92 | "latency-time", (gint64)LATENCY_TIME, |
93 | NULL); | 93 | NULL); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static void | 97 | static void |
98 | ogg_pad_added (GstElement *element, | 98 | ogg_pad_added(GstElement *element, |
99 | GstPad *pad, | 99 | GstPad *pad, |
100 | gpointer data) | 100 | gpointer data) |
101 | { | 101 | { |
102 | GstPad *sinkpad; | 102 | GstPad *sinkpad; |
103 | GstElement *decoder = (GstElement *) data; | 103 | GstElement *decoder = (GstElement *)data; |
104 | 104 | ||
105 | /* We can now link this pad with the opus-decoder sink pad */ | 105 | /* We can now link this pad with the opus-decoder sink pad */ |
106 | sinkpad = gst_element_get_static_pad (decoder, "sink"); | 106 | sinkpad = gst_element_get_static_pad(decoder, "sink"); |
107 | 107 | ||
108 | gst_pad_link (pad, sinkpad); | 108 | gst_pad_link(pad, sinkpad); |
109 | 109 | ||
110 | gst_element_link_many (decoder, conv, resampler, sink, NULL); | 110 | gst_element_link_many(decoder, conv, resampler, sink, NULL); |
111 | 111 | ||
112 | gst_object_unref (sinkpad); | 112 | gst_object_unref(sinkpad); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | static void | 116 | static void |
117 | quit () | 117 | quit() |
118 | { | 118 | { |
119 | if (NULL != source) | 119 | if (NULL != source) |
120 | gst_app_src_end_of_stream (GST_APP_SRC (source)); | 120 | gst_app_src_end_of_stream(GST_APP_SRC(source)); |
121 | if (NULL != pipeline) | 121 | if (NULL != pipeline) |
122 | gst_element_set_state (pipeline, GST_STATE_NULL); | 122 | gst_element_set_state(pipeline, GST_STATE_NULL); |
123 | abort_read = 1; | 123 | abort_read = 1; |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | static gboolean | 127 | static gboolean |
128 | bus_call (GstBus *bus, GstMessage *msg, gpointer data) | 128 | bus_call(GstBus *bus, GstMessage *msg, gpointer data) |
129 | { | 129 | { |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
131 | "Bus message\n"); | 131 | "Bus message\n"); |
132 | switch (GST_MESSAGE_TYPE (msg)) | 132 | switch (GST_MESSAGE_TYPE(msg)) |
133 | { | 133 | { |
134 | case GST_MESSAGE_EOS: | 134 | case GST_MESSAGE_EOS: |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 135 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
136 | "End of stream\n"); | 136 | "End of stream\n"); |
137 | quit (); | 137 | quit(); |
138 | break; | 138 | break; |
139 | 139 | ||
140 | case GST_MESSAGE_ERROR: | 140 | case GST_MESSAGE_ERROR: |
141 | { | 141 | { |
142 | gchar *debug; | 142 | gchar *debug; |
143 | GError *error; | 143 | GError *error; |
144 | 144 | ||
145 | gst_message_parse_error (msg, &error, &debug); | 145 | gst_message_parse_error(msg, &error, &debug); |
146 | g_free (debug); | 146 | g_free(debug); |
147 | 147 | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 148 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
149 | "Error: %s\n", | 149 | "Error: %s\n", |
150 | error->message); | 150 | error->message); |
151 | g_error_free (error); | 151 | g_error_free(error); |
152 | 152 | ||
153 | quit (); | 153 | quit(); |
154 | break; | ||
155 | } | ||
156 | |||
157 | default: | ||
154 | break; | 158 | break; |
155 | } | 159 | } |
156 | default: | ||
157 | break; | ||
158 | } | ||
159 | 160 | ||
160 | return TRUE; | 161 | return TRUE; |
161 | } | 162 | } |
162 | 163 | ||
163 | 164 | ||
164 | static void | 165 | static void |
165 | signalhandler (int s) | 166 | signalhandler(int s) |
166 | { | 167 | { |
167 | quit (); | 168 | quit(); |
168 | } | 169 | } |
169 | 170 | ||
170 | 171 | ||
171 | static int | 172 | static int |
172 | feed_buffer_to_gst (const char *audio, size_t b_len) | 173 | feed_buffer_to_gst(const char *audio, size_t b_len) |
173 | { | 174 | { |
174 | GstBuffer *b; | 175 | GstBuffer *b; |
175 | gchar *bufspace; | 176 | gchar *bufspace; |
176 | GstFlowReturn flow; | 177 | GstFlowReturn flow; |
177 | 178 | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
179 | "Feeding %u bytes to GStreamer\n", | 180 | "Feeding %u bytes to GStreamer\n", |
180 | (unsigned int) b_len); | 181 | (unsigned int)b_len); |
181 | 182 | ||
182 | bufspace = g_memdup (audio, b_len); | 183 | bufspace = g_memdup(audio, b_len); |
183 | b = gst_buffer_new_wrapped (bufspace, b_len); | 184 | b = gst_buffer_new_wrapped(bufspace, b_len); |
184 | if (NULL == b) | 185 | if (NULL == b) |
185 | { | 186 | { |
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
187 | "Failed to wrap a buffer\n"); | 188 | "Failed to wrap a buffer\n"); |
188 | g_free (bufspace); | 189 | g_free(bufspace); |
189 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
190 | } | 191 | } |
191 | flow = gst_app_src_push_buffer (GST_APP_SRC (source), b); | 192 | flow = gst_app_src_push_buffer(GST_APP_SRC(source), b); |
192 | /* They all return GNUNET_OK, because currently player stops when | 193 | /* They all return GNUNET_OK, because currently player stops when |
193 | * data stops coming. This might need to be changed for the player | 194 | * data stops coming. This might need to be changed for the player |
194 | * to also stop when pipeline breaks. | 195 | * to also stop when pipeline breaks. |
195 | */ | 196 | */ |
196 | switch (flow) | 197 | switch (flow) |
197 | { | 198 | { |
198 | case GST_FLOW_OK: | 199 | case GST_FLOW_OK: |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
200 | "Fed %u bytes to the pipeline\n", | 201 | "Fed %u bytes to the pipeline\n", |
201 | (unsigned int) b_len); | 202 | (unsigned int)b_len); |
202 | break; | 203 | break; |
203 | case GST_FLOW_FLUSHING: | 204 | |
204 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ | 205 | case GST_FLOW_FLUSHING: |
205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 206 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ |
206 | "Dropped a buffer\n"); | 207 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
207 | break; | 208 | "Dropped a buffer\n"); |
208 | case GST_FLOW_EOS: | 209 | break; |
209 | /* end of stream */ | 210 | |
210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 211 | case GST_FLOW_EOS: |
211 | "EOS\n"); | 212 | /* end of stream */ |
212 | break; | 213 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
213 | default: | 214 | "EOS\n"); |
214 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 215 | break; |
215 | "Unexpected push result\n"); | 216 | |
216 | break; | 217 | default: |
217 | } | 218 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
219 | "Unexpected push result\n"); | ||
220 | break; | ||
221 | } | ||
218 | return GNUNET_OK; | 222 | return GNUNET_OK; |
219 | } | 223 | } |
220 | 224 | ||
@@ -228,29 +232,30 @@ feed_buffer_to_gst (const char *audio, size_t b_len) | |||
228 | * #GNUNET_SYSERR to stop further processing due to error | 232 | * #GNUNET_SYSERR to stop further processing due to error |
229 | */ | 233 | */ |
230 | static int | 234 | static int |
231 | stdin_receiver (void *cls, | 235 | stdin_receiver(void *cls, |
232 | const struct GNUNET_MessageHeader *msg) | 236 | const struct GNUNET_MessageHeader *msg) |
233 | { | 237 | { |
234 | struct AudioMessage *audio; | 238 | struct AudioMessage *audio; |
235 | size_t b_len; | 239 | size_t b_len; |
236 | 240 | ||
237 | switch (ntohs (msg->type)) | 241 | switch (ntohs(msg->type)) |
238 | { | 242 | { |
239 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 243 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
240 | audio = (struct AudioMessage *) msg; | 244 | audio = (struct AudioMessage *)msg; |
241 | 245 | ||
242 | b_len = ntohs (audio->header.size) - sizeof (struct AudioMessage); | 246 | b_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); |
243 | feed_buffer_to_gst ((const char *) &audio[1], b_len); | 247 | feed_buffer_to_gst((const char *)&audio[1], b_len); |
244 | break; | 248 | break; |
245 | default: | 249 | |
246 | break; | 250 | default: |
247 | } | 251 | break; |
252 | } | ||
248 | return GNUNET_OK; | 253 | return GNUNET_OK; |
249 | } | 254 | } |
250 | 255 | ||
251 | 256 | ||
252 | int | 257 | int |
253 | main (int argc, char **argv) | 258 | main(int argc, char **argv) |
254 | { | 259 | { |
255 | GstBus *bus; | 260 | GstBus *bus; |
256 | guint bus_watch_id; | 261 | guint bus_watch_id; |
@@ -260,144 +265,144 @@ main (int argc, char **argv) | |||
260 | 265 | ||
261 | SignalHandlerPointer inthandler, termhandler; | 266 | SignalHandlerPointer inthandler, termhandler; |
262 | #ifdef DEBUG_READ_PURE_OGG | 267 | #ifdef DEBUG_READ_PURE_OGG |
263 | int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0; | 268 | int read_pure_ogg = getenv("GNUNET_READ_PURE_OGG") ? 1 : 0; |
264 | #endif | 269 | #endif |
265 | 270 | ||
266 | inthandler = signal (SIGINT, | 271 | inthandler = signal(SIGINT, |
267 | &signalhandler); | 272 | &signalhandler); |
268 | termhandler = signal (SIGTERM, | 273 | termhandler = signal(SIGTERM, |
269 | &signalhandler); | 274 | &signalhandler); |
270 | 275 | ||
271 | #ifdef WINDOWS | 276 | #ifdef WINDOWS |
272 | setmode (0, _O_BINARY); | 277 | setmode(0, _O_BINARY); |
273 | #endif | 278 | #endif |
274 | 279 | ||
275 | /* Initialisation */ | 280 | /* Initialisation */ |
276 | gst_init (&argc, &argv); | 281 | gst_init(&argc, &argv); |
277 | 282 | ||
278 | GNUNET_assert (GNUNET_OK == | 283 | GNUNET_assert(GNUNET_OK == |
279 | GNUNET_log_setup ("gnunet-helper-audio-playback-gst", | 284 | GNUNET_log_setup("gnunet-helper-audio-playback-gst", |
280 | "WARNING", | 285 | "WARNING", |
281 | NULL)); | 286 | NULL)); |
282 | 287 | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
284 | "Audio sink starts\n"); | 289 | "Audio sink starts\n"); |
285 | 290 | ||
286 | stdin_mst = GNUNET_MST_create (&stdin_receiver, | 291 | stdin_mst = GNUNET_MST_create(&stdin_receiver, |
287 | NULL); | 292 | NULL); |
288 | 293 | ||
289 | /* Create gstreamer elements */ | 294 | /* Create gstreamer elements */ |
290 | pipeline = gst_pipeline_new ("audio-player"); | 295 | pipeline = gst_pipeline_new("audio-player"); |
291 | source = gst_element_factory_make ("appsrc", "audio-input"); | 296 | source = gst_element_factory_make("appsrc", "audio-input"); |
292 | demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); | 297 | demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer"); |
293 | decoder = gst_element_factory_make ("opusdec", "opus-decoder"); | 298 | decoder = gst_element_factory_make("opusdec", "opus-decoder"); |
294 | conv = gst_element_factory_make ("audioconvert", "converter"); | 299 | conv = gst_element_factory_make("audioconvert", "converter"); |
295 | resampler= gst_element_factory_make ("audioresample", "resampler"); | 300 | resampler = gst_element_factory_make("audioresample", "resampler"); |
296 | sink = gst_element_factory_make ("autoaudiosink", "audiosink"); | 301 | sink = gst_element_factory_make("autoaudiosink", "audiosink"); |
297 | 302 | ||
298 | if (!pipeline || !source || !conv || !resampler || !decoder || !demuxer || !sink) | 303 | if (!pipeline || !source || !conv || !resampler || !decoder || !demuxer || !sink) |
299 | { | 304 | { |
300 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 305 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
301 | "One element could not be created. Exiting.\n"); | 306 | "One element could not be created. Exiting.\n"); |
302 | return -1; | 307 | return -1; |
303 | } | 308 | } |
304 | 309 | ||
305 | g_signal_connect (sink, | 310 | g_signal_connect(sink, |
306 | "child-added", | 311 | "child-added", |
307 | G_CALLBACK (sink_child_added), | 312 | G_CALLBACK(sink_child_added), |
308 | NULL); | 313 | NULL); |
309 | g_signal_connect (demuxer, | 314 | g_signal_connect(demuxer, |
310 | "pad-added", | 315 | "pad-added", |
311 | G_CALLBACK (ogg_pad_added), | 316 | G_CALLBACK(ogg_pad_added), |
312 | decoder); | 317 | decoder); |
313 | 318 | ||
314 | /* Keep a reference to it, we operate on it */ | 319 | /* Keep a reference to it, we operate on it */ |
315 | gst_object_ref (GST_OBJECT (source)); | 320 | gst_object_ref(GST_OBJECT(source)); |
316 | 321 | ||
317 | /* Set up the pipeline */ | 322 | /* Set up the pipeline */ |
318 | 323 | ||
319 | /* we feed appsrc as fast as possible, it just blocks when it's full */ | 324 | /* we feed appsrc as fast as possible, it just blocks when it's full */ |
320 | g_object_set (G_OBJECT (source), | 325 | g_object_set(G_OBJECT(source), |
321 | /* "format", GST_FORMAT_TIME,*/ | 326 | /* "format", GST_FORMAT_TIME,*/ |
322 | "block", TRUE, | 327 | "block", TRUE, |
323 | "is-live", TRUE, | 328 | "is-live", TRUE, |
324 | NULL); | 329 | NULL); |
325 | 330 | ||
326 | g_object_set (G_OBJECT (decoder), | 331 | g_object_set(G_OBJECT(decoder), |
327 | /* "plc", FALSE,*/ | 332 | /* "plc", FALSE,*/ |
328 | /* "apply-gain", TRUE,*/ | 333 | /* "apply-gain", TRUE,*/ |
329 | "use-inband-fec", TRUE, | 334 | "use-inband-fec", TRUE, |
330 | NULL); | 335 | NULL); |
331 | 336 | ||
332 | /* we add a message handler */ | 337 | /* we add a message handler */ |
333 | bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); | 338 | bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); |
334 | bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); | 339 | bus_watch_id = gst_bus_add_watch(bus, bus_call, pipeline); |
335 | gst_object_unref (bus); | 340 | gst_object_unref(bus); |
336 | 341 | ||
337 | /* we add all elements into the pipeline */ | 342 | /* we add all elements into the pipeline */ |
338 | /* audio-input | ogg-demuxer | opus-decoder | converter | resampler | audiosink */ | 343 | /* audio-input | ogg-demuxer | opus-decoder | converter | resampler | audiosink */ |
339 | gst_bin_add_many (GST_BIN (pipeline), source, demuxer, decoder, conv, | 344 | gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, |
340 | resampler, sink, NULL); | 345 | resampler, sink, NULL); |
341 | 346 | ||
342 | /* we link the elements together */ | 347 | /* we link the elements together */ |
343 | gst_element_link_many (source, demuxer, NULL); | 348 | gst_element_link_many(source, demuxer, NULL); |
344 | 349 | ||
345 | /* Set the pipeline to "playing" state*/ | 350 | /* Set the pipeline to "playing" state*/ |
346 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); | 351 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Now playing\n"); |
347 | gst_element_set_state (pipeline, GST_STATE_PLAYING); | 352 | gst_element_set_state(pipeline, GST_STATE_PLAYING); |
348 | 353 | ||
349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); | 354 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running...\n"); |
350 | /* Iterate */ | 355 | /* Iterate */ |
351 | toff = 0; | 356 | toff = 0; |
352 | while (!abort_read) | 357 | while (!abort_read) |
353 | { | ||
354 | char readbuf[MAXLINE]; | ||
355 | int ret; | ||
356 | |||
357 | ret = read (0, readbuf, sizeof (readbuf)); | ||
358 | if (0 > ret) | ||
359 | { | 358 | { |
360 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 359 | char readbuf[MAXLINE]; |
361 | _("Read error from STDIN: %d %s\n"), | 360 | int ret; |
362 | ret, strerror (errno)); | 361 | |
363 | break; | 362 | ret = read(0, readbuf, sizeof(readbuf)); |
364 | } | 363 | if (0 > ret) |
365 | toff += ret; | 364 | { |
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 365 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
367 | "Received %d bytes of audio data (total: %llu)\n", | 366 | _("Read error from STDIN: %d %s\n"), |
368 | (int) ret, | 367 | ret, strerror(errno)); |
369 | (unsigned long long) toff); | 368 | break; |
370 | if (0 == ret) | 369 | } |
371 | break; | 370 | toff += ret; |
371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
372 | "Received %d bytes of audio data (total: %llu)\n", | ||
373 | (int)ret, | ||
374 | (unsigned long long)toff); | ||
375 | if (0 == ret) | ||
376 | break; | ||
372 | #ifdef DEBUG_READ_PURE_OGG | 377 | #ifdef DEBUG_READ_PURE_OGG |
373 | if (read_pure_ogg) | 378 | if (read_pure_ogg) |
374 | { | 379 | { |
375 | feed_buffer_to_gst (readbuf, ret); | 380 | feed_buffer_to_gst(readbuf, ret); |
376 | } | 381 | } |
377 | else | 382 | else |
378 | #endif | 383 | #endif |
379 | GNUNET_MST_from_buffer (stdin_mst, | 384 | GNUNET_MST_from_buffer(stdin_mst, |
380 | readbuf, | 385 | readbuf, |
381 | ret, | 386 | ret, |
382 | GNUNET_NO, | 387 | GNUNET_NO, |
383 | GNUNET_NO); | 388 | GNUNET_NO); |
384 | } | 389 | } |
385 | GNUNET_MST_destroy (stdin_mst); | 390 | GNUNET_MST_destroy(stdin_mst); |
386 | 391 | ||
387 | signal (SIGINT, inthandler); | 392 | signal(SIGINT, inthandler); |
388 | signal (SIGINT, termhandler); | 393 | signal(SIGINT, termhandler); |
389 | 394 | ||
390 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 395 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
391 | "Returned, stopping playback\n"); | 396 | "Returned, stopping playback\n"); |
392 | quit (); | 397 | quit(); |
393 | 398 | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
395 | "Deleting pipeline\n"); | 400 | "Deleting pipeline\n"); |
396 | gst_object_unref (GST_OBJECT (source)); | 401 | gst_object_unref(GST_OBJECT(source)); |
397 | source = NULL; | 402 | source = NULL; |
398 | gst_object_unref (GST_OBJECT (pipeline)); | 403 | gst_object_unref(GST_OBJECT(pipeline)); |
399 | pipeline = NULL; | 404 | pipeline = NULL; |
400 | g_source_remove (bus_watch_id); | 405 | g_source_remove(bus_watch_id); |
401 | 406 | ||
402 | return 0; | 407 | return 0; |
403 | } | 408 | } |
diff --git a/src/conversation/gnunet-helper-audio-playback.c b/src/conversation/gnunet-helper-audio-playback.c index e86bb6508..34e61c100 100644 --- a/src/conversation/gnunet-helper-audio-playback.c +++ b/src/conversation/gnunet-helper-audio-playback.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-helper-audio-playback.c | 21 | * @file conversation/gnunet-helper-audio-playback.c |
22 | * @brief program to playback audio data to the speaker | 22 | * @brief program to playback audio data to the speaker |
@@ -124,8 +124,7 @@ static float gain; | |||
124 | GNUNET_NETWORK_STRUCT_BEGIN | 124 | GNUNET_NETWORK_STRUCT_BEGIN |
125 | 125 | ||
126 | /* OggOpus spec says the numbers must be in little-endian order */ | 126 | /* OggOpus spec says the numbers must be in little-endian order */ |
127 | struct OpusHeadPacket | 127 | struct OpusHeadPacket { |
128 | { | ||
129 | uint8_t magic[8]; | 128 | uint8_t magic[8]; |
130 | uint8_t version; | 129 | uint8_t version; |
131 | uint8_t channels; | 130 | uint8_t channels; |
@@ -143,71 +142,71 @@ GNUNET_NETWORK_STRUCT_END | |||
143 | * elsewhere in the code. | 142 | * elsewhere in the code. |
144 | */ | 143 | */ |
145 | static OpusDecoder * | 144 | static OpusDecoder * |
146 | process_header (ogg_packet *op) | 145 | process_header(ogg_packet *op) |
147 | { | 146 | { |
148 | int err; | 147 | int err; |
149 | OpusDecoder *dec; | 148 | OpusDecoder *dec; |
150 | struct OpusHeadPacket header; | 149 | struct OpusHeadPacket header; |
151 | 150 | ||
152 | if ( ((unsigned int) op->bytes) < sizeof (header)) | 151 | if (((unsigned int)op->bytes) < sizeof(header)) |
153 | return NULL; | 152 | return NULL; |
154 | GNUNET_memcpy (&header, | 153 | GNUNET_memcpy(&header, |
155 | op->packet, | 154 | op->packet, |
156 | sizeof (header)); | 155 | sizeof(header)); |
157 | header.preskip = GNUNET_le16toh (header.preskip); | 156 | header.preskip = GNUNET_le16toh(header.preskip); |
158 | header.sampling_rate = GNUNET_le32toh (header.sampling_rate); | 157 | header.sampling_rate = GNUNET_le32toh(header.sampling_rate); |
159 | header.gain = GNUNET_le16toh (header.gain); | 158 | header.gain = GNUNET_le16toh(header.gain); |
160 | 159 | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
162 | "Header: v%u, %u-ch, skip %u, %uHz, %u gain\n", | 161 | "Header: v%u, %u-ch, skip %u, %uHz, %u gain\n", |
163 | header.version, | 162 | header.version, |
164 | header.channels, | 163 | header.channels, |
165 | header.preskip, | 164 | header.preskip, |
166 | header.sampling_rate, | 165 | header.sampling_rate, |
167 | header.gain); | 166 | header.gain); |
168 | channels = header.channels; | 167 | channels = header.channels; |
169 | preskip = header.preskip; | 168 | preskip = header.preskip; |
170 | 169 | ||
171 | if (header.channel_mapping != 0) | 170 | if (header.channel_mapping != 0) |
172 | { | 171 | { |
173 | fprintf (stderr, | 172 | fprintf(stderr, |
174 | "This implementation does not support non-mono streams\n"); | 173 | "This implementation does not support non-mono streams\n"); |
175 | return NULL; | 174 | return NULL; |
176 | } | 175 | } |
177 | 176 | ||
178 | dec = opus_decoder_create (SAMPLING_RATE, channels, &err); | 177 | dec = opus_decoder_create(SAMPLING_RATE, channels, &err); |
179 | if (OPUS_OK != err) | 178 | if (OPUS_OK != err) |
180 | { | ||
181 | fprintf (stderr, | ||
182 | "Cannot create encoder: %s\n", | ||
183 | opus_strerror (err)); | ||
184 | return NULL; | ||
185 | } | ||
186 | if (! dec) | ||
187 | { | ||
188 | fprintf (stderr, | ||
189 | "Decoder initialization failed: %s\n", | ||
190 | opus_strerror (err)); | ||
191 | return NULL; | ||
192 | } | ||
193 | |||
194 | if (0 != header.gain) | ||
195 | { | ||
196 | /*Gain API added in a newer libopus version, if we don't have it | ||
197 | we apply the gain ourselves. We also add in a user provided | ||
198 | manual gain at the same time.*/ | ||
199 | int gainadj = (int) header.gain; | ||
200 | err = opus_decoder_ctl (dec, OPUS_SET_GAIN (gainadj)); | ||
201 | if(OPUS_UNIMPLEMENTED == err) | ||
202 | { | 179 | { |
203 | gain = pow (10.0, gainadj / 5120.0); | 180 | fprintf(stderr, |
181 | "Cannot create encoder: %s\n", | ||
182 | opus_strerror(err)); | ||
183 | return NULL; | ||
204 | } | 184 | } |
205 | else if (OPUS_OK != err) | 185 | if (!dec) |
206 | { | 186 | { |
207 | fprintf (stderr, "Error setting gain: %s\n", opus_strerror (err)); | 187 | fprintf(stderr, |
188 | "Decoder initialization failed: %s\n", | ||
189 | opus_strerror(err)); | ||
208 | return NULL; | 190 | return NULL; |
209 | } | 191 | } |
210 | } | 192 | |
193 | if (0 != header.gain) | ||
194 | { | ||
195 | /*Gain API added in a newer libopus version, if we don't have it | ||
196 | we apply the gain ourselves. We also add in a user provided | ||
197 | manual gain at the same time.*/ | ||
198 | int gainadj = (int)header.gain; | ||
199 | err = opus_decoder_ctl(dec, OPUS_SET_GAIN(gainadj)); | ||
200 | if (OPUS_UNIMPLEMENTED == err) | ||
201 | { | ||
202 | gain = pow(10.0, gainadj / 5120.0); | ||
203 | } | ||
204 | else if (OPUS_OK != err) | ||
205 | { | ||
206 | fprintf(stderr, "Error setting gain: %s\n", opus_strerror(err)); | ||
207 | return NULL; | ||
208 | } | ||
209 | } | ||
211 | 210 | ||
212 | return dec; | 211 | return dec; |
213 | } | 212 | } |
@@ -217,122 +216,126 @@ process_header (ogg_packet *op) | |||
217 | static size_t | 216 | static size_t |
218 | fwrite_le32(opus_int32 i32, FILE *file) | 217 | fwrite_le32(opus_int32 i32, FILE *file) |
219 | { | 218 | { |
220 | unsigned char buf[4]; | 219 | unsigned char buf[4]; |
221 | buf[0]=(unsigned char)(i32&0xFF); | 220 | |
222 | buf[1]=(unsigned char)(i32>>8&0xFF); | 221 | buf[0] = (unsigned char)(i32 & 0xFF); |
223 | buf[2]=(unsigned char)(i32>>16&0xFF); | 222 | buf[1] = (unsigned char)(i32 >> 8 & 0xFF); |
224 | buf[3]=(unsigned char)(i32>>24&0xFF); | 223 | buf[2] = (unsigned char)(i32 >> 16 & 0xFF); |
225 | return fwrite(buf,4,1,file); | 224 | buf[3] = (unsigned char)(i32 >> 24 & 0xFF); |
225 | return fwrite(buf, 4, 1, file); | ||
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | static size_t | 229 | static size_t |
230 | fwrite_le16(int i16, FILE *file) | 230 | fwrite_le16(int i16, FILE *file) |
231 | { | 231 | { |
232 | unsigned char buf[2]; | 232 | unsigned char buf[2]; |
233 | buf[0]=(unsigned char)(i16&0xFF); | 233 | |
234 | buf[1]=(unsigned char)(i16>>8&0xFF); | 234 | buf[0] = (unsigned char)(i16 & 0xFF); |
235 | return fwrite(buf,2,1,file); | 235 | buf[1] = (unsigned char)(i16 >> 8 & 0xFF); |
236 | return fwrite(buf, 2, 1, file); | ||
236 | } | 237 | } |
237 | 238 | ||
238 | 239 | ||
239 | static int | 240 | static int |
240 | write_wav_header() | 241 | write_wav_header() |
241 | { | 242 | { |
242 | int ret; | 243 | int ret; |
243 | FILE *file = stdout; | 244 | FILE *file = stdout; |
244 | 245 | ||
245 | ret = fprintf (file, "RIFF") >= 0; | 246 | ret = fprintf(file, "RIFF") >= 0; |
246 | ret &= fwrite_le32 (0x7fffffff, file); | 247 | ret &= fwrite_le32(0x7fffffff, file); |
247 | 248 | ||
248 | ret &= fprintf (file, "WAVEfmt ") >= 0; | 249 | ret &= fprintf(file, "WAVEfmt ") >= 0; |
249 | ret &= fwrite_le32 (16, file); | 250 | ret &= fwrite_le32(16, file); |
250 | ret &= fwrite_le16 (1, file); | 251 | ret &= fwrite_le16(1, file); |
251 | ret &= fwrite_le16 (channels, file); | 252 | ret &= fwrite_le16(channels, file); |
252 | ret &= fwrite_le32 (SAMPLING_RATE, file); | 253 | ret &= fwrite_le32(SAMPLING_RATE, file); |
253 | ret &= fwrite_le32 (2*channels*SAMPLING_RATE, file); | 254 | ret &= fwrite_le32(2 * channels * SAMPLING_RATE, file); |
254 | ret &= fwrite_le16 (2*channels, file); | 255 | ret &= fwrite_le16(2 * channels, file); |
255 | ret &= fwrite_le16 (16, file); | 256 | ret &= fwrite_le16(16, file); |
256 | 257 | ||
257 | ret &= fprintf (file, "data") >= 0; | 258 | ret &= fprintf(file, "data") >= 0; |
258 | ret &= fwrite_le32 (0x7fffffff, file); | 259 | ret &= fwrite_le32(0x7fffffff, file); |
259 | 260 | ||
260 | return !ret ? -1 : 16; | 261 | return !ret ? -1 : 16; |
261 | } | 262 | } |
262 | 263 | ||
263 | #endif | 264 | #endif |
264 | 265 | ||
265 | 266 | ||
266 | static int64_t | 267 | static int64_t |
267 | audio_write (int64_t maxout) | 268 | audio_write(int64_t maxout) |
268 | { | 269 | { |
269 | int64_t sampout = 0; | 270 | int64_t sampout = 0; |
270 | int tmp_skip; | 271 | int tmp_skip; |
271 | unsigned out_len; | 272 | unsigned out_len; |
272 | unsigned to_write; | 273 | unsigned to_write; |
273 | float *output; | 274 | float *output; |
275 | |||
274 | #ifdef DEBUG_DUMP_DECODED_OGG | 276 | #ifdef DEBUG_DUMP_DECODED_OGG |
275 | static int wrote_wav_header; | 277 | static int wrote_wav_header; |
276 | 278 | ||
277 | if (dump_to_stdout && !wrote_wav_header) | 279 | if (dump_to_stdout && !wrote_wav_header) |
278 | { | 280 | { |
279 | write_wav_header (); | 281 | write_wav_header(); |
280 | wrote_wav_header = 1; | 282 | wrote_wav_header = 1; |
281 | } | 283 | } |
282 | #endif | 284 | #endif |
283 | maxout = 0 > maxout ? 0 : maxout; | 285 | maxout = 0 > maxout ? 0 : maxout; |
284 | do | 286 | do |
285 | { | ||
286 | tmp_skip = (preskip > frame_size) ? (int) frame_size : preskip; | ||
287 | preskip -= tmp_skip; | ||
288 | output = pcm_buffer + channels * tmp_skip; | ||
289 | out_len = frame_size - tmp_skip; | ||
290 | if (out_len > MAX_FRAME_SIZE) | ||
291 | exit (6); | ||
292 | frame_size = 0; | ||
293 | |||
294 | to_write = out_len < maxout ? out_len : (unsigned) maxout; | ||
295 | if (0 < maxout) | ||
296 | { | 287 | { |
297 | int64_t wrote = 0; | 288 | tmp_skip = (preskip > frame_size) ? (int)frame_size : preskip; |
298 | wrote = to_write; | 289 | preskip -= tmp_skip; |
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 290 | output = pcm_buffer + channels * tmp_skip; |
300 | "Writing %u * %u * %u = %llu bytes into PA\n", | 291 | out_len = frame_size - tmp_skip; |
301 | to_write, | 292 | if (out_len > MAX_FRAME_SIZE) |
302 | channels, | 293 | exit(6); |
303 | (unsigned int) sizeof (float), | 294 | frame_size = 0; |
304 | (unsigned long long) (to_write * channels * sizeof (float))); | 295 | |
296 | to_write = out_len < maxout ? out_len : (unsigned)maxout; | ||
297 | if (0 < maxout) | ||
298 | { | ||
299 | int64_t wrote = 0; | ||
300 | wrote = to_write; | ||
301 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "Writing %u * %u * %u = %llu bytes into PA\n", | ||
303 | to_write, | ||
304 | channels, | ||
305 | (unsigned int)sizeof(float), | ||
306 | (unsigned long long)(to_write * channels * sizeof(float))); | ||
305 | #ifdef DEBUG_DUMP_DECODED_OGG | 307 | #ifdef DEBUG_DUMP_DECODED_OGG |
306 | if (dump_to_stdout) | 308 | if (dump_to_stdout) |
307 | { | 309 | { |
308 | # define fminf(_x,_y) ((_x)<(_y)?(_x):(_y)) | 310 | # define fminf(_x, _y) ((_x) < (_y) ? (_x) : (_y)) |
309 | # define fmaxf(_x,_y) ((_x)>(_y)?(_x):(_y)) | 311 | # define fmaxf(_x, _y) ((_x) > (_y) ? (_x) : (_y)) |
310 | # define float2int(flt) ((int)(floor(.5+flt))) | 312 | # define float2int(flt) ((int)(floor(.5 + flt))) |
311 | int i; | 313 | int i; |
312 | int16_t *out = alloca(sizeof(short)*MAX_FRAME_SIZE*channels); | 314 | int16_t *out = alloca(sizeof(short) * MAX_FRAME_SIZE * channels); |
313 | for (i=0;i<(int)out_len*channels;i++) | 315 | for (i = 0; i < (int)out_len * channels; i++) |
314 | out[i]=(short)float2int(fmaxf(-32768,fminf(output[i]*32768.f,32767))); | 316 | out[i] = (short)float2int(fmaxf(-32768, fminf(output[i] * 32768.f, 32767))); |
315 | 317 | ||
316 | fwrite (out, 2 * channels, out_len<maxout?out_len:maxout, stdout); | 318 | fwrite(out, 2 * channels, out_len < maxout ? out_len : maxout, stdout); |
317 | } | 319 | } |
318 | else | 320 | else |
319 | #endif | 321 | #endif |
320 | if (pa_stream_write | 322 | if (pa_stream_write |
321 | (stream_out, output, to_write * channels * sizeof (float), NULL, 0, | 323 | (stream_out, output, to_write * channels * sizeof(float), NULL, 0, |
322 | PA_SEEK_RELATIVE) < 0) | 324 | PA_SEEK_RELATIVE) < 0) |
323 | { | 325 | { |
324 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 326 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
325 | _("pa_stream_write() failed: %s\n"), | 327 | _("pa_stream_write() failed: %s\n"), |
326 | pa_strerror (pa_context_errno (context))); | 328 | pa_strerror(pa_context_errno(context))); |
327 | } | 329 | } |
328 | sampout += wrote; | 330 | sampout += wrote; |
329 | maxout -= wrote; | 331 | maxout -= wrote; |
332 | } | ||
330 | } | 333 | } |
331 | } while (0 < frame_size && 0 < maxout); | 334 | while (0 < frame_size && 0 < maxout); |
332 | 335 | ||
333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
334 | "Wrote %" PRId64 " samples\n", | 337 | "Wrote %" PRId64 " samples\n", |
335 | sampout); | 338 | sampout); |
336 | return sampout; | 339 | return sampout; |
337 | } | 340 | } |
338 | 341 | ||
@@ -341,16 +344,16 @@ audio_write (int64_t maxout) | |||
341 | * Pulseaudio shutdown task | 344 | * Pulseaudio shutdown task |
342 | */ | 345 | */ |
343 | static void | 346 | static void |
344 | quit (int ret) | 347 | quit(int ret) |
345 | { | 348 | { |
346 | mainloop_api->quit (mainloop_api, | 349 | mainloop_api->quit(mainloop_api, |
347 | ret); | 350 | ret); |
348 | exit (ret); | 351 | exit(ret); |
349 | } | 352 | } |
350 | 353 | ||
351 | 354 | ||
352 | static void | 355 | static void |
353 | ogg_demux_and_decode () | 356 | ogg_demux_and_decode() |
354 | { | 357 | { |
355 | ogg_page og; | 358 | ogg_page og; |
356 | static int stream_init; | 359 | static int stream_init; |
@@ -365,189 +368,189 @@ ogg_demux_and_decode () | |||
365 | static int total_links; | 368 | static int total_links; |
366 | static int gran_offset; | 369 | static int gran_offset; |
367 | 370 | ||
368 | while (1 == ogg_sync_pageout (&oy, &og)) | 371 | while (1 == ogg_sync_pageout(&oy, &og)) |
369 | { | ||
370 | if (0 == stream_init) | ||
371 | { | 372 | { |
372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | if (0 == stream_init) |
373 | "Initialized the stream\n"); | ||
374 | ogg_stream_init (&os, ogg_page_serialno (&og)); | ||
375 | stream_init = 1; | ||
376 | } | ||
377 | if (ogg_page_serialno (&og) != os.serialno) | ||
378 | { | ||
379 | /* so all streams are read. */ | ||
380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
381 | "Re-set serial number\n"); | ||
382 | ogg_stream_reset_serialno (&os, ogg_page_serialno (&og)); | ||
383 | } | ||
384 | /*Add page to the bitstream*/ | ||
385 | ogg_stream_pagein (&os, &og); | ||
386 | page_granule = ogg_page_granulepos (&og); | ||
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
388 | "Reading page that ends at %" PRId64 "\n", | ||
389 | page_granule); | ||
390 | /*Extract all available packets*/ | ||
391 | while (1 == ogg_stream_packetout (&os, &op)) | ||
392 | { | ||
393 | /*OggOpus streams are identified by a magic string in the initial | ||
394 | stream header.*/ | ||
395 | if (op.b_o_s && op.bytes >= 8 && !memcmp (op.packet, "OpusHead", 8)) | ||
396 | { | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
398 | "Got Opus Header\n"); | ||
399 | if (has_opus_stream && has_tags_packet) | ||
400 | { | ||
401 | /*If we're seeing another BOS OpusHead now it means | ||
402 | the stream is chained without an EOS. | ||
403 | This can easily happen if record helper is terminated unexpectedly. | ||
404 | */ | ||
405 | has_opus_stream = 0; | ||
406 | if (dec) | ||
407 | opus_decoder_destroy (dec); | ||
408 | dec = NULL; | ||
409 | fprintf (stderr, "\nWarning: stream %" PRId64 " ended without EOS and a new stream began.\n", (int64_t) os.serialno); | ||
410 | } | ||
411 | if (!has_opus_stream) | ||
412 | { | 374 | { |
413 | if (packet_count > 0 && opus_serialno == os.serialno) | 375 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
414 | { | 376 | "Initialized the stream\n"); |
415 | fprintf (stderr, "\nError: Apparent chaining without changing serial number (%" PRId64 "==%" PRId64 ").\n", | 377 | ogg_stream_init(&os, ogg_page_serialno(&og)); |
416 | (int64_t) opus_serialno, (int64_t) os.serialno); | 378 | stream_init = 1; |
417 | quit(1); | ||
418 | } | ||
419 | opus_serialno = os.serialno; | ||
420 | has_opus_stream = 1; | ||
421 | has_tags_packet = 0; | ||
422 | link_out = 0; | ||
423 | packet_count = 0; | ||
424 | eos = 0; | ||
425 | total_links++; | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Got header for stream %" PRId64 ", this is %dth link\n", | ||
428 | (int64_t) opus_serialno, total_links); | ||
429 | } | 379 | } |
430 | else | 380 | if (ogg_page_serialno(&og) != os.serialno) |
431 | { | 381 | { |
432 | fprintf (stderr, "\nWarning: ignoring opus stream %" PRId64 "\n", (int64_t) os.serialno); | 382 | /* so all streams are read. */ |
383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Re-set serial number\n"); | ||
385 | ogg_stream_reset_serialno(&os, ogg_page_serialno(&og)); | ||
433 | } | 386 | } |
434 | } | 387 | /*Add page to the bitstream*/ |
435 | if (!has_opus_stream || os.serialno != opus_serialno) | 388 | ogg_stream_pagein(&os, &og); |
436 | { | 389 | page_granule = ogg_page_granulepos(&og); |
437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
438 | "breaking out\n"); | 391 | "Reading page that ends at %" PRId64 "\n", |
439 | break; | 392 | page_granule); |
440 | } | 393 | /*Extract all available packets*/ |
441 | /*If first packet in a logical stream, process the Opus header*/ | 394 | while (1 == ogg_stream_packetout(&os, &op)) |
442 | if (0 == packet_count) | ||
443 | { | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "Decoding header\n"); | ||
446 | dec = process_header (&op); | ||
447 | if (!dec) | ||
448 | quit (1); | ||
449 | |||
450 | if (0 != ogg_stream_packetout (&os, &op) || 255 == og.header[og.header_len - 1]) | ||
451 | { | ||
452 | /*The format specifies that the initial header and tags packets are on their | ||
453 | own pages. To aid implementors in discovering that their files are wrong | ||
454 | we reject them explicitly here. In some player designs files like this would | ||
455 | fail even without an explicit test.*/ | ||
456 | fprintf (stderr, "Extra packets on initial header page. Invalid stream.\n"); | ||
457 | quit (1); | ||
458 | } | ||
459 | |||
460 | /*Remember how many samples at the front we were told to skip | ||
461 | so that we can adjust the timestamp counting.*/ | ||
462 | gran_offset = preskip; | ||
463 | |||
464 | if (! pcm_buffer) | ||
465 | { | 395 | { |
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 396 | /*OggOpus streams are identified by a magic string in the initial |
467 | "Allocating %u * %u * %u = %llu bytes of buffer space\n", | 397 | stream header.*/ |
468 | MAX_FRAME_SIZE, | 398 | if (op.b_o_s && op.bytes >= 8 && !memcmp(op.packet, "OpusHead", 8)) |
469 | channels, | 399 | { |
470 | (unsigned int) sizeof (float), | 400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
471 | (unsigned long long) (MAX_FRAME_SIZE * channels * sizeof (float))); | 401 | "Got Opus Header\n"); |
472 | pcm_buffer = pa_xmalloc (sizeof (float) * MAX_FRAME_SIZE * channels); | 402 | if (has_opus_stream && has_tags_packet) |
403 | { | ||
404 | /*If we're seeing another BOS OpusHead now it means | ||
405 | the stream is chained without an EOS. | ||
406 | This can easily happen if record helper is terminated unexpectedly. | ||
407 | */ | ||
408 | has_opus_stream = 0; | ||
409 | if (dec) | ||
410 | opus_decoder_destroy(dec); | ||
411 | dec = NULL; | ||
412 | fprintf(stderr, "\nWarning: stream %" PRId64 " ended without EOS and a new stream began.\n", (int64_t)os.serialno); | ||
413 | } | ||
414 | if (!has_opus_stream) | ||
415 | { | ||
416 | if (packet_count > 0 && opus_serialno == os.serialno) | ||
417 | { | ||
418 | fprintf(stderr, "\nError: Apparent chaining without changing serial number (%" PRId64 "==%" PRId64 ").\n", | ||
419 | (int64_t)opus_serialno, (int64_t)os.serialno); | ||
420 | quit(1); | ||
421 | } | ||
422 | opus_serialno = os.serialno; | ||
423 | has_opus_stream = 1; | ||
424 | has_tags_packet = 0; | ||
425 | link_out = 0; | ||
426 | packet_count = 0; | ||
427 | eos = 0; | ||
428 | total_links++; | ||
429 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
430 | "Got header for stream %" PRId64 ", this is %dth link\n", | ||
431 | (int64_t)opus_serialno, total_links); | ||
432 | } | ||
433 | else | ||
434 | { | ||
435 | fprintf(stderr, "\nWarning: ignoring opus stream %" PRId64 "\n", (int64_t)os.serialno); | ||
436 | } | ||
437 | } | ||
438 | if (!has_opus_stream || os.serialno != opus_serialno) | ||
439 | { | ||
440 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
441 | "breaking out\n"); | ||
442 | break; | ||
443 | } | ||
444 | /*If first packet in a logical stream, process the Opus header*/ | ||
445 | if (0 == packet_count) | ||
446 | { | ||
447 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
448 | "Decoding header\n"); | ||
449 | dec = process_header(&op); | ||
450 | if (!dec) | ||
451 | quit(1); | ||
452 | |||
453 | if (0 != ogg_stream_packetout(&os, &op) || 255 == og.header[og.header_len - 1]) | ||
454 | { | ||
455 | /*The format specifies that the initial header and tags packets are on their | ||
456 | own pages. To aid implementors in discovering that their files are wrong | ||
457 | we reject them explicitly here. In some player designs files like this would | ||
458 | fail even without an explicit test.*/ | ||
459 | fprintf(stderr, "Extra packets on initial header page. Invalid stream.\n"); | ||
460 | quit(1); | ||
461 | } | ||
462 | |||
463 | /*Remember how many samples at the front we were told to skip | ||
464 | so that we can adjust the timestamp counting.*/ | ||
465 | gran_offset = preskip; | ||
466 | |||
467 | if (!pcm_buffer) | ||
468 | { | ||
469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
470 | "Allocating %u * %u * %u = %llu bytes of buffer space\n", | ||
471 | MAX_FRAME_SIZE, | ||
472 | channels, | ||
473 | (unsigned int)sizeof(float), | ||
474 | (unsigned long long)(MAX_FRAME_SIZE * channels * sizeof(float))); | ||
475 | pcm_buffer = pa_xmalloc(sizeof(float) * MAX_FRAME_SIZE * channels); | ||
476 | } | ||
477 | } | ||
478 | else if (1 == packet_count) | ||
479 | { | ||
480 | has_tags_packet = 1; | ||
481 | if (0 != ogg_stream_packetout(&os, &op) || 255 == og.header[og.header_len - 1]) | ||
482 | { | ||
483 | fprintf(stderr, "Extra packets on initial tags page. Invalid stream.\n"); | ||
484 | quit(1); | ||
485 | } | ||
486 | } | ||
487 | else | ||
488 | { | ||
489 | int ret; | ||
490 | int64_t maxout; | ||
491 | int64_t outsamp; | ||
492 | |||
493 | /*End of stream condition*/ | ||
494 | if (op.e_o_s && os.serialno == opus_serialno) | ||
495 | { | ||
496 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
497 | "Got EOS\n"); | ||
498 | eos = 1; /* don't care for anything except opus eos */ | ||
499 | } | ||
500 | |||
501 | /*Decode Opus packet*/ | ||
502 | ret = opus_decode_float(dec, | ||
503 | (const unsigned char *)op.packet, | ||
504 | op.bytes, | ||
505 | pcm_buffer, | ||
506 | MAX_FRAME_SIZE, 0); | ||
507 | |||
508 | /*If the decoder returned less than zero, we have an error.*/ | ||
509 | if (0 > ret) | ||
510 | { | ||
511 | fprintf(stderr, "Decoding error: %s\n", opus_strerror(ret)); | ||
512 | break; | ||
513 | } | ||
514 | frame_size = ret; | ||
515 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
516 | "Decoded %d bytes/channel (%d bytes) from %u compressed bytes\n", | ||
517 | ret, | ||
518 | ret * channels, | ||
519 | (unsigned int)op.bytes); | ||
520 | |||
521 | /*Apply header gain, if we're not using an opus library new | ||
522 | enough to do this internally.*/ | ||
523 | if (0 != gain) | ||
524 | { | ||
525 | int i; | ||
526 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
527 | "Applying gain %f\n", | ||
528 | gain); | ||
529 | for (i = 0; i < frame_size * channels; i++) | ||
530 | pcm_buffer[i] *= gain; | ||
531 | } | ||
532 | |||
533 | /*This handles making sure that our output duration respects | ||
534 | the final end-trim by not letting the output sample count | ||
535 | get ahead of the granpos indicated value.*/ | ||
536 | maxout = ((page_granule - gran_offset) * SAMPLING_RATE / 48000) - link_out; | ||
537 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
538 | "Writing audio packet %" PRId64 ", at most %" PRId64 " samples\n", | ||
539 | packet_count, maxout); | ||
540 | |||
541 | outsamp = audio_write(0 > maxout ? 0 : maxout); | ||
542 | link_out += outsamp; | ||
543 | } | ||
544 | packet_count++; | ||
473 | } | 545 | } |
474 | } | 546 | if (eos) |
475 | else if (1 == packet_count) | ||
476 | { | ||
477 | has_tags_packet = 1; | ||
478 | if (0 != ogg_stream_packetout (&os, &op) || 255 == og.header[og.header_len - 1]) | ||
479 | { | 547 | { |
480 | fprintf (stderr, "Extra packets on initial tags page. Invalid stream.\n"); | 548 | has_opus_stream = 0; |
481 | quit (1); | 549 | if (dec) |
482 | } | 550 | opus_decoder_destroy(dec); |
483 | } | 551 | dec = NULL; |
484 | else | ||
485 | { | ||
486 | int ret; | ||
487 | int64_t maxout; | ||
488 | int64_t outsamp; | ||
489 | |||
490 | /*End of stream condition*/ | ||
491 | if (op.e_o_s && os.serialno == opus_serialno) | ||
492 | { | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
494 | "Got EOS\n"); | ||
495 | eos = 1; /* don't care for anything except opus eos */ | ||
496 | } | ||
497 | |||
498 | /*Decode Opus packet*/ | ||
499 | ret = opus_decode_float (dec, | ||
500 | (const unsigned char *) op.packet, | ||
501 | op.bytes, | ||
502 | pcm_buffer, | ||
503 | MAX_FRAME_SIZE, 0); | ||
504 | |||
505 | /*If the decoder returned less than zero, we have an error.*/ | ||
506 | if (0 > ret) | ||
507 | { | ||
508 | fprintf (stderr, "Decoding error: %s\n", opus_strerror (ret)); | ||
509 | break; | ||
510 | } | ||
511 | frame_size = ret; | ||
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
513 | "Decoded %d bytes/channel (%d bytes) from %u compressed bytes\n", | ||
514 | ret, | ||
515 | ret * channels, | ||
516 | (unsigned int) op.bytes); | ||
517 | |||
518 | /*Apply header gain, if we're not using an opus library new | ||
519 | enough to do this internally.*/ | ||
520 | if (0 != gain) | ||
521 | { | ||
522 | int i; | ||
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
524 | "Applying gain %f\n", | ||
525 | gain); | ||
526 | for (i = 0; i < frame_size * channels; i++) | ||
527 | pcm_buffer[i] *= gain; | ||
528 | } | 552 | } |
529 | |||
530 | /*This handles making sure that our output duration respects | ||
531 | the final end-trim by not letting the output sample count | ||
532 | get ahead of the granpos indicated value.*/ | ||
533 | maxout = ((page_granule - gran_offset) * SAMPLING_RATE / 48000) - link_out; | ||
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
535 | "Writing audio packet %" PRId64 ", at most %" PRId64 " samples\n", | ||
536 | packet_count, maxout); | ||
537 | |||
538 | outsamp = audio_write (0 > maxout ? 0 : maxout); | ||
539 | link_out += outsamp; | ||
540 | } | ||
541 | packet_count++; | ||
542 | } | ||
543 | if (eos) | ||
544 | { | ||
545 | has_opus_stream = 0; | ||
546 | if (dec) | ||
547 | opus_decoder_destroy (dec); | ||
548 | dec = NULL; | ||
549 | } | 553 | } |
550 | } | ||
551 | } | 554 | } |
552 | 555 | ||
553 | 556 | ||
@@ -560,31 +563,32 @@ ogg_demux_and_decode () | |||
560 | * #GNUNET_SYSERR to stop further processing due to error | 563 | * #GNUNET_SYSERR to stop further processing due to error |
561 | */ | 564 | */ |
562 | static int | 565 | static int |
563 | stdin_receiver (void *cls, | 566 | stdin_receiver(void *cls, |
564 | const struct GNUNET_MessageHeader *msg) | 567 | const struct GNUNET_MessageHeader *msg) |
565 | { | 568 | { |
566 | struct AudioMessage *audio; | 569 | struct AudioMessage *audio; |
567 | char *data; | 570 | char *data; |
568 | size_t payload_len; | 571 | size_t payload_len; |
569 | 572 | ||
570 | (void) cls; | 573 | (void)cls; |
571 | switch (ntohs (msg->type)) | 574 | switch (ntohs(msg->type)) |
572 | { | 575 | { |
573 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 576 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
574 | audio = (struct AudioMessage *) msg; | 577 | audio = (struct AudioMessage *)msg; |
575 | payload_len = ntohs (audio->header.size) - sizeof (struct AudioMessage); | 578 | payload_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); |
576 | 579 | ||
577 | /*Get the ogg buffer for writing*/ | 580 | /*Get the ogg buffer for writing*/ |
578 | data = ogg_sync_buffer (&oy, payload_len); | 581 | data = ogg_sync_buffer(&oy, payload_len); |
579 | /*Read bitstream from input file*/ | 582 | /*Read bitstream from input file*/ |
580 | GNUNET_memcpy (data, (const unsigned char *) &audio[1], payload_len); | 583 | GNUNET_memcpy(data, (const unsigned char *)&audio[1], payload_len); |
581 | ogg_sync_wrote (&oy, payload_len); | 584 | ogg_sync_wrote(&oy, payload_len); |
582 | 585 | ||
583 | ogg_demux_and_decode (); | 586 | ogg_demux_and_decode(); |
584 | break; | 587 | break; |
585 | default: | 588 | |
586 | break; | 589 | default: |
587 | } | 590 | break; |
591 | } | ||
588 | return GNUNET_OK; | 592 | return GNUNET_OK; |
589 | } | 593 | } |
590 | 594 | ||
@@ -593,20 +597,20 @@ stdin_receiver (void *cls, | |||
593 | * Callback when data is there for playback | 597 | * Callback when data is there for playback |
594 | */ | 598 | */ |
595 | static void | 599 | static void |
596 | stream_write_callback (pa_stream *s, | 600 | stream_write_callback(pa_stream *s, |
597 | size_t length, | 601 | size_t length, |
598 | void *userdata) | 602 | void *userdata) |
599 | { | 603 | { |
600 | /* unblock 'main' */ | 604 | /* unblock 'main' */ |
601 | (void) userdata; | 605 | (void)userdata; |
602 | (void) length; | 606 | (void)length; |
603 | (void) s; | 607 | (void)s; |
604 | if (-1 != ready_pipe[1]) | 608 | if (-1 != ready_pipe[1]) |
605 | { | 609 | { |
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 610 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
607 | "Unblocking main loop!\n"); | 611 | "Unblocking main loop!\n"); |
608 | (void) write (ready_pipe[1], "r", 1); | 612 | (void)write(ready_pipe[1], "r", 1); |
609 | } | 613 | } |
610 | } | 614 | } |
611 | 615 | ||
612 | 616 | ||
@@ -614,18 +618,18 @@ stream_write_callback (pa_stream *s, | |||
614 | * Exit callback for SIGTERM and SIGINT | 618 | * Exit callback for SIGTERM and SIGINT |
615 | */ | 619 | */ |
616 | static void | 620 | static void |
617 | exit_signal_callback (pa_mainloop_api *m, | 621 | exit_signal_callback(pa_mainloop_api *m, |
618 | pa_signal_event *e, | 622 | pa_signal_event *e, |
619 | int sig, | 623 | int sig, |
620 | void *userdata) | 624 | void *userdata) |
621 | { | 625 | { |
622 | (void) m; | 626 | (void)m; |
623 | (void) e; | 627 | (void)e; |
624 | (void) sig; | 628 | (void)sig; |
625 | (void) userdata; | 629 | (void)userdata; |
626 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 630 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
627 | _("gnunet-helper-audio-playback - Got signal, exiting\n")); | 631 | _("gnunet-helper-audio-playback - Got signal, exiting\n")); |
628 | quit (1); | 632 | quit(1); |
629 | } | 633 | } |
630 | 634 | ||
631 | 635 | ||
@@ -633,62 +637,64 @@ exit_signal_callback (pa_mainloop_api *m, | |||
633 | * Pulseaudio stream state callback | 637 | * Pulseaudio stream state callback |
634 | */ | 638 | */ |
635 | static void | 639 | static void |
636 | context_state_callback (pa_context *c, | 640 | context_state_callback(pa_context *c, |
637 | void *userdata) | 641 | void *userdata) |
638 | { | 642 | { |
639 | int p; | 643 | int p; |
640 | 644 | ||
641 | (void) userdata; | 645 | (void)userdata; |
642 | GNUNET_assert (NULL != c); | 646 | GNUNET_assert(NULL != c); |
643 | switch (pa_context_get_state (c)) | 647 | switch (pa_context_get_state(c)) |
644 | { | ||
645 | case PA_CONTEXT_CONNECTING: | ||
646 | case PA_CONTEXT_AUTHORIZING: | ||
647 | case PA_CONTEXT_SETTING_NAME: | ||
648 | break; | ||
649 | case PA_CONTEXT_READY: | ||
650 | { | ||
651 | GNUNET_assert (! stream_out); | ||
652 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
653 | _("Connection established.\n")); | ||
654 | if (! (stream_out = | ||
655 | pa_stream_new (c, "GNUNET VoIP playback", &sample_spec, NULL))) | ||
656 | { | 648 | { |
657 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 649 | case PA_CONTEXT_CONNECTING: |
658 | _("pa_stream_new() failed: %s\n"), | 650 | case PA_CONTEXT_AUTHORIZING: |
659 | pa_strerror (pa_context_errno (c))); | 651 | case PA_CONTEXT_SETTING_NAME: |
660 | goto fail; | 652 | break; |
661 | } | 653 | |
662 | pa_stream_set_write_callback (stream_out, | 654 | case PA_CONTEXT_READY: |
663 | &stream_write_callback, | ||
664 | NULL); | ||
665 | if ((p = | ||
666 | pa_stream_connect_playback (stream_out, NULL, | ||
667 | NULL, | ||
668 | PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE, | ||
669 | NULL, NULL)) < 0) | ||
670 | { | 655 | { |
671 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 656 | GNUNET_assert(!stream_out); |
672 | _("pa_stream_connect_playback() failed: %s\n"), | 657 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
673 | pa_strerror (pa_context_errno (c))); | 658 | _("Connection established.\n")); |
659 | if (!(stream_out = | ||
660 | pa_stream_new(c, "GNUNET VoIP playback", &sample_spec, NULL))) | ||
661 | { | ||
662 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
663 | _("pa_stream_new() failed: %s\n"), | ||
664 | pa_strerror(pa_context_errno(c))); | ||
665 | goto fail; | ||
666 | } | ||
667 | pa_stream_set_write_callback(stream_out, | ||
668 | &stream_write_callback, | ||
669 | NULL); | ||
670 | if ((p = | ||
671 | pa_stream_connect_playback(stream_out, NULL, | ||
672 | NULL, | ||
673 | PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE, | ||
674 | NULL, NULL)) < 0) | ||
675 | { | ||
676 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
677 | _("pa_stream_connect_playback() failed: %s\n"), | ||
678 | pa_strerror(pa_context_errno(c))); | ||
679 | goto fail; | ||
680 | } | ||
681 | break; | ||
682 | } | ||
683 | |||
684 | case PA_CONTEXT_TERMINATED: | ||
685 | quit(0); | ||
686 | break; | ||
687 | |||
688 | case PA_CONTEXT_FAILED: | ||
689 | default: | ||
690 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
691 | _("Connection failure: %s\n"), | ||
692 | pa_strerror(pa_context_errno(c))); | ||
674 | goto fail; | 693 | goto fail; |
675 | } | 694 | } |
676 | break; | ||
677 | } | ||
678 | case PA_CONTEXT_TERMINATED: | ||
679 | quit (0); | ||
680 | break; | ||
681 | |||
682 | case PA_CONTEXT_FAILED: | ||
683 | default: | ||
684 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
685 | _("Connection failure: %s\n"), | ||
686 | pa_strerror (pa_context_errno (c))); | ||
687 | goto fail; | ||
688 | } | ||
689 | return; | 695 | return; |
690 | fail: | 696 | fail: |
691 | quit (1); | 697 | quit(1); |
692 | } | 698 | } |
693 | 699 | ||
694 | 700 | ||
@@ -696,66 +702,66 @@ context_state_callback (pa_context *c, | |||
696 | * Pulseaudio initialization | 702 | * Pulseaudio initialization |
697 | */ | 703 | */ |
698 | static void | 704 | static void |
699 | pa_init () | 705 | pa_init() |
700 | { | 706 | { |
701 | int r; | 707 | int r; |
702 | 708 | ||
703 | if (!pa_sample_spec_valid (&sample_spec)) | 709 | if (!pa_sample_spec_valid(&sample_spec)) |
704 | { | 710 | { |
705 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 711 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
706 | _("Wrong Spec\n")); | 712 | _("Wrong Spec\n")); |
707 | } | 713 | } |
708 | /* set up threaded playback mainloop */ | 714 | /* set up threaded playback mainloop */ |
709 | if (!(m = pa_threaded_mainloop_new ())) | 715 | if (!(m = pa_threaded_mainloop_new())) |
710 | { | 716 | { |
711 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 717 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
712 | _("pa_mainloop_new() failed.\n")); | 718 | _("pa_mainloop_new() failed.\n")); |
713 | } | 719 | } |
714 | mainloop_api = pa_threaded_mainloop_get_api (m); | 720 | mainloop_api = pa_threaded_mainloop_get_api(m); |
715 | /* listen to signals */ | 721 | /* listen to signals */ |
716 | r = pa_signal_init (mainloop_api); | 722 | r = pa_signal_init(mainloop_api); |
717 | GNUNET_assert (r == 0); | 723 | GNUNET_assert(r == 0); |
718 | pa_signal_new (SIGINT, exit_signal_callback, NULL); | 724 | pa_signal_new(SIGINT, exit_signal_callback, NULL); |
719 | pa_signal_new (SIGTERM, exit_signal_callback, NULL); | 725 | pa_signal_new(SIGTERM, exit_signal_callback, NULL); |
720 | 726 | ||
721 | 727 | ||
722 | /* connect to the main pulseaudio context */ | 728 | /* connect to the main pulseaudio context */ |
723 | if (!(context = pa_context_new (mainloop_api, "GNUnet VoIP"))) | 729 | if (!(context = pa_context_new(mainloop_api, "GNUnet VoIP"))) |
724 | { | 730 | { |
725 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 731 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
726 | _("pa_context_new() failed.\n")); | 732 | _("pa_context_new() failed.\n")); |
727 | } | 733 | } |
728 | pa_context_set_state_callback (context, context_state_callback, NULL); | 734 | pa_context_set_state_callback(context, context_state_callback, NULL); |
729 | 735 | ||
730 | if (pa_context_connect (context, NULL, 0, NULL) < 0) | 736 | if (pa_context_connect(context, NULL, 0, NULL) < 0) |
731 | { | 737 | { |
732 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 738 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
733 | _("pa_context_connect() failed: %s\n"), | 739 | _("pa_context_connect() failed: %s\n"), |
734 | pa_strerror (pa_context_errno (context))); | 740 | pa_strerror(pa_context_errno(context))); |
735 | } | 741 | } |
736 | if (pa_threaded_mainloop_start (m) < 0) | 742 | if (pa_threaded_mainloop_start(m) < 0) |
737 | { | 743 | { |
738 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 744 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
739 | _("pa_mainloop_run() failed.\n")); | 745 | _("pa_mainloop_run() failed.\n")); |
740 | } | 746 | } |
741 | } | 747 | } |
742 | 748 | ||
743 | 749 | ||
744 | static void | 750 | static void |
745 | ogg_init () | 751 | ogg_init() |
746 | { | 752 | { |
747 | ogg_sync_init (&oy); | 753 | ogg_sync_init(&oy); |
748 | } | 754 | } |
749 | 755 | ||
750 | 756 | ||
751 | static void | 757 | static void |
752 | drain_callback (pa_stream*s, int success, void *userdata) | 758 | drain_callback(pa_stream*s, int success, void *userdata) |
753 | { | 759 | { |
754 | (void) s; | 760 | (void)s; |
755 | (void) success; | 761 | (void)success; |
756 | (void) userdata; | 762 | (void)userdata; |
757 | pa_threaded_mainloop_signal (m, | 763 | pa_threaded_mainloop_signal(m, |
758 | 0); | 764 | 0); |
759 | } | 765 | } |
760 | 766 | ||
761 | 767 | ||
@@ -767,95 +773,96 @@ drain_callback (pa_stream*s, int success, void *userdata) | |||
767 | * @return 0 ok, 1 on error | 773 | * @return 0 ok, 1 on error |
768 | */ | 774 | */ |
769 | int | 775 | int |
770 | main (int argc, char *argv[]) | 776 | main(int argc, char *argv[]) |
771 | { | 777 | { |
772 | static unsigned long long toff; | 778 | static unsigned long long toff; |
773 | char readbuf[MAXLINE]; | 779 | char readbuf[MAXLINE]; |
774 | struct GNUNET_MessageStreamTokenizer *stdin_mst; | 780 | struct GNUNET_MessageStreamTokenizer *stdin_mst; |
775 | char c; | 781 | char c; |
776 | ssize_t ret; | 782 | ssize_t ret; |
783 | |||
777 | #ifdef DEBUG_READ_PURE_OGG | 784 | #ifdef DEBUG_READ_PURE_OGG |
778 | int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0; | 785 | int read_pure_ogg = getenv("GNUNET_READ_PURE_OGG") ? 1 : 0; |
779 | #endif | 786 | #endif |
780 | 787 | ||
781 | (void) argc; | 788 | (void)argc; |
782 | (void) argv; | 789 | (void)argv; |
783 | GNUNET_assert (GNUNET_OK == | 790 | GNUNET_assert(GNUNET_OK == |
784 | GNUNET_log_setup ("gnunet-helper-audio-playback", | 791 | GNUNET_log_setup("gnunet-helper-audio-playback", |
785 | "WARNING", | 792 | "WARNING", |
786 | NULL)); | 793 | NULL)); |
787 | if (0 != pipe (ready_pipe)) | 794 | if (0 != pipe(ready_pipe)) |
788 | { | 795 | { |
789 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 796 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "pipe"); |
790 | return 1; | 797 | return 1; |
791 | } | 798 | } |
792 | stdin_mst = GNUNET_MST_create (&stdin_receiver, NULL); | 799 | stdin_mst = GNUNET_MST_create(&stdin_receiver, NULL); |
793 | ogg_init (); | 800 | ogg_init(); |
794 | pa_init (); | 801 | pa_init(); |
795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 802 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
796 | "Waiting for PulseAudio to be ready.\n"); | 803 | "Waiting for PulseAudio to be ready.\n"); |
797 | GNUNET_assert (1 == read (ready_pipe[0], &c, 1)); | 804 | GNUNET_assert(1 == read(ready_pipe[0], &c, 1)); |
798 | close (ready_pipe[0]); | 805 | close(ready_pipe[0]); |
799 | close (ready_pipe[1]); | 806 | close(ready_pipe[1]); |
800 | ready_pipe[0] = -1; | 807 | ready_pipe[0] = -1; |
801 | ready_pipe[1] = -1; | 808 | ready_pipe[1] = -1; |
802 | #ifdef DEBUG_DUMP_DECODED_OGG | 809 | #ifdef DEBUG_DUMP_DECODED_OGG |
803 | dump_to_stdout = getenv ("GNUNET_DUMP_DECODED_OGG") ? 1 : 0; | 810 | dump_to_stdout = getenv("GNUNET_DUMP_DECODED_OGG") ? 1 : 0; |
804 | #endif | 811 | #endif |
805 | while (1) | 812 | while (1) |
806 | { | ||
807 | ret = read (STDIN_FILENO, | ||
808 | readbuf, | ||
809 | sizeof (readbuf)); | ||
810 | toff += ret; | ||
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
812 | "Received %d bytes of audio data (total: %llu)\n", | ||
813 | (int) ret, | ||
814 | toff); | ||
815 | if (0 > ret) | ||
816 | { | 813 | { |
817 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 814 | ret = read(STDIN_FILENO, |
818 | _("Read error from STDIN: %s\n"), | 815 | readbuf, |
819 | strerror (errno)); | 816 | sizeof(readbuf)); |
820 | break; | 817 | toff += ret; |
821 | } | 818 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
822 | if (0 == ret) | 819 | "Received %d bytes of audio data (total: %llu)\n", |
823 | break; | 820 | (int)ret, |
821 | toff); | ||
822 | if (0 > ret) | ||
823 | { | ||
824 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
825 | _("Read error from STDIN: %s\n"), | ||
826 | strerror(errno)); | ||
827 | break; | ||
828 | } | ||
829 | if (0 == ret) | ||
830 | break; | ||
824 | #ifdef DEBUG_READ_PURE_OGG | 831 | #ifdef DEBUG_READ_PURE_OGG |
825 | if (read_pure_ogg) | 832 | if (read_pure_ogg) |
826 | { | 833 | { |
827 | char *data = ogg_sync_buffer (&oy, ret); | 834 | char *data = ogg_sync_buffer(&oy, ret); |
828 | GNUNET_memcpy (data, readbuf, ret); | 835 | GNUNET_memcpy(data, readbuf, ret); |
829 | ogg_sync_wrote (&oy, ret); | 836 | ogg_sync_wrote(&oy, ret); |
830 | ogg_demux_and_decode (); | 837 | ogg_demux_and_decode(); |
831 | } | 838 | } |
832 | else | 839 | else |
833 | #endif | 840 | #endif |
834 | GNUNET_MST_from_buffer (stdin_mst, | 841 | GNUNET_MST_from_buffer(stdin_mst, |
835 | readbuf, ret, | 842 | readbuf, ret, |
836 | GNUNET_NO, GNUNET_NO); | 843 | GNUNET_NO, GNUNET_NO); |
837 | } | 844 | } |
838 | GNUNET_MST_destroy (stdin_mst); | 845 | GNUNET_MST_destroy(stdin_mst); |
839 | if (stream_out) | 846 | if (stream_out) |
840 | { | ||
841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
842 | "Locking\n"); | ||
843 | pa_threaded_mainloop_lock (m); | ||
844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
845 | "Draining\n"); | ||
846 | pa_operation *o = pa_stream_drain (stream_out, drain_callback, NULL); | ||
847 | while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) | ||
848 | { | 847 | { |
849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 848 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
850 | "Waiting\n"); | 849 | "Locking\n"); |
851 | pa_threaded_mainloop_wait (m); | 850 | pa_threaded_mainloop_lock(m); |
851 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
852 | "Draining\n"); | ||
853 | pa_operation *o = pa_stream_drain(stream_out, drain_callback, NULL); | ||
854 | while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) | ||
855 | { | ||
856 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
857 | "Waiting\n"); | ||
858 | pa_threaded_mainloop_wait(m); | ||
859 | } | ||
860 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
861 | "Unreffing\n"); | ||
862 | pa_operation_unref(o); | ||
863 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
864 | "Unlocking\n"); | ||
865 | pa_threaded_mainloop_unlock(m); | ||
852 | } | 866 | } |
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
854 | "Unreffing\n"); | ||
855 | pa_operation_unref (o); | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
857 | "Unlocking\n"); | ||
858 | pa_threaded_mainloop_unlock (m); | ||
859 | } | ||
860 | return 0; | 867 | return 0; |
861 | } | 868 | } |
diff --git a/src/conversation/gnunet-helper-audio-record-gst.c b/src/conversation/gnunet-helper-audio-record-gst.c index 78c94c83e..98ee97d15 100644 --- a/src/conversation/gnunet-helper-audio-record-gst.c +++ b/src/conversation/gnunet-helper-audio-record-gst.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-helper-audio-record-gst.c | 21 | * @file conversation/gnunet-helper-audio-record-gst.c |
22 | * @brief program to record audio data from the microphone (GStreamer version) | 22 | * @brief program to record audio data from the microphone (GStreamer version) |
@@ -102,60 +102,61 @@ static int dump_pure_ogg; | |||
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | static void | 104 | static void |
105 | quit () | 105 | quit() |
106 | { | 106 | { |
107 | if (NULL != pipeline) | 107 | if (NULL != pipeline) |
108 | gst_element_set_state (pipeline, GST_STATE_NULL); | 108 | gst_element_set_state(pipeline, GST_STATE_NULL); |
109 | } | 109 | } |
110 | 110 | ||
111 | static gboolean | 111 | static gboolean |
112 | bus_call (GstBus *bus, GstMessage *msg, gpointer data) | 112 | bus_call(GstBus *bus, GstMessage *msg, gpointer data) |
113 | { | 113 | { |
114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bus message\n"); | 114 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bus message\n"); |
115 | switch (GST_MESSAGE_TYPE (msg)) | 115 | switch (GST_MESSAGE_TYPE(msg)) |
116 | { | 116 | { |
117 | case GST_MESSAGE_EOS: | 117 | case GST_MESSAGE_EOS: |
118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "End of stream\n"); | 118 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "End of stream\n"); |
119 | quit (); | 119 | quit(); |
120 | break; | 120 | break; |
121 | 121 | ||
122 | case GST_MESSAGE_ERROR: | 122 | case GST_MESSAGE_ERROR: |
123 | { | 123 | { |
124 | gchar *debug; | 124 | gchar *debug; |
125 | GError *error; | 125 | GError *error; |
126 | 126 | ||
127 | gst_message_parse_error (msg, &error, &debug); | 127 | gst_message_parse_error(msg, &error, &debug); |
128 | g_free (debug); | 128 | g_free(debug); |
129 | 129 | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error: %s\n", error->message); | 130 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error: %s\n", error->message); |
131 | g_error_free (error); | 131 | g_error_free(error); |
132 | 132 | ||
133 | quit (); | 133 | quit(); |
134 | break; | ||
135 | } | ||
136 | |||
137 | default: | ||
134 | break; | 138 | break; |
135 | } | 139 | } |
136 | default: | ||
137 | break; | ||
138 | } | ||
139 | 140 | ||
140 | return TRUE; | 141 | return TRUE; |
141 | } | 142 | } |
142 | 143 | ||
143 | void | 144 | void |
144 | source_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) | 145 | source_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) |
145 | { | 146 | { |
146 | if (GST_IS_AUDIO_BASE_SRC (object)) | 147 | if (GST_IS_AUDIO_BASE_SRC(object)) |
147 | g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); | 148 | g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); |
148 | } | 149 | } |
149 | 150 | ||
150 | static void | 151 | static void |
151 | signalhandler (int s) | 152 | signalhandler(int s) |
152 | { | 153 | { |
153 | quit (); | 154 | quit(); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | int | 158 | int |
158 | main (int argc, char **argv) | 159 | main(int argc, char **argv) |
159 | { | 160 | { |
160 | GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; | 161 | GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; |
161 | GstCaps *caps; | 162 | GstCaps *caps; |
@@ -167,218 +168,218 @@ main (int argc, char **argv) | |||
167 | typedef void (*SignalHandlerPointer) (int); | 168 | typedef void (*SignalHandlerPointer) (int); |
168 | 169 | ||
169 | SignalHandlerPointer inthandler, termhandler; | 170 | SignalHandlerPointer inthandler, termhandler; |
170 | inthandler = signal (SIGINT, signalhandler); | 171 | inthandler = signal(SIGINT, signalhandler); |
171 | termhandler = signal (SIGTERM, signalhandler); | 172 | termhandler = signal(SIGTERM, signalhandler); |
172 | 173 | ||
173 | #ifdef DEBUG_RECORD_PURE_OGG | 174 | #ifdef DEBUG_RECORD_PURE_OGG |
174 | dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; | 175 | dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; |
175 | #endif | 176 | #endif |
176 | 177 | ||
177 | #ifdef WINDOWS | 178 | #ifdef WINDOWS |
178 | setmode (1, _O_BINARY); | 179 | setmode(1, _O_BINARY); |
179 | #endif | 180 | #endif |
180 | 181 | ||
181 | /* Initialisation */ | 182 | /* Initialisation */ |
182 | gst_init (&argc, &argv); | 183 | gst_init(&argc, &argv); |
183 | 184 | ||
184 | GNUNET_assert (GNUNET_OK == | 185 | GNUNET_assert(GNUNET_OK == |
185 | GNUNET_log_setup ("gnunet-helper-audio-record", | 186 | GNUNET_log_setup("gnunet-helper-audio-record", |
186 | "WARNING", | 187 | "WARNING", |
187 | NULL)); | 188 | NULL)); |
188 | 189 | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
190 | "Audio source starts\n"); | 191 | "Audio source starts\n"); |
191 | 192 | ||
192 | audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 193 | audio_message.header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
193 | 194 | ||
194 | /* Create gstreamer elements */ | 195 | /* Create gstreamer elements */ |
195 | pipeline = gst_pipeline_new ("audio-recorder"); | 196 | pipeline = gst_pipeline_new("audio-recorder"); |
196 | source = gst_element_factory_make ("autoaudiosrc", "audiosource"); | 197 | source = gst_element_factory_make("autoaudiosrc", "audiosource"); |
197 | filter = gst_element_factory_make ("capsfilter", "filter"); | 198 | filter = gst_element_factory_make("capsfilter", "filter"); |
198 | conv = gst_element_factory_make ("audioconvert", "converter"); | 199 | conv = gst_element_factory_make("audioconvert", "converter"); |
199 | resampler= gst_element_factory_make ("audioresample", "resampler"); | 200 | resampler = gst_element_factory_make("audioresample", "resampler"); |
200 | encoder = gst_element_factory_make ("opusenc", "opus-encoder"); | 201 | encoder = gst_element_factory_make("opusenc", "opus-encoder"); |
201 | oggmux = gst_element_factory_make ("oggmux", "ogg-muxer"); | 202 | oggmux = gst_element_factory_make("oggmux", "ogg-muxer"); |
202 | sink = gst_element_factory_make ("appsink", "audio-output"); | 203 | sink = gst_element_factory_make("appsink", "audio-output"); |
203 | 204 | ||
204 | if (!pipeline || !filter || !source || !conv || !resampler || !encoder || !oggmux || !sink) | 205 | if (!pipeline || !filter || !source || !conv || !resampler || !encoder || !oggmux || !sink) |
205 | { | 206 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 207 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
207 | "One element could not be created. Exiting.\n"); | 208 | "One element could not be created. Exiting.\n"); |
208 | return -1; | 209 | return -1; |
209 | } | 210 | } |
210 | 211 | ||
211 | g_signal_connect (source, "child-added", G_CALLBACK (source_child_added), NULL); | 212 | g_signal_connect(source, "child-added", G_CALLBACK(source_child_added), NULL); |
212 | 213 | ||
213 | /* Set up the pipeline */ | 214 | /* Set up the pipeline */ |
214 | 215 | ||
215 | caps = gst_caps_new_simple ("audio/x-raw", | 216 | caps = gst_caps_new_simple("audio/x-raw", |
216 | "format", G_TYPE_STRING, "S16LE", | 217 | "format", G_TYPE_STRING, "S16LE", |
217 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ | 218 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ |
218 | "channels", G_TYPE_INT, OPUS_CHANNELS, | 219 | "channels", G_TYPE_INT, OPUS_CHANNELS, |
219 | /* "layout", G_TYPE_STRING, "interleaved",*/ | 220 | /* "layout", G_TYPE_STRING, "interleaved",*/ |
220 | NULL); | 221 | NULL); |
221 | g_object_set (G_OBJECT (filter), | 222 | g_object_set(G_OBJECT(filter), |
222 | "caps", caps, | 223 | "caps", caps, |
223 | NULL); | 224 | NULL); |
224 | gst_caps_unref (caps); | 225 | gst_caps_unref(caps); |
225 | 226 | ||
226 | g_object_set (G_OBJECT (encoder), | 227 | g_object_set(G_OBJECT(encoder), |
227 | /* "bitrate", 64000, */ | 228 | /* "bitrate", 64000, */ |
228 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | 229 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ |
229 | "inband-fec", INBAND_FEC_MODE, | 230 | "inband-fec", INBAND_FEC_MODE, |
230 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | 231 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, |
231 | "max-payload-size", MAX_PAYLOAD_SIZE, | 232 | "max-payload-size", MAX_PAYLOAD_SIZE, |
232 | "audio", FALSE, /* VoIP, not audio */ | 233 | "audio", FALSE, /* VoIP, not audio */ |
233 | "frame-size", OPUS_FRAME_SIZE, | 234 | "frame-size", OPUS_FRAME_SIZE, |
234 | NULL); | 235 | NULL); |
235 | 236 | ||
236 | g_object_set (G_OBJECT (oggmux), | 237 | g_object_set(G_OBJECT(oggmux), |
237 | "max-delay", OGG_MAX_DELAY, | 238 | "max-delay", OGG_MAX_DELAY, |
238 | "max-page-delay", OGG_MAX_PAGE_DELAY, | 239 | "max-page-delay", OGG_MAX_PAGE_DELAY, |
239 | NULL); | 240 | NULL); |
240 | 241 | ||
241 | /* we add a message handler */ | 242 | /* we add a message handler */ |
242 | bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); | 243 | bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); |
243 | bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); | 244 | bus_watch_id = gst_bus_add_watch(bus, bus_call, pipeline); |
244 | gst_object_unref (bus); | 245 | gst_object_unref(bus); |
245 | 246 | ||
246 | /* we add all elements into the pipeline */ | 247 | /* we add all elements into the pipeline */ |
247 | /* audiosource | converter | resampler | opus-encoder | audio-output */ | 248 | /* audiosource | converter | resampler | opus-encoder | audio-output */ |
248 | gst_bin_add_many (GST_BIN (pipeline), source, filter, conv, resampler, encoder, | 249 | gst_bin_add_many(GST_BIN(pipeline), source, filter, conv, resampler, encoder, |
249 | oggmux, sink, NULL); | 250 | oggmux, sink, NULL); |
250 | 251 | ||
251 | /* we link the elements together */ | 252 | /* we link the elements together */ |
252 | gst_element_link_many (source, filter, conv, resampler, encoder, oggmux, sink, NULL); | 253 | gst_element_link_many(source, filter, conv, resampler, encoder, oggmux, sink, NULL); |
253 | 254 | ||
254 | /* Set the pipeline to "playing" state*/ | 255 | /* Set the pipeline to "playing" state*/ |
255 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); | 256 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Now playing\n"); |
256 | gst_element_set_state (pipeline, GST_STATE_PLAYING); | 257 | gst_element_set_state(pipeline, GST_STATE_PLAYING); |
257 | 258 | ||
258 | 259 | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); | 260 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running...\n"); |
260 | /* Iterate */ | 261 | /* Iterate */ |
261 | while (!abort_send) | 262 | while (!abort_send) |
262 | { | ||
263 | GstSample *s; | ||
264 | GstBuffer *b; | ||
265 | GstMapInfo m; | ||
266 | size_t len, msg_size; | ||
267 | const char *ptr; | ||
268 | int phase; | ||
269 | |||
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); | ||
271 | s = gst_app_sink_pull_sample (GST_APP_SINK (sink)); | ||
272 | if (NULL == s) | ||
273 | { | 263 | { |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); | 264 | GstSample *s; |
275 | break; | 265 | GstBuffer *b; |
276 | } | 266 | GstMapInfo m; |
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); | 267 | size_t len, msg_size; |
278 | { | 268 | const char *ptr; |
279 | const GstStructure *si; | 269 | int phase; |
280 | char *si_str; | 270 | |
281 | GstCaps *s_caps; | 271 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); |
282 | char *caps_str; | 272 | s = gst_app_sink_pull_sample(GST_APP_SINK(sink)); |
283 | si = gst_sample_get_info (s); | 273 | if (NULL == s) |
284 | if (si) | ||
285 | { | ||
286 | si_str = gst_structure_to_string (si); | ||
287 | if (si_str) | ||
288 | { | 274 | { |
289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); | 275 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); |
290 | g_free (si_str); | 276 | break; |
291 | } | 277 | } |
292 | } | 278 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); |
293 | else | ||
294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); | ||
295 | s_caps = gst_sample_get_caps (s); | ||
296 | if (s_caps) | ||
297 | { | 279 | { |
298 | caps_str = gst_caps_to_string (s_caps); | 280 | const GstStructure *si; |
299 | if (caps_str) | 281 | char *si_str; |
282 | GstCaps *s_caps; | ||
283 | char *caps_str; | ||
284 | si = gst_sample_get_info(s); | ||
285 | if (si) | ||
286 | { | ||
287 | si_str = gst_structure_to_string(si); | ||
288 | if (si_str) | ||
289 | { | ||
290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); | ||
291 | g_free(si_str); | ||
292 | } | ||
293 | } | ||
294 | else | ||
295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); | ||
296 | s_caps = gst_sample_get_caps(s); | ||
297 | if (s_caps) | ||
298 | { | ||
299 | caps_str = gst_caps_to_string(s_caps); | ||
300 | if (caps_str) | ||
301 | { | ||
302 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str); | ||
303 | g_free(caps_str); | ||
304 | } | ||
305 | } | ||
306 | else | ||
307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | ||
308 | } | ||
309 | b = gst_sample_get_buffer(s); | ||
310 | if (NULL == b || !gst_buffer_map(b, &m, GST_MAP_READ)) | ||
300 | { | 311 | { |
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str); | 312 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); |
302 | g_free (caps_str); | 313 | gst_sample_unref(s); |
314 | continue; | ||
303 | } | 315 | } |
304 | } | ||
305 | else | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | ||
307 | } | ||
308 | b = gst_sample_get_buffer (s); | ||
309 | if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) | ||
310 | { | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); | ||
312 | gst_sample_unref (s); | ||
313 | continue; | ||
314 | } | ||
315 | 316 | ||
316 | len = m.size; | 317 | len = m.size; |
317 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 318 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) |
318 | { | 319 | { |
319 | GNUNET_break (0); | 320 | GNUNET_break(0); |
320 | len = UINT16_MAX - sizeof (struct AudioMessage); | 321 | len = UINT16_MAX - sizeof(struct AudioMessage); |
321 | } | 322 | } |
322 | msg_size = sizeof (struct AudioMessage) + len; | 323 | msg_size = sizeof(struct AudioMessage) + len; |
323 | audio_message.header.size = htons ((uint16_t) msg_size); | 324 | audio_message.header.size = htons((uint16_t)msg_size); |
324 | 325 | ||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
326 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); | 327 | "Sending %u bytes of audio data\n", (unsigned int)msg_size); |
327 | for (phase = 0; phase < 2; phase++) | 328 | for (phase = 0; phase < 2; phase++) |
328 | { | 329 | { |
329 | size_t offset; | 330 | size_t offset; |
330 | size_t to_send; | 331 | size_t to_send; |
331 | ssize_t ret; | 332 | ssize_t ret; |
332 | if (0 == phase) | 333 | if (0 == phase) |
333 | { | 334 | { |
334 | #ifdef DEBUG_RECORD_PURE_OGG | 335 | #ifdef DEBUG_RECORD_PURE_OGG |
335 | if (dump_pure_ogg) | 336 | if (dump_pure_ogg) |
336 | continue; | 337 | continue; |
337 | #endif | 338 | #endif |
338 | ptr = (const char *) &audio_message; | 339 | ptr = (const char *)&audio_message; |
339 | to_send = sizeof (audio_message); | 340 | to_send = sizeof(audio_message); |
340 | } | 341 | } |
341 | else | 342 | else |
342 | { | 343 | { |
343 | ptr = (const char *) m.data; | 344 | ptr = (const char *)m.data; |
344 | to_send = len; | 345 | to_send = len; |
345 | } | 346 | } |
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
347 | "Sending %u bytes on phase %d\n", (unsigned int) to_send, phase); | 348 | "Sending %u bytes on phase %d\n", (unsigned int)to_send, phase); |
348 | for (offset = 0; offset < to_send; offset += ret) | 349 | for (offset = 0; offset < to_send; offset += ret) |
349 | { | 350 | { |
350 | ret = write (1, &ptr[offset], to_send - offset); | 351 | ret = write(1, &ptr[offset], to_send - offset); |
351 | if (0 >= ret) | 352 | if (0 >= ret) |
352 | { | 353 | { |
353 | if (-1 == ret) | 354 | if (-1 == ret) |
354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 355 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
355 | "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", | 356 | "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", |
356 | (unsigned int) (to_send - offset), | 357 | (unsigned int)(to_send - offset), |
357 | (unsigned int) offset, | 358 | (unsigned int)offset, |
358 | (unsigned int) (to_send + offset), | 359 | (unsigned int)(to_send + offset), |
359 | phase, | 360 | phase, |
360 | strerror (errno)); | 361 | strerror(errno)); |
361 | abort_send = 1; | 362 | abort_send = 1; |
362 | break; | 363 | break; |
364 | } | ||
365 | } | ||
366 | if (abort_send) | ||
367 | break; | ||
363 | } | 368 | } |
364 | } | 369 | gst_buffer_unmap(b, &m); |
365 | if (abort_send) | 370 | gst_sample_unref(s); |
366 | break; | ||
367 | } | 371 | } |
368 | gst_buffer_unmap (b, &m); | ||
369 | gst_sample_unref (s); | ||
370 | } | ||
371 | 372 | ||
372 | signal (SIGINT, inthandler); | 373 | signal(SIGINT, inthandler); |
373 | signal (SIGINT, termhandler); | 374 | signal(SIGINT, termhandler); |
374 | 375 | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); | 376 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); |
376 | quit (); | 377 | quit(); |
377 | 378 | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); | 379 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); |
379 | gst_object_unref (GST_OBJECT (pipeline)); | 380 | gst_object_unref(GST_OBJECT(pipeline)); |
380 | pipeline = NULL; | 381 | pipeline = NULL; |
381 | g_source_remove (bus_watch_id); | 382 | g_source_remove(bus_watch_id); |
382 | 383 | ||
383 | return 0; | 384 | return 0; |
384 | } | 385 | } |
diff --git a/src/conversation/gnunet-helper-audio-record.c b/src/conversation/gnunet-helper-audio-record.c index f3f51e681..0cfc04578 100644 --- a/src/conversation/gnunet-helper-audio-record.c +++ b/src/conversation/gnunet-helper-audio-record.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-helper-audio-record.c | 21 | * @file conversation/gnunet-helper-audio-record.c |
22 | * @brief program to record audio data from the microphone | 22 | * @brief program to record audio data from the microphone |
@@ -149,8 +149,7 @@ static pa_sample_spec sample_spec = { | |||
149 | GNUNET_NETWORK_STRUCT_BEGIN | 149 | GNUNET_NETWORK_STRUCT_BEGIN |
150 | 150 | ||
151 | /* OggOpus spec says the numbers must be in little-endian order */ | 151 | /* OggOpus spec says the numbers must be in little-endian order */ |
152 | struct OpusHeadPacket | 152 | struct OpusHeadPacket { |
153 | { | ||
154 | uint8_t magic[8]; | 153 | uint8_t magic[8]; |
155 | uint8_t version; | 154 | uint8_t version; |
156 | uint8_t channels; | 155 | uint8_t channels; |
@@ -160,8 +159,7 @@ struct OpusHeadPacket | |||
160 | uint8_t channel_mapping; | 159 | uint8_t channel_mapping; |
161 | }; | 160 | }; |
162 | 161 | ||
163 | struct OpusCommentsPacket | 162 | struct OpusCommentsPacket { |
164 | { | ||
165 | uint8_t magic[8]; | 163 | uint8_t magic[8]; |
166 | uint32_t vendor_length; | 164 | uint32_t vendor_length; |
167 | /* followed by: | 165 | /* followed by: |
@@ -267,61 +265,63 @@ static int dump_pure_ogg; | |||
267 | * Pulseaudio shutdown task | 265 | * Pulseaudio shutdown task |
268 | */ | 266 | */ |
269 | static void | 267 | static void |
270 | quit (int ret) | 268 | quit(int ret) |
271 | { | 269 | { |
272 | mainloop_api->quit (mainloop_api, | 270 | mainloop_api->quit(mainloop_api, |
273 | ret); | 271 | ret); |
274 | exit (ret); | 272 | exit(ret); |
275 | } | 273 | } |
276 | 274 | ||
277 | 275 | ||
278 | static void | 276 | static void |
279 | write_data (const char *ptr, | 277 | write_data(const char *ptr, |
280 | size_t msg_size) | 278 | size_t msg_size) |
281 | { | 279 | { |
282 | ssize_t ret; | 280 | ssize_t ret; |
283 | size_t off; | 281 | size_t off; |
282 | |||
284 | off = 0; | 283 | off = 0; |
285 | while (off < msg_size) | 284 | while (off < msg_size) |
286 | { | ||
287 | ret = write (STDOUT_FILENO, | ||
288 | &ptr[off], | ||
289 | msg_size - off); | ||
290 | if (0 >= ret) | ||
291 | { | 285 | { |
292 | if (-1 == ret) | 286 | ret = write(STDOUT_FILENO, |
293 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 287 | &ptr[off], |
294 | "write"); | 288 | msg_size - off); |
295 | quit (2); | 289 | if (0 >= ret) |
290 | { | ||
291 | if (-1 == ret) | ||
292 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | ||
293 | "write"); | ||
294 | quit(2); | ||
295 | } | ||
296 | off += ret; | ||
296 | } | 297 | } |
297 | off += ret; | ||
298 | } | ||
299 | } | 298 | } |
300 | 299 | ||
301 | 300 | ||
302 | static void | 301 | static void |
303 | write_page (ogg_page *og) | 302 | write_page(ogg_page *og) |
304 | { | 303 | { |
305 | static unsigned long long toff; | 304 | static unsigned long long toff; |
306 | size_t msg_size; | 305 | size_t msg_size; |
307 | msg_size = sizeof (struct AudioMessage) + og->header_len + og->body_len; | 306 | |
308 | audio_message->header.size = htons ((uint16_t) msg_size); | 307 | msg_size = sizeof(struct AudioMessage) + og->header_len + og->body_len; |
309 | GNUNET_memcpy (&audio_message[1], og->header, og->header_len); | 308 | audio_message->header.size = htons((uint16_t)msg_size); |
310 | GNUNET_memcpy (((char *) &audio_message[1]) + og->header_len, og->body, og->body_len); | 309 | GNUNET_memcpy(&audio_message[1], og->header, og->header_len); |
310 | GNUNET_memcpy(((char *)&audio_message[1]) + og->header_len, og->body, og->body_len); | ||
311 | 311 | ||
312 | toff += msg_size; | 312 | toff += msg_size; |
313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
314 | "Sending %u bytes of audio data (total: %llu)\n", | 314 | "Sending %u bytes of audio data (total: %llu)\n", |
315 | (unsigned int) msg_size, | 315 | (unsigned int)msg_size, |
316 | toff); | 316 | toff); |
317 | #ifdef DEBUG_RECORD_PURE_OGG | 317 | #ifdef DEBUG_RECORD_PURE_OGG |
318 | if (dump_pure_ogg) | 318 | if (dump_pure_ogg) |
319 | write_data ((const char *) &audio_message[1], | 319 | write_data((const char *)&audio_message[1], |
320 | og->header_len + og->body_len); | 320 | og->header_len + og->body_len); |
321 | else | 321 | else |
322 | #endif | 322 | #endif |
323 | write_data ((const char *) audio_message, | 323 | write_data((const char *)audio_message, |
324 | msg_size); | 324 | msg_size); |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
@@ -329,7 +329,7 @@ write_page (ogg_page *og) | |||
329 | * Creates OPUS packets from PCM data | 329 | * Creates OPUS packets from PCM data |
330 | */ | 330 | */ |
331 | static void | 331 | static void |
332 | packetizer () | 332 | packetizer() |
333 | { | 333 | { |
334 | char *nbuf; | 334 | char *nbuf; |
335 | size_t new_size; | 335 | size_t new_size; |
@@ -338,68 +338,68 @@ packetizer () | |||
338 | ogg_page og; | 338 | ogg_page og; |
339 | 339 | ||
340 | while (transmit_buffer_length >= transmit_buffer_index + pcm_length) | 340 | while (transmit_buffer_length >= transmit_buffer_index + pcm_length) |
341 | { | ||
342 | GNUNET_memcpy (pcm_buffer, | ||
343 | &transmit_buffer[transmit_buffer_index], | ||
344 | pcm_length); | ||
345 | transmit_buffer_index += pcm_length; | ||
346 | len = | ||
347 | opus_encode_float (enc, pcm_buffer, FRAME_SIZE, opus_data, | ||
348 | MAX_PAYLOAD_BYTES); | ||
349 | |||
350 | if (len < 0) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
353 | _("opus_encode_float() failed: %s. Aborting\n"), | ||
354 | opus_strerror (len)); | ||
355 | quit (5); | ||
356 | } | ||
357 | if (((uint32_t)len) > UINT16_MAX - sizeof (struct AudioMessage)) | ||
358 | { | ||
359 | GNUNET_break (0); | ||
360 | continue; | ||
361 | } | ||
362 | |||
363 | /* As per OggOpus spec, granule is calculated as if the audio | ||
364 | had 48kHz sampling rate. */ | ||
365 | enc_granulepos += FRAME_SIZE * 48000 / SAMPLING_RATE; | ||
366 | |||
367 | op.packet = (unsigned char *) opus_data; | ||
368 | op.bytes = len; | ||
369 | op.b_o_s = 0; | ||
370 | op.e_o_s = 0; | ||
371 | op.granulepos = enc_granulepos; | ||
372 | op.packetno = packet_id++; | ||
373 | ogg_stream_packetin (&os, &op); | ||
374 | |||
375 | while (ogg_stream_flush_fill (&os, &og, PAGE_WATERLINE)) | ||
376 | { | 341 | { |
377 | if ( ((unsigned long long) og.header_len) + | 342 | GNUNET_memcpy(pcm_buffer, |
378 | ((unsigned long long) og.body_len) > | 343 | &transmit_buffer[transmit_buffer_index], |
379 | UINT16_MAX - sizeof (struct AudioMessage)) | 344 | pcm_length); |
380 | { | 345 | transmit_buffer_index += pcm_length; |
381 | GNUNET_assert (0); | 346 | len = |
382 | continue; | 347 | opus_encode_float(enc, pcm_buffer, FRAME_SIZE, opus_data, |
383 | } | 348 | MAX_PAYLOAD_BYTES); |
384 | write_page (&og); | 349 | |
350 | if (len < 0) | ||
351 | { | ||
352 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
353 | _("opus_encode_float() failed: %s. Aborting\n"), | ||
354 | opus_strerror(len)); | ||
355 | quit(5); | ||
356 | } | ||
357 | if (((uint32_t)len) > UINT16_MAX - sizeof(struct AudioMessage)) | ||
358 | { | ||
359 | GNUNET_break(0); | ||
360 | continue; | ||
361 | } | ||
362 | |||
363 | /* As per OggOpus spec, granule is calculated as if the audio | ||
364 | had 48kHz sampling rate. */ | ||
365 | enc_granulepos += FRAME_SIZE * 48000 / SAMPLING_RATE; | ||
366 | |||
367 | op.packet = (unsigned char *)opus_data; | ||
368 | op.bytes = len; | ||
369 | op.b_o_s = 0; | ||
370 | op.e_o_s = 0; | ||
371 | op.granulepos = enc_granulepos; | ||
372 | op.packetno = packet_id++; | ||
373 | ogg_stream_packetin(&os, &op); | ||
374 | |||
375 | while (ogg_stream_flush_fill(&os, &og, PAGE_WATERLINE)) | ||
376 | { | ||
377 | if (((unsigned long long)og.header_len) + | ||
378 | ((unsigned long long)og.body_len) > | ||
379 | UINT16_MAX - sizeof(struct AudioMessage)) | ||
380 | { | ||
381 | GNUNET_assert(0); | ||
382 | continue; | ||
383 | } | ||
384 | write_page(&og); | ||
385 | } | ||
385 | } | 386 | } |
386 | } | ||
387 | 387 | ||
388 | new_size = transmit_buffer_length - transmit_buffer_index; | 388 | new_size = transmit_buffer_length - transmit_buffer_index; |
389 | if (0 != new_size) | 389 | if (0 != new_size) |
390 | { | 390 | { |
391 | nbuf = pa_xmalloc (new_size); | 391 | nbuf = pa_xmalloc(new_size); |
392 | memmove (nbuf, | 392 | memmove(nbuf, |
393 | &transmit_buffer[transmit_buffer_index], | 393 | &transmit_buffer[transmit_buffer_index], |
394 | new_size); | 394 | new_size); |
395 | pa_xfree (transmit_buffer); | 395 | pa_xfree(transmit_buffer); |
396 | transmit_buffer = nbuf; | 396 | transmit_buffer = nbuf; |
397 | } | 397 | } |
398 | else | 398 | else |
399 | { | 399 | { |
400 | pa_xfree (transmit_buffer); | 400 | pa_xfree(transmit_buffer); |
401 | transmit_buffer = NULL; | 401 | transmit_buffer = NULL; |
402 | } | 402 | } |
403 | transmit_buffer_index = 0; | 403 | transmit_buffer_index = 0; |
404 | transmit_buffer_length = new_size; | 404 | transmit_buffer_length = new_size; |
405 | } | 405 | } |
@@ -409,51 +409,51 @@ packetizer () | |||
409 | * Pulseaudio callback when new data is available. | 409 | * Pulseaudio callback when new data is available. |
410 | */ | 410 | */ |
411 | static void | 411 | static void |
412 | stream_read_callback (pa_stream * s, | 412 | stream_read_callback(pa_stream * s, |
413 | size_t length, | 413 | size_t length, |
414 | void *userdata) | 414 | void *userdata) |
415 | { | 415 | { |
416 | const void *data; | 416 | const void *data; |
417 | 417 | ||
418 | (void) userdata; | 418 | (void)userdata; |
419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
420 | "Got %u/%d bytes of PCM data\n", | 420 | "Got %u/%d bytes of PCM data\n", |
421 | (unsigned int) length, | 421 | (unsigned int)length, |
422 | pcm_length); | 422 | pcm_length); |
423 | 423 | ||
424 | GNUNET_assert (NULL != s); | 424 | GNUNET_assert(NULL != s); |
425 | GNUNET_assert (length > 0); | 425 | GNUNET_assert(length > 0); |
426 | if (stdio_event) | 426 | if (stdio_event) |
427 | mainloop_api->io_enable (stdio_event, PA_IO_EVENT_OUTPUT); | 427 | mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT); |
428 | 428 | ||
429 | if (pa_stream_peek (s, (const void **) &data, &length) < 0) | 429 | if (pa_stream_peek(s, (const void **)&data, &length) < 0) |
430 | { | 430 | { |
431 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 431 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
432 | _("pa_stream_peek() failed: %s\n"), | 432 | _("pa_stream_peek() failed: %s\n"), |
433 | pa_strerror (pa_context_errno (context))); | 433 | pa_strerror(pa_context_errno(context))); |
434 | quit (1); | 434 | quit(1); |
435 | return; | 435 | return; |
436 | } | 436 | } |
437 | GNUNET_assert (NULL != data); | 437 | GNUNET_assert(NULL != data); |
438 | GNUNET_assert (length > 0); | 438 | GNUNET_assert(length > 0); |
439 | if (NULL != transmit_buffer) | 439 | if (NULL != transmit_buffer) |
440 | { | 440 | { |
441 | transmit_buffer = pa_xrealloc (transmit_buffer, | 441 | transmit_buffer = pa_xrealloc(transmit_buffer, |
442 | transmit_buffer_length + length); | 442 | transmit_buffer_length + length); |
443 | GNUNET_memcpy (&transmit_buffer[transmit_buffer_length], | 443 | GNUNET_memcpy(&transmit_buffer[transmit_buffer_length], |
444 | data, | 444 | data, |
445 | length); | 445 | length); |
446 | transmit_buffer_length += length; | 446 | transmit_buffer_length += length; |
447 | } | 447 | } |
448 | else | 448 | else |
449 | { | 449 | { |
450 | transmit_buffer = pa_xmalloc (length); | 450 | transmit_buffer = pa_xmalloc(length); |
451 | GNUNET_memcpy (transmit_buffer, data, length); | 451 | GNUNET_memcpy(transmit_buffer, data, length); |
452 | transmit_buffer_length = length; | 452 | transmit_buffer_length = length; |
453 | transmit_buffer_index = 0; | 453 | transmit_buffer_index = 0; |
454 | } | 454 | } |
455 | pa_stream_drop (s); | 455 | pa_stream_drop(s); |
456 | packetizer (); | 456 | packetizer(); |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||
@@ -461,18 +461,18 @@ stream_read_callback (pa_stream * s, | |||
461 | * Exit callback for SIGTERM and SIGINT | 461 | * Exit callback for SIGTERM and SIGINT |
462 | */ | 462 | */ |
463 | static void | 463 | static void |
464 | exit_signal_callback (pa_mainloop_api * m, | 464 | exit_signal_callback(pa_mainloop_api * m, |
465 | pa_signal_event * e, | 465 | pa_signal_event * e, |
466 | int sig, | 466 | int sig, |
467 | void *userdata) | 467 | void *userdata) |
468 | { | 468 | { |
469 | (void) m; | 469 | (void)m; |
470 | (void) e; | 470 | (void)e; |
471 | (void) sig; | 471 | (void)sig; |
472 | (void) userdata; | 472 | (void)userdata; |
473 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 473 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
474 | _("Got signal, exiting.\n")); | 474 | _("Got signal, exiting.\n")); |
475 | quit (1); | 475 | quit(1); |
476 | } | 476 | } |
477 | 477 | ||
478 | 478 | ||
@@ -480,60 +480,61 @@ exit_signal_callback (pa_mainloop_api * m, | |||
480 | * Pulseaudio stream state callback | 480 | * Pulseaudio stream state callback |
481 | */ | 481 | */ |
482 | static void | 482 | static void |
483 | stream_state_callback (pa_stream * s, | 483 | stream_state_callback(pa_stream * s, |
484 | void *userdata) | 484 | void *userdata) |
485 | { | 485 | { |
486 | (void) userdata; | 486 | (void)userdata; |
487 | GNUNET_assert (NULL != s); | 487 | GNUNET_assert(NULL != s); |
488 | switch (pa_stream_get_state (s)) | 488 | switch (pa_stream_get_state(s)) |
489 | { | 489 | { |
490 | case PA_STREAM_CREATING: | 490 | case PA_STREAM_CREATING: |
491 | case PA_STREAM_TERMINATED: | 491 | case PA_STREAM_TERMINATED: |
492 | break; | 492 | break; |
493 | case PA_STREAM_READY: | 493 | |
494 | case PA_STREAM_READY: | ||
494 | { | 495 | { |
495 | const pa_buffer_attr *a; | 496 | const pa_buffer_attr *a; |
496 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX]; | 497 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX]; |
497 | char sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; | 498 | char sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; |
498 | 499 | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 500 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
500 | _("Stream successfully created.\n")); | 501 | _("Stream successfully created.\n")); |
501 | 502 | ||
502 | if (!(a = pa_stream_get_buffer_attr (s))) | 503 | if (!(a = pa_stream_get_buffer_attr(s))) |
503 | { | 504 | { |
504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 505 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
505 | _("pa_stream_get_buffer_attr() failed: %s\n"), | 506 | _("pa_stream_get_buffer_attr() failed: %s\n"), |
506 | pa_strerror (pa_context_errno | 507 | pa_strerror(pa_context_errno |
507 | (pa_stream_get_context (s)))); | 508 | (pa_stream_get_context(s)))); |
508 | 509 | } | |
509 | } | ||
510 | else | 510 | else |
511 | { | 511 | { |
512 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 512 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
513 | _("Buffer metrics: maxlength=%u, fragsize=%u\n"), | 513 | _("Buffer metrics: maxlength=%u, fragsize=%u\n"), |
514 | a->maxlength, a->fragsize); | 514 | a->maxlength, a->fragsize); |
515 | } | 515 | } |
516 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 516 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
517 | _("Using sample spec '%s', channel map '%s'.\n"), | 517 | _("Using sample spec '%s', channel map '%s'.\n"), |
518 | pa_sample_spec_snprint (sst, sizeof (sst), | 518 | pa_sample_spec_snprint(sst, sizeof(sst), |
519 | pa_stream_get_sample_spec (s)), | 519 | pa_stream_get_sample_spec(s)), |
520 | pa_channel_map_snprint (cmt, sizeof (cmt), | 520 | pa_channel_map_snprint(cmt, sizeof(cmt), |
521 | pa_stream_get_channel_map (s))); | 521 | pa_stream_get_channel_map(s))); |
522 | 522 | ||
523 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
524 | _("Connected to device %s (%u, %ssuspended).\n"), | 524 | _("Connected to device %s (%u, %ssuspended).\n"), |
525 | pa_stream_get_device_name (s), | 525 | pa_stream_get_device_name(s), |
526 | pa_stream_get_device_index (s), | 526 | pa_stream_get_device_index(s), |
527 | pa_stream_is_suspended (s) ? "" : "not "); | 527 | pa_stream_is_suspended(s) ? "" : "not "); |
528 | } | 528 | } |
529 | break; | 529 | break; |
530 | case PA_STREAM_FAILED: | 530 | |
531 | default: | 531 | case PA_STREAM_FAILED: |
532 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 532 | default: |
533 | _("Stream error: %s\n"), | 533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
534 | pa_strerror (pa_context_errno (pa_stream_get_context (s)))); | 534 | _("Stream error: %s\n"), |
535 | quit (1); | 535 | pa_strerror(pa_context_errno(pa_stream_get_context(s)))); |
536 | } | 536 | quit(1); |
537 | } | ||
537 | } | 538 | } |
538 | 539 | ||
539 | 540 | ||
@@ -541,64 +542,67 @@ stream_state_callback (pa_stream * s, | |||
541 | * Pulseaudio context state callback | 542 | * Pulseaudio context state callback |
542 | */ | 543 | */ |
543 | static void | 544 | static void |
544 | context_state_callback (pa_context * c, | 545 | context_state_callback(pa_context * c, |
545 | void *userdata) | 546 | void *userdata) |
546 | { | 547 | { |
547 | (void) userdata; | 548 | (void)userdata; |
548 | GNUNET_assert (c); | 549 | GNUNET_assert(c); |
549 | 550 | ||
550 | switch (pa_context_get_state (c)) | 551 | switch (pa_context_get_state(c)) |
551 | { | ||
552 | case PA_CONTEXT_CONNECTING: | ||
553 | case PA_CONTEXT_AUTHORIZING: | ||
554 | case PA_CONTEXT_SETTING_NAME: | ||
555 | break; | ||
556 | case PA_CONTEXT_READY: | ||
557 | { | ||
558 | int r; | ||
559 | pa_buffer_attr na; | ||
560 | |||
561 | GNUNET_assert (!stream_in); | ||
562 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
563 | _("Connection established.\n")); | ||
564 | if (! (stream_in = | ||
565 | pa_stream_new (c, "GNUNET_VoIP recorder", &sample_spec, NULL))) | ||
566 | { | 552 | { |
567 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 553 | case PA_CONTEXT_CONNECTING: |
568 | _("pa_stream_new() failed: %s\n"), | 554 | case PA_CONTEXT_AUTHORIZING: |
569 | pa_strerror (pa_context_errno (c))); | 555 | case PA_CONTEXT_SETTING_NAME: |
570 | goto fail; | 556 | break; |
571 | } | 557 | |
572 | pa_stream_set_state_callback (stream_in, &stream_state_callback, NULL); | 558 | case PA_CONTEXT_READY: |
573 | pa_stream_set_read_callback (stream_in, &stream_read_callback, NULL); | ||
574 | memset (&na, 0, sizeof (na)); | ||
575 | na.maxlength = UINT32_MAX; | ||
576 | na.fragsize = pcm_length; | ||
577 | if ((r = pa_stream_connect_record (stream_in, NULL, &na, | ||
578 | PA_STREAM_ADJUST_LATENCY)) < 0) | ||
579 | { | 559 | { |
580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 560 | int r; |
581 | _("pa_stream_connect_record() failed: %s\n"), | 561 | pa_buffer_attr na; |
582 | pa_strerror (pa_context_errno (c))); | 562 | |
583 | goto fail; | 563 | GNUNET_assert(!stream_in); |
564 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
565 | _("Connection established.\n")); | ||
566 | if (!(stream_in = | ||
567 | pa_stream_new(c, "GNUNET_VoIP recorder", &sample_spec, NULL))) | ||
568 | { | ||
569 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
570 | _("pa_stream_new() failed: %s\n"), | ||
571 | pa_strerror(pa_context_errno(c))); | ||
572 | goto fail; | ||
573 | } | ||
574 | pa_stream_set_state_callback(stream_in, &stream_state_callback, NULL); | ||
575 | pa_stream_set_read_callback(stream_in, &stream_read_callback, NULL); | ||
576 | memset(&na, 0, sizeof(na)); | ||
577 | na.maxlength = UINT32_MAX; | ||
578 | na.fragsize = pcm_length; | ||
579 | if ((r = pa_stream_connect_record(stream_in, NULL, &na, | ||
580 | PA_STREAM_ADJUST_LATENCY)) < 0) | ||
581 | { | ||
582 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
583 | _("pa_stream_connect_record() failed: %s\n"), | ||
584 | pa_strerror(pa_context_errno(c))); | ||
585 | goto fail; | ||
586 | } | ||
587 | |||
588 | break; | ||
584 | } | 589 | } |
585 | 590 | ||
586 | break; | 591 | case PA_CONTEXT_TERMINATED: |
587 | } | 592 | quit(0); |
588 | case PA_CONTEXT_TERMINATED: | 593 | break; |
589 | quit (0); | 594 | |
590 | break; | 595 | case PA_CONTEXT_FAILED: |
591 | case PA_CONTEXT_FAILED: | 596 | default: |
592 | default: | 597 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
593 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 598 | _("Connection failure: %s\n"), |
594 | _("Connection failure: %s\n"), | 599 | pa_strerror(pa_context_errno(c))); |
595 | pa_strerror (pa_context_errno (c))); | 600 | goto fail; |
596 | goto fail; | 601 | } |
597 | } | ||
598 | return; | 602 | return; |
599 | 603 | ||
600 | fail: | 604 | fail: |
601 | quit (1); | 605 | quit(1); |
602 | } | 606 | } |
603 | 607 | ||
604 | 608 | ||
@@ -606,49 +610,49 @@ fail: | |||
606 | * Pulsaudio init | 610 | * Pulsaudio init |
607 | */ | 611 | */ |
608 | static void | 612 | static void |
609 | pa_init () | 613 | pa_init() |
610 | { | 614 | { |
611 | int r; | 615 | int r; |
612 | int i; | 616 | int i; |
613 | 617 | ||
614 | if (!pa_sample_spec_valid (&sample_spec)) | 618 | if (!pa_sample_spec_valid(&sample_spec)) |
615 | { | 619 | { |
616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 620 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
617 | _("Wrong Spec\n")); | 621 | _("Wrong Spec\n")); |
618 | } | 622 | } |
619 | /* set up main record loop */ | 623 | /* set up main record loop */ |
620 | if (!(m = pa_mainloop_new ())) | 624 | if (!(m = pa_mainloop_new())) |
621 | { | 625 | { |
622 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 626 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
623 | _("pa_mainloop_new() failed.\n")); | 627 | _("pa_mainloop_new() failed.\n")); |
624 | } | 628 | } |
625 | mainloop_api = pa_mainloop_get_api (m); | 629 | mainloop_api = pa_mainloop_get_api(m); |
626 | 630 | ||
627 | /* listen to signals */ | 631 | /* listen to signals */ |
628 | r = pa_signal_init (mainloop_api); | 632 | r = pa_signal_init(mainloop_api); |
629 | GNUNET_assert (r == 0); | 633 | GNUNET_assert(r == 0); |
630 | pa_signal_new (SIGINT, &exit_signal_callback, NULL); | 634 | pa_signal_new(SIGINT, &exit_signal_callback, NULL); |
631 | pa_signal_new (SIGTERM, &exit_signal_callback, NULL); | 635 | pa_signal_new(SIGTERM, &exit_signal_callback, NULL); |
632 | 636 | ||
633 | /* connect to the main pulseaudio context */ | 637 | /* connect to the main pulseaudio context */ |
634 | 638 | ||
635 | if (!(context = pa_context_new (mainloop_api, "GNUNET VoIP"))) | 639 | if (!(context = pa_context_new(mainloop_api, "GNUNET VoIP"))) |
636 | { | 640 | { |
637 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 641 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
638 | _("pa_context_new() failed.\n")); | 642 | _("pa_context_new() failed.\n")); |
639 | } | 643 | } |
640 | pa_context_set_state_callback (context, &context_state_callback, NULL); | 644 | pa_context_set_state_callback(context, &context_state_callback, NULL); |
641 | if (pa_context_connect (context, NULL, 0, NULL) < 0) | 645 | if (pa_context_connect(context, NULL, 0, NULL) < 0) |
642 | { | 646 | { |
643 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 647 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
644 | _("pa_context_connect() failed: %s\n"), | 648 | _("pa_context_connect() failed: %s\n"), |
645 | pa_strerror (pa_context_errno (context))); | 649 | pa_strerror(pa_context_errno(context))); |
646 | } | 650 | } |
647 | if (pa_mainloop_run (m, &i) < 0) | 651 | if (pa_mainloop_run(m, &i) < 0) |
648 | { | 652 | { |
649 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 653 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
650 | _("pa_mainloop_run() failed.\n")); | 654 | _("pa_mainloop_run() failed.\n")); |
651 | } | 655 | } |
652 | } | 656 | } |
653 | 657 | ||
654 | 658 | ||
@@ -656,45 +660,45 @@ pa_init () | |||
656 | * OPUS init | 660 | * OPUS init |
657 | */ | 661 | */ |
658 | static void | 662 | static void |
659 | opus_init () | 663 | opus_init() |
660 | { | 664 | { |
661 | int err; | 665 | int err; |
662 | 666 | ||
663 | pcm_length = FRAME_SIZE * CHANNELS * sizeof (float); | 667 | pcm_length = FRAME_SIZE * CHANNELS * sizeof(float); |
664 | pcm_buffer = pa_xmalloc (pcm_length); | 668 | pcm_buffer = pa_xmalloc(pcm_length); |
665 | opus_data = GNUNET_malloc (MAX_PAYLOAD_BYTES); | 669 | opus_data = GNUNET_malloc(MAX_PAYLOAD_BYTES); |
666 | enc = opus_encoder_create (SAMPLING_RATE, | 670 | enc = opus_encoder_create(SAMPLING_RATE, |
667 | CHANNELS, | 671 | CHANNELS, |
668 | CONV_OPUS_APP_TYPE, | 672 | CONV_OPUS_APP_TYPE, |
669 | &err); | 673 | &err); |
670 | opus_encoder_ctl (enc, | 674 | opus_encoder_ctl(enc, |
671 | OPUS_SET_PACKET_LOSS_PERC (CONV_OPUS_PACKET_LOSS_PERCENTAGE)); | 675 | OPUS_SET_PACKET_LOSS_PERC(CONV_OPUS_PACKET_LOSS_PERCENTAGE)); |
672 | opus_encoder_ctl (enc, | 676 | opus_encoder_ctl(enc, |
673 | OPUS_SET_COMPLEXITY (CONV_OPUS_ENCODING_COMPLEXITY)); | 677 | OPUS_SET_COMPLEXITY(CONV_OPUS_ENCODING_COMPLEXITY)); |
674 | opus_encoder_ctl (enc, | 678 | opus_encoder_ctl(enc, |
675 | OPUS_SET_INBAND_FEC (CONV_OPUS_INBAND_FEC)); | 679 | OPUS_SET_INBAND_FEC(CONV_OPUS_INBAND_FEC)); |
676 | opus_encoder_ctl (enc, | 680 | opus_encoder_ctl(enc, |
677 | OPUS_SET_SIGNAL (CONV_OPUS_SIGNAL)); | 681 | OPUS_SET_SIGNAL(CONV_OPUS_SIGNAL)); |
678 | } | 682 | } |
679 | 683 | ||
680 | 684 | ||
681 | static void | 685 | static void |
682 | ogg_init () | 686 | ogg_init() |
683 | { | 687 | { |
684 | int serialno; | 688 | int serialno; |
685 | struct OpusHeadPacket headpacket; | 689 | struct OpusHeadPacket headpacket; |
686 | struct OpusCommentsPacket *commentspacket; | 690 | struct OpusCommentsPacket *commentspacket; |
687 | size_t commentspacket_len; | 691 | size_t commentspacket_len; |
688 | 692 | ||
689 | serialno = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 693 | serialno = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, |
690 | 0x7FFFFFFF); | 694 | 0x7FFFFFFF); |
691 | /*Initialize Ogg stream struct*/ | 695 | /*Initialize Ogg stream struct*/ |
692 | if (-1 == ogg_stream_init (&os, serialno)) | 696 | if (-1 == ogg_stream_init(&os, serialno)) |
693 | { | 697 | { |
694 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 698 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
695 | _("ogg_stream_init() failed.\n")); | 699 | _("ogg_stream_init() failed.\n")); |
696 | exit (3); | 700 | exit(3); |
697 | } | 701 | } |
698 | 702 | ||
699 | packet_id = 0; | 703 | packet_id = 0; |
700 | 704 | ||
@@ -705,64 +709,64 @@ ogg_init () | |||
705 | const char *opusver; | 709 | const char *opusver; |
706 | int vendor_length; | 710 | int vendor_length; |
707 | 711 | ||
708 | GNUNET_memcpy (headpacket.magic, "OpusHead", 8); | 712 | GNUNET_memcpy(headpacket.magic, "OpusHead", 8); |
709 | headpacket.version = 1; | 713 | headpacket.version = 1; |
710 | headpacket.channels = CHANNELS; | 714 | headpacket.channels = CHANNELS; |
711 | headpacket.preskip = GNUNET_htole16 (0); | 715 | headpacket.preskip = GNUNET_htole16(0); |
712 | headpacket.sampling_rate = GNUNET_htole32 (SAMPLING_RATE); | 716 | headpacket.sampling_rate = GNUNET_htole32(SAMPLING_RATE); |
713 | headpacket.gain = GNUNET_htole16 (0); | 717 | headpacket.gain = GNUNET_htole16(0); |
714 | headpacket.channel_mapping = 0; /* Mono or stereo */ | 718 | headpacket.channel_mapping = 0; /* Mono or stereo */ |
715 | 719 | ||
716 | op.packet = (unsigned char *) &headpacket; | 720 | op.packet = (unsigned char *)&headpacket; |
717 | op.bytes = sizeof (headpacket); | 721 | op.bytes = sizeof(headpacket); |
718 | op.b_o_s = 1; | 722 | op.b_o_s = 1; |
719 | op.e_o_s = 0; | 723 | op.e_o_s = 0; |
720 | op.granulepos = 0; | 724 | op.granulepos = 0; |
721 | op.packetno = packet_id++; | 725 | op.packetno = packet_id++; |
722 | ogg_stream_packetin (&os, &op); | 726 | ogg_stream_packetin(&os, &op); |
723 | 727 | ||
724 | /* Head packet must be alone on its page */ | 728 | /* Head packet must be alone on its page */ |
725 | while (ogg_stream_flush (&os, &og)) | 729 | while (ogg_stream_flush(&os, &og)) |
726 | { | 730 | { |
727 | write_page (&og); | 731 | write_page(&og); |
728 | } | 732 | } |
729 | 733 | ||
730 | commentspacket_len = sizeof (*commentspacket); | 734 | commentspacket_len = sizeof(*commentspacket); |
731 | opusver = opus_get_version_string (); | 735 | opusver = opus_get_version_string(); |
732 | vendor_length = strlen (opusver); | 736 | vendor_length = strlen(opusver); |
733 | commentspacket_len += vendor_length; | 737 | commentspacket_len += vendor_length; |
734 | commentspacket_len += sizeof (uint32_t); | 738 | commentspacket_len += sizeof(uint32_t); |
735 | 739 | ||
736 | commentspacket = (struct OpusCommentsPacket *) malloc (commentspacket_len); | 740 | commentspacket = (struct OpusCommentsPacket *)malloc(commentspacket_len); |
737 | if (NULL == commentspacket) | 741 | if (NULL == commentspacket) |
738 | { | 742 | { |
739 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 743 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
740 | _("Failed to allocate %u bytes for second packet\n"), | 744 | _("Failed to allocate %u bytes for second packet\n"), |
741 | (unsigned int) commentspacket_len); | 745 | (unsigned int)commentspacket_len); |
742 | exit (5); | 746 | exit(5); |
743 | } | 747 | } |
744 | 748 | ||
745 | GNUNET_memcpy (commentspacket->magic, "OpusTags", 8); | 749 | GNUNET_memcpy(commentspacket->magic, "OpusTags", 8); |
746 | commentspacket->vendor_length = GNUNET_htole32 (vendor_length); | 750 | commentspacket->vendor_length = GNUNET_htole32(vendor_length); |
747 | GNUNET_memcpy (&commentspacket[1], opusver, vendor_length); | 751 | GNUNET_memcpy(&commentspacket[1], opusver, vendor_length); |
748 | *(uint32_t *) &((char *) &commentspacket[1])[vendor_length] = \ | 752 | *(uint32_t *)&((char *)&commentspacket[1])[vendor_length] = \ |
749 | GNUNET_htole32 (0); /* no tags */ | 753 | GNUNET_htole32(0); /* no tags */ |
750 | 754 | ||
751 | op.packet = (unsigned char *) commentspacket; | 755 | op.packet = (unsigned char *)commentspacket; |
752 | op.bytes = commentspacket_len; | 756 | op.bytes = commentspacket_len; |
753 | op.b_o_s = 0; | 757 | op.b_o_s = 0; |
754 | op.e_o_s = 0; | 758 | op.e_o_s = 0; |
755 | op.granulepos = 0; | 759 | op.granulepos = 0; |
756 | op.packetno = packet_id++; | 760 | op.packetno = packet_id++; |
757 | ogg_stream_packetin (&os, &op); | 761 | ogg_stream_packetin(&os, &op); |
758 | 762 | ||
759 | /* Comment packets must not be mixed with audio packets on their pages */ | 763 | /* Comment packets must not be mixed with audio packets on their pages */ |
760 | while (ogg_stream_flush (&os, &og)) | 764 | while (ogg_stream_flush(&os, &og)) |
761 | { | 765 | { |
762 | write_page (&og); | 766 | write_page(&og); |
763 | } | 767 | } |
764 | 768 | ||
765 | free (commentspacket); | 769 | free(commentspacket); |
766 | } | 770 | } |
767 | } | 771 | } |
768 | 772 | ||
@@ -774,25 +778,25 @@ ogg_init () | |||
774 | * @return 0 ok, 1 on error | 778 | * @return 0 ok, 1 on error |
775 | */ | 779 | */ |
776 | int | 780 | int |
777 | main (int argc, | 781 | main(int argc, |
778 | char *argv[]) | 782 | char *argv[]) |
779 | { | 783 | { |
780 | (void) argc; | 784 | (void)argc; |
781 | (void) argv; | 785 | (void)argv; |
782 | GNUNET_assert (GNUNET_OK == | 786 | GNUNET_assert(GNUNET_OK == |
783 | GNUNET_log_setup ("gnunet-helper-audio-record", | 787 | GNUNET_log_setup("gnunet-helper-audio-record", |
784 | "WARNING", | 788 | "WARNING", |
785 | NULL)); | 789 | NULL)); |
786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 790 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
787 | "Audio source starts\n"); | 791 | "Audio source starts\n"); |
788 | audio_message = GNUNET_malloc (UINT16_MAX); | 792 | audio_message = GNUNET_malloc(UINT16_MAX); |
789 | audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 793 | audio_message->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
790 | 794 | ||
791 | #ifdef DEBUG_RECORD_PURE_OGG | 795 | #ifdef DEBUG_RECORD_PURE_OGG |
792 | dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; | 796 | dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; |
793 | #endif | 797 | #endif |
794 | ogg_init (); | 798 | ogg_init(); |
795 | opus_init (); | 799 | opus_init(); |
796 | pa_init (); | 800 | pa_init(); |
797 | return 0; | 801 | return 0; |
798 | } | 802 | } |
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index 3e531e202..e5e225623 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2013, 2016, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet-service-conversation.c | 21 | * @file conversation/gnunet-service-conversation.c |
22 | * @brief conversation service implementation | 22 | * @brief conversation service implementation |
@@ -52,8 +52,7 @@ struct Line; | |||
52 | /** | 52 | /** |
53 | * The possible connection status | 53 | * The possible connection status |
54 | */ | 54 | */ |
55 | enum ChannelStatus | 55 | enum ChannelStatus { |
56 | { | ||
57 | /** | 56 | /** |
58 | * We just got the connection, but no introduction yet. | 57 | * We just got the connection, but no introduction yet. |
59 | */ | 58 | */ |
@@ -88,7 +87,6 @@ enum ChannelStatus | |||
88 | * We're in shutdown, sending hangup messages before cleaning up. | 87 | * We're in shutdown, sending hangup messages before cleaning up. |
89 | */ | 88 | */ |
90 | CS_CALLER_SHUTDOWN | 89 | CS_CALLER_SHUTDOWN |
91 | |||
92 | }; | 90 | }; |
93 | 91 | ||
94 | 92 | ||
@@ -98,9 +96,7 @@ enum ChannelStatus | |||
98 | * be attached the the same `struct Line`, which represents a local | 96 | * be attached the the same `struct Line`, which represents a local |
99 | * client. We keep them in a linked list. | 97 | * client. We keep them in a linked list. |
100 | */ | 98 | */ |
101 | struct Channel | 99 | struct Channel { |
102 | { | ||
103 | |||
104 | /** | 100 | /** |
105 | * This is a DLL. | 101 | * This is a DLL. |
106 | */ | 102 | */ |
@@ -156,8 +152,7 @@ struct Channel | |||
156 | /** | 152 | /** |
157 | * A `struct Line` connects a local client with cadet channels. | 153 | * A `struct Line` connects a local client with cadet channels. |
158 | */ | 154 | */ |
159 | struct Line | 155 | struct Line { |
160 | { | ||
161 | /** | 156 | /** |
162 | * This is a DLL. | 157 | * This is a DLL. |
163 | */ | 158 | */ |
@@ -221,7 +216,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
221 | * @return NULL for not found | 216 | * @return NULL for not found |
222 | */ | 217 | */ |
223 | static struct Channel * | 218 | static struct Channel * |
224 | find_channel_by_line (struct Line *line, uint32_t cid) | 219 | find_channel_by_line(struct Line *line, uint32_t cid) |
225 | { | 220 | { |
226 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) | 221 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) |
227 | if (cid == ch->cid) | 222 | if (cid == ch->cid) |
@@ -237,8 +232,8 @@ find_channel_by_line (struct Line *line, uint32_t cid) | |||
237 | * @param msg the message from the client | 232 | * @param msg the message from the client |
238 | */ | 233 | */ |
239 | static void | 234 | static void |
240 | handle_client_pickup_message (void *cls, | 235 | handle_client_pickup_message(void *cls, |
241 | const struct ClientPhonePickupMessage *msg) | 236 | const struct ClientPhonePickupMessage *msg) |
242 | { | 237 | { |
243 | struct Line *line = cls; | 238 | struct Line *line = cls; |
244 | struct CadetPhonePickupMessage *mppm; | 239 | struct CadetPhonePickupMessage *mppm; |
@@ -246,52 +241,56 @@ handle_client_pickup_message (void *cls, | |||
246 | struct Channel *ch; | 241 | struct Channel *ch; |
247 | 242 | ||
248 | if (NULL == line->port) | 243 | if (NULL == line->port) |
249 | { | 244 | { |
250 | /* we never opened the port, bad client! */ | 245 | /* we never opened the port, bad client! */ |
251 | GNUNET_break_op (0); | 246 | GNUNET_break_op(0); |
252 | GNUNET_SERVICE_client_drop (line->client); | 247 | GNUNET_SERVICE_client_drop(line->client); |
253 | return; | 248 | return; |
254 | } | 249 | } |
255 | for (ch = line->channel_head; NULL != ch; ch = ch->next) | 250 | for (ch = line->channel_head; NULL != ch; ch = ch->next) |
256 | if (msg->cid == ch->cid) | 251 | if (msg->cid == ch->cid) |
257 | break; | 252 | break; |
258 | if (NULL == ch) | 253 | if (NULL == ch) |
259 | { | 254 | { |
260 | /* could have been destroyed asynchronously, ignore message */ | 255 | /* could have been destroyed asynchronously, ignore message */ |
261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
262 | GNUNET_SERVICE_client_continue (line->client); | 257 | GNUNET_SERVICE_client_continue(line->client); |
263 | return; | 258 | return; |
264 | } | 259 | } |
265 | switch (ch->status) | 260 | switch (ch->status) |
266 | { | 261 | { |
267 | case CS_CALLEE_INIT: | 262 | case CS_CALLEE_INIT: |
268 | GNUNET_break (0); | 263 | GNUNET_break(0); |
269 | GNUNET_SERVICE_client_drop (line->client); | 264 | GNUNET_SERVICE_client_drop(line->client); |
270 | return; | 265 | return; |
271 | case CS_CALLEE_RINGING: | 266 | |
272 | ch->status = CS_CALLEE_CONNECTED; | 267 | case CS_CALLEE_RINGING: |
273 | break; | 268 | ch->status = CS_CALLEE_CONNECTED; |
274 | case CS_CALLEE_CONNECTED: | 269 | break; |
275 | GNUNET_break (0); | 270 | |
276 | GNUNET_SERVICE_client_drop (line->client); | 271 | case CS_CALLEE_CONNECTED: |
277 | return; | 272 | GNUNET_break(0); |
278 | case CS_CALLEE_SHUTDOWN: | 273 | GNUNET_SERVICE_client_drop(line->client); |
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 274 | return; |
280 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); | 275 | |
281 | break; | 276 | case CS_CALLEE_SHUTDOWN: |
282 | case CS_CALLER_CALLING: | 277 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
283 | case CS_CALLER_CONNECTED: | 278 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); |
284 | case CS_CALLER_SHUTDOWN: | 279 | break; |
285 | GNUNET_break (0); | 280 | |
286 | GNUNET_SERVICE_client_drop (line->client); | 281 | case CS_CALLER_CALLING: |
287 | return; | 282 | case CS_CALLER_CONNECTED: |
288 | } | 283 | case CS_CALLER_SHUTDOWN: |
289 | GNUNET_break (CS_CALLEE_CONNECTED == ch->status); | 284 | GNUNET_break(0); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); | 285 | GNUNET_SERVICE_client_drop(line->client); |
286 | return; | ||
287 | } | ||
288 | GNUNET_break(CS_CALLEE_CONNECTED == ch->status); | ||
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); | ||
291 | env = | 290 | env = |
292 | GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); | 291 | GNUNET_MQ_msg(mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); |
293 | GNUNET_MQ_send (ch->mq, env); | 292 | GNUNET_MQ_send(ch->mq, env); |
294 | GNUNET_SERVICE_client_continue (line->client); | 293 | GNUNET_SERVICE_client_continue(line->client); |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
@@ -302,34 +301,35 @@ handle_client_pickup_message (void *cls, | |||
302 | * @param ch channel that went down | 301 | * @param ch channel that went down |
303 | */ | 302 | */ |
304 | static void | 303 | static void |
305 | clean_up_channel (struct Channel *ch) | 304 | clean_up_channel(struct Channel *ch) |
306 | { | 305 | { |
307 | struct Line *line = ch->line; | 306 | struct Line *line = ch->line; |
308 | struct GNUNET_MQ_Envelope *env; | 307 | struct GNUNET_MQ_Envelope *env; |
309 | struct ClientPhoneHangupMessage *hup; | 308 | struct ClientPhoneHangupMessage *hup; |
310 | 309 | ||
311 | switch (ch->status) | 310 | switch (ch->status) |
312 | { | ||
313 | case CS_CALLEE_INIT: | ||
314 | case CS_CALLEE_SHUTDOWN: | ||
315 | case CS_CALLER_SHUTDOWN: | ||
316 | break; | ||
317 | case CS_CALLEE_RINGING: | ||
318 | case CS_CALLEE_CONNECTED: | ||
319 | case CS_CALLER_CALLING: | ||
320 | case CS_CALLER_CONNECTED: | ||
321 | if (NULL != line) | ||
322 | { | 311 | { |
323 | env = | 312 | case CS_CALLEE_INIT: |
324 | GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 313 | case CS_CALLEE_SHUTDOWN: |
325 | hup->cid = ch->cid; | 314 | case CS_CALLER_SHUTDOWN: |
326 | GNUNET_MQ_send (line->mq, env); | 315 | break; |
316 | |||
317 | case CS_CALLEE_RINGING: | ||
318 | case CS_CALLEE_CONNECTED: | ||
319 | case CS_CALLER_CALLING: | ||
320 | case CS_CALLER_CONNECTED: | ||
321 | if (NULL != line) | ||
322 | { | ||
323 | env = | ||
324 | GNUNET_MQ_msg(hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
325 | hup->cid = ch->cid; | ||
326 | GNUNET_MQ_send(line->mq, env); | ||
327 | } | ||
328 | break; | ||
327 | } | 329 | } |
328 | break; | ||
329 | } | ||
330 | if (NULL != line) | 330 | if (NULL != line) |
331 | GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch); | 331 | GNUNET_CONTAINER_DLL_remove(line->channel_head, line->channel_tail, ch); |
332 | GNUNET_free (ch); | 332 | GNUNET_free(ch); |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
@@ -339,15 +339,15 @@ clean_up_channel (struct Channel *ch) | |||
339 | * @param ch channel to destroy. | 339 | * @param ch channel to destroy. |
340 | */ | 340 | */ |
341 | static void | 341 | static void |
342 | destroy_line_cadet_channels (struct Channel *ch) | 342 | destroy_line_cadet_channels(struct Channel *ch) |
343 | { | 343 | { |
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); | 344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); |
345 | if (NULL != ch->channel) | 345 | if (NULL != ch->channel) |
346 | { | 346 | { |
347 | GNUNET_CADET_channel_destroy (ch->channel); | 347 | GNUNET_CADET_channel_destroy(ch->channel); |
348 | ch->channel = NULL; | 348 | ch->channel = NULL; |
349 | } | 349 | } |
350 | clean_up_channel (ch); | 350 | clean_up_channel(ch); |
351 | } | 351 | } |
352 | 352 | ||
353 | 353 | ||
@@ -358,34 +358,40 @@ destroy_line_cadet_channels (struct Channel *ch) | |||
358 | * @param cls the `struct Channel` to reset/terminate | 358 | * @param cls the `struct Channel` to reset/terminate |
359 | */ | 359 | */ |
360 | static void | 360 | static void |
361 | mq_done_finish_caller_shutdown (void *cls) | 361 | mq_done_finish_caller_shutdown(void *cls) |
362 | { | 362 | { |
363 | struct Channel *ch = cls; | 363 | struct Channel *ch = cls; |
364 | 364 | ||
365 | switch (ch->status) | 365 | switch (ch->status) |
366 | { | 366 | { |
367 | case CS_CALLEE_INIT: | 367 | case CS_CALLEE_INIT: |
368 | GNUNET_break (0); | 368 | GNUNET_break(0); |
369 | break; | 369 | break; |
370 | case CS_CALLEE_RINGING: | 370 | |
371 | GNUNET_break (0); | 371 | case CS_CALLEE_RINGING: |
372 | break; | 372 | GNUNET_break(0); |
373 | case CS_CALLEE_CONNECTED: | 373 | break; |
374 | GNUNET_break (0); | 374 | |
375 | break; | 375 | case CS_CALLEE_CONNECTED: |
376 | case CS_CALLEE_SHUTDOWN: | 376 | GNUNET_break(0); |
377 | destroy_line_cadet_channels (ch); | 377 | break; |
378 | break; | 378 | |
379 | case CS_CALLER_CALLING: | 379 | case CS_CALLEE_SHUTDOWN: |
380 | GNUNET_break (0); | 380 | destroy_line_cadet_channels(ch); |
381 | break; | 381 | break; |
382 | case CS_CALLER_CONNECTED: | 382 | |
383 | GNUNET_break (0); | 383 | case CS_CALLER_CALLING: |
384 | break; | 384 | GNUNET_break(0); |
385 | case CS_CALLER_SHUTDOWN: | 385 | break; |
386 | destroy_line_cadet_channels (ch); | 386 | |
387 | break; | 387 | case CS_CALLER_CONNECTED: |
388 | } | 388 | GNUNET_break(0); |
389 | break; | ||
390 | |||
391 | case CS_CALLER_SHUTDOWN: | ||
392 | destroy_line_cadet_channels(ch); | ||
393 | break; | ||
394 | } | ||
389 | } | 395 | } |
390 | 396 | ||
391 | 397 | ||
@@ -396,8 +402,8 @@ mq_done_finish_caller_shutdown (void *cls) | |||
396 | * @param msg the message from the client | 402 | * @param msg the message from the client |
397 | */ | 403 | */ |
398 | static void | 404 | static void |
399 | handle_client_hangup_message (void *cls, | 405 | handle_client_hangup_message(void *cls, |
400 | const struct ClientPhoneHangupMessage *msg) | 406 | const struct ClientPhoneHangupMessage *msg) |
401 | { | 407 | { |
402 | struct Line *line = cls; | 408 | struct Line *line = cls; |
403 | struct GNUNET_MQ_Envelope *e; | 409 | struct GNUNET_MQ_Envelope *e; |
@@ -408,49 +414,55 @@ handle_client_hangup_message (void *cls, | |||
408 | if (msg->cid == ch->cid) | 414 | if (msg->cid == ch->cid) |
409 | break; | 415 | break; |
410 | if (NULL == ch) | 416 | if (NULL == ch) |
411 | { | 417 | { |
412 | /* could have been destroyed asynchronously, ignore message */ | 418 | /* could have been destroyed asynchronously, ignore message */ |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
414 | GNUNET_SERVICE_client_continue (line->client); | 420 | GNUNET_SERVICE_client_continue(line->client); |
415 | return; | 421 | return; |
416 | } | 422 | } |
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
418 | "Received HANGUP for channel %u which is in state %d\n", | 424 | "Received HANGUP for channel %u which is in state %d\n", |
419 | msg->cid, | 425 | msg->cid, |
420 | ch->status); | 426 | ch->status); |
421 | switch (ch->status) | 427 | switch (ch->status) |
422 | { | 428 | { |
423 | case CS_CALLEE_INIT: | 429 | case CS_CALLEE_INIT: |
424 | GNUNET_break (0); | 430 | GNUNET_break(0); |
425 | GNUNET_SERVICE_client_drop (line->client); | 431 | GNUNET_SERVICE_client_drop(line->client); |
426 | return; | 432 | return; |
427 | case CS_CALLEE_RINGING: | 433 | |
428 | ch->status = CS_CALLEE_SHUTDOWN; | 434 | case CS_CALLEE_RINGING: |
429 | break; | 435 | ch->status = CS_CALLEE_SHUTDOWN; |
430 | case CS_CALLEE_CONNECTED: | 436 | break; |
431 | ch->status = CS_CALLEE_SHUTDOWN; | 437 | |
432 | break; | 438 | case CS_CALLEE_CONNECTED: |
433 | case CS_CALLEE_SHUTDOWN: | 439 | ch->status = CS_CALLEE_SHUTDOWN; |
434 | /* maybe the other peer closed asynchronously... */ | 440 | break; |
435 | GNUNET_SERVICE_client_continue (line->client); | 441 | |
436 | return; | 442 | case CS_CALLEE_SHUTDOWN: |
437 | case CS_CALLER_CALLING: | 443 | /* maybe the other peer closed asynchronously... */ |
438 | ch->status = CS_CALLER_SHUTDOWN; | 444 | GNUNET_SERVICE_client_continue(line->client); |
439 | break; | 445 | return; |
440 | case CS_CALLER_CONNECTED: | 446 | |
441 | ch->status = CS_CALLER_SHUTDOWN; | 447 | case CS_CALLER_CALLING: |
442 | break; | 448 | ch->status = CS_CALLER_SHUTDOWN; |
443 | case CS_CALLER_SHUTDOWN: | 449 | break; |
444 | /* maybe the other peer closed asynchronously... */ | 450 | |
445 | GNUNET_SERVICE_client_continue (line->client); | 451 | case CS_CALLER_CONNECTED: |
446 | return; | 452 | ch->status = CS_CALLER_SHUTDOWN; |
447 | } | 453 | break; |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); | 454 | |
455 | case CS_CALLER_SHUTDOWN: | ||
456 | /* maybe the other peer closed asynchronously... */ | ||
457 | GNUNET_SERVICE_client_continue(line->client); | ||
458 | return; | ||
459 | } | ||
460 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); | ||
449 | e = | 461 | e = |
450 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); | 462 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); |
451 | GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch); | 463 | GNUNET_MQ_notify_sent(e, &mq_done_finish_caller_shutdown, ch); |
452 | GNUNET_MQ_send (ch->mq, e); | 464 | GNUNET_MQ_send(ch->mq, e); |
453 | GNUNET_SERVICE_client_continue (line->client); | 465 | GNUNET_SERVICE_client_continue(line->client); |
454 | } | 466 | } |
455 | 467 | ||
456 | 468 | ||
@@ -461,8 +473,8 @@ handle_client_hangup_message (void *cls, | |||
461 | * @param msg the message from the client | 473 | * @param msg the message from the client |
462 | */ | 474 | */ |
463 | static void | 475 | static void |
464 | handle_client_suspend_message (void *cls, | 476 | handle_client_suspend_message(void *cls, |
465 | const struct ClientPhoneSuspendMessage *msg) | 477 | const struct ClientPhoneSuspendMessage *msg) |
466 | { | 478 | { |
467 | struct Line *line = cls; | 479 | struct Line *line = cls; |
468 | struct GNUNET_MQ_Envelope *e; | 480 | struct GNUNET_MQ_Envelope *e; |
@@ -473,56 +485,62 @@ handle_client_suspend_message (void *cls, | |||
473 | if (msg->cid == ch->cid) | 485 | if (msg->cid == ch->cid) |
474 | break; | 486 | break; |
475 | if (NULL == ch) | 487 | if (NULL == ch) |
476 | { | 488 | { |
477 | /* could have been destroyed asynchronously, ignore message */ | 489 | /* could have been destroyed asynchronously, ignore message */ |
478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 490 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
479 | GNUNET_SERVICE_client_continue (line->client); | 491 | GNUNET_SERVICE_client_continue(line->client); |
480 | return; | 492 | return; |
481 | } | 493 | } |
482 | if (GNUNET_YES == ch->suspended_local) | 494 | if (GNUNET_YES == ch->suspended_local) |
483 | { | 495 | { |
484 | GNUNET_break (0); | 496 | GNUNET_break(0); |
485 | GNUNET_SERVICE_client_drop (line->client); | 497 | GNUNET_SERVICE_client_drop(line->client); |
486 | return; | 498 | return; |
487 | } | 499 | } |
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 500 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
489 | "Received SUSPEND for channel %u which is in state %d\n", | 501 | "Received SUSPEND for channel %u which is in state %d\n", |
490 | msg->cid, | 502 | msg->cid, |
491 | ch->status); | 503 | ch->status); |
492 | switch (ch->status) | 504 | switch (ch->status) |
493 | { | 505 | { |
494 | case CS_CALLEE_INIT: | 506 | case CS_CALLEE_INIT: |
495 | GNUNET_break (0); | 507 | GNUNET_break(0); |
496 | GNUNET_SERVICE_client_drop (line->client); | 508 | GNUNET_SERVICE_client_drop(line->client); |
497 | return; | 509 | return; |
498 | case CS_CALLEE_RINGING: | 510 | |
499 | GNUNET_break (0); | 511 | case CS_CALLEE_RINGING: |
500 | GNUNET_SERVICE_client_drop (line->client); | 512 | GNUNET_break(0); |
501 | return; | 513 | GNUNET_SERVICE_client_drop(line->client); |
502 | case CS_CALLEE_CONNECTED: | 514 | return; |
503 | ch->suspended_local = GNUNET_YES; | 515 | |
504 | break; | 516 | case CS_CALLEE_CONNECTED: |
505 | case CS_CALLEE_SHUTDOWN: | 517 | ch->suspended_local = GNUNET_YES; |
506 | /* maybe the other peer closed asynchronously... */ | 518 | break; |
507 | GNUNET_SERVICE_client_continue (line->client); | 519 | |
508 | return; | 520 | case CS_CALLEE_SHUTDOWN: |
509 | case CS_CALLER_CALLING: | 521 | /* maybe the other peer closed asynchronously... */ |
510 | GNUNET_break (0); | 522 | GNUNET_SERVICE_client_continue(line->client); |
511 | GNUNET_SERVICE_client_drop (line->client); | 523 | return; |
512 | return; | 524 | |
513 | case CS_CALLER_CONNECTED: | 525 | case CS_CALLER_CALLING: |
514 | ch->suspended_local = GNUNET_YES; | 526 | GNUNET_break(0); |
515 | break; | 527 | GNUNET_SERVICE_client_drop(line->client); |
516 | case CS_CALLER_SHUTDOWN: | 528 | return; |
517 | /* maybe the other peer closed asynchronously... */ | 529 | |
518 | GNUNET_SERVICE_client_continue (line->client); | 530 | case CS_CALLER_CONNECTED: |
519 | return; | 531 | ch->suspended_local = GNUNET_YES; |
520 | } | 532 | break; |
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); | 533 | |
534 | case CS_CALLER_SHUTDOWN: | ||
535 | /* maybe the other peer closed asynchronously... */ | ||
536 | GNUNET_SERVICE_client_continue(line->client); | ||
537 | return; | ||
538 | } | ||
539 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); | ||
522 | e = | 540 | e = |
523 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); | 541 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); |
524 | GNUNET_MQ_send (ch->mq, e); | 542 | GNUNET_MQ_send(ch->mq, e); |
525 | GNUNET_SERVICE_client_continue (line->client); | 543 | GNUNET_SERVICE_client_continue(line->client); |
526 | } | 544 | } |
527 | 545 | ||
528 | 546 | ||
@@ -533,8 +551,8 @@ handle_client_suspend_message (void *cls, | |||
533 | * @param msg the message from the client | 551 | * @param msg the message from the client |
534 | */ | 552 | */ |
535 | static void | 553 | static void |
536 | handle_client_resume_message (void *cls, | 554 | handle_client_resume_message(void *cls, |
537 | const struct ClientPhoneResumeMessage *msg) | 555 | const struct ClientPhoneResumeMessage *msg) |
538 | { | 556 | { |
539 | struct Line *line = cls; | 557 | struct Line *line = cls; |
540 | struct GNUNET_MQ_Envelope *e; | 558 | struct GNUNET_MQ_Envelope *e; |
@@ -545,55 +563,61 @@ handle_client_resume_message (void *cls, | |||
545 | if (msg->cid == ch->cid) | 563 | if (msg->cid == ch->cid) |
546 | break; | 564 | break; |
547 | if (NULL == ch) | 565 | if (NULL == ch) |
548 | { | 566 | { |
549 | /* could have been destroyed asynchronously, ignore message */ | 567 | /* could have been destroyed asynchronously, ignore message */ |
550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
551 | GNUNET_SERVICE_client_continue (line->client); | 569 | GNUNET_SERVICE_client_continue(line->client); |
552 | return; | 570 | return; |
553 | } | 571 | } |
554 | if (GNUNET_YES != ch->suspended_local) | 572 | if (GNUNET_YES != ch->suspended_local) |
555 | { | 573 | { |
556 | GNUNET_break (0); | 574 | GNUNET_break(0); |
557 | GNUNET_SERVICE_client_drop (line->client); | 575 | GNUNET_SERVICE_client_drop(line->client); |
558 | return; | 576 | return; |
559 | } | 577 | } |
560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
561 | "Received RESUME for channel %u which is in state %d\n", | 579 | "Received RESUME for channel %u which is in state %d\n", |
562 | msg->cid, | 580 | msg->cid, |
563 | ch->status); | 581 | ch->status); |
564 | switch (ch->status) | 582 | switch (ch->status) |
565 | { | 583 | { |
566 | case CS_CALLEE_INIT: | 584 | case CS_CALLEE_INIT: |
567 | GNUNET_break (0); | 585 | GNUNET_break(0); |
568 | GNUNET_SERVICE_client_drop (line->client); | 586 | GNUNET_SERVICE_client_drop(line->client); |
569 | return; | 587 | return; |
570 | case CS_CALLEE_RINGING: | 588 | |
571 | GNUNET_break (0); | 589 | case CS_CALLEE_RINGING: |
572 | GNUNET_SERVICE_client_drop (line->client); | 590 | GNUNET_break(0); |
573 | return; | 591 | GNUNET_SERVICE_client_drop(line->client); |
574 | case CS_CALLEE_CONNECTED: | 592 | return; |
575 | ch->suspended_local = GNUNET_NO; | 593 | |
576 | break; | 594 | case CS_CALLEE_CONNECTED: |
577 | case CS_CALLEE_SHUTDOWN: | 595 | ch->suspended_local = GNUNET_NO; |
578 | /* maybe the other peer closed asynchronously... */ | 596 | break; |
579 | GNUNET_SERVICE_client_continue (line->client); | 597 | |
580 | return; | 598 | case CS_CALLEE_SHUTDOWN: |
581 | case CS_CALLER_CALLING: | 599 | /* maybe the other peer closed asynchronously... */ |
582 | GNUNET_break (0); | 600 | GNUNET_SERVICE_client_continue(line->client); |
583 | GNUNET_SERVICE_client_drop (line->client); | 601 | return; |
584 | return; | 602 | |
585 | case CS_CALLER_CONNECTED: | 603 | case CS_CALLER_CALLING: |
586 | ch->suspended_local = GNUNET_NO; | 604 | GNUNET_break(0); |
587 | break; | 605 | GNUNET_SERVICE_client_drop(line->client); |
588 | case CS_CALLER_SHUTDOWN: | 606 | return; |
589 | /* maybe the other peer closed asynchronously... */ | 607 | |
590 | GNUNET_SERVICE_client_drop (line->client); | 608 | case CS_CALLER_CONNECTED: |
591 | return; | 609 | ch->suspended_local = GNUNET_NO; |
592 | } | 610 | break; |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); | 611 | |
594 | e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); | 612 | case CS_CALLER_SHUTDOWN: |
595 | GNUNET_MQ_send (ch->mq, e); | 613 | /* maybe the other peer closed asynchronously... */ |
596 | GNUNET_SERVICE_client_continue (line->client); | 614 | GNUNET_SERVICE_client_drop(line->client); |
615 | return; | ||
616 | } | ||
617 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); | ||
618 | e = GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); | ||
619 | GNUNET_MQ_send(ch->mq, e); | ||
620 | GNUNET_SERVICE_client_continue(line->client); | ||
597 | } | 621 | } |
598 | 622 | ||
599 | 623 | ||
@@ -603,7 +627,7 @@ handle_client_resume_message (void *cls, | |||
603 | * @param cls the `struct Channel` we are transmitting for | 627 | * @param cls the `struct Channel` we are transmitting for |
604 | */ | 628 | */ |
605 | static void | 629 | static void |
606 | channel_audio_sent_notify (void *cls) | 630 | channel_audio_sent_notify(void *cls) |
607 | { | 631 | { |
608 | struct Channel *ch = cls; | 632 | struct Channel *ch = cls; |
609 | 633 | ||
@@ -619,10 +643,10 @@ channel_audio_sent_notify (void *cls) | |||
619 | * @return #GNUNET_OK (any data is ok) | 643 | * @return #GNUNET_OK (any data is ok) |
620 | */ | 644 | */ |
621 | static int | 645 | static int |
622 | check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | 646 | check_client_audio_message(void *cls, const struct ClientAudioMessage *msg) |
623 | { | 647 | { |
624 | (void) cls; | 648 | (void)cls; |
625 | (void) msg; | 649 | (void)msg; |
626 | return GNUNET_OK; | 650 | return GNUNET_OK; |
627 | } | 651 | } |
628 | 652 | ||
@@ -634,70 +658,72 @@ check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | |||
634 | * @param msg the message from the client | 658 | * @param msg the message from the client |
635 | */ | 659 | */ |
636 | static void | 660 | static void |
637 | handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | 661 | handle_client_audio_message(void *cls, const struct ClientAudioMessage *msg) |
638 | { | 662 | { |
639 | struct Line *line = cls; | 663 | struct Line *line = cls; |
640 | struct CadetAudioMessage *mam; | 664 | struct CadetAudioMessage *mam; |
641 | struct Channel *ch; | 665 | struct Channel *ch; |
642 | size_t size; | 666 | size_t size; |
643 | 667 | ||
644 | size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage); | 668 | size = ntohs(msg->header.size) - sizeof(struct ClientAudioMessage); |
645 | ch = find_channel_by_line (line, msg->cid); | 669 | ch = find_channel_by_line(line, msg->cid); |
646 | if (NULL == ch) | 670 | if (NULL == ch) |
647 | { | 671 | { |
648 | /* could have been destroyed asynchronously, ignore message */ | 672 | /* could have been destroyed asynchronously, ignore message */ |
649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 673 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
650 | GNUNET_SERVICE_client_continue (line->client); | 674 | GNUNET_SERVICE_client_continue(line->client); |
651 | return; | 675 | return; |
652 | } | 676 | } |
653 | 677 | ||
654 | switch (ch->status) | 678 | switch (ch->status) |
655 | { | 679 | { |
656 | case CS_CALLEE_INIT: | 680 | case CS_CALLEE_INIT: |
657 | case CS_CALLEE_RINGING: | 681 | case CS_CALLEE_RINGING: |
658 | case CS_CALLER_CALLING: | 682 | case CS_CALLER_CALLING: |
659 | GNUNET_break (0); | 683 | GNUNET_break(0); |
660 | GNUNET_SERVICE_client_drop (line->client); | 684 | GNUNET_SERVICE_client_drop(line->client); |
661 | return; | 685 | return; |
662 | case CS_CALLEE_CONNECTED: | 686 | |
663 | case CS_CALLER_CONNECTED: | 687 | case CS_CALLEE_CONNECTED: |
664 | /* common case, handled below */ | 688 | case CS_CALLER_CONNECTED: |
665 | break; | 689 | /* common case, handled below */ |
666 | case CS_CALLEE_SHUTDOWN: | 690 | break; |
667 | case CS_CALLER_SHUTDOWN: | 691 | |
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 692 | case CS_CALLEE_SHUTDOWN: |
669 | "Cadet audio channel in shutdown; audio data dropped\n"); | 693 | case CS_CALLER_SHUTDOWN: |
670 | GNUNET_SERVICE_client_continue (line->client); | 694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
671 | return; | 695 | "Cadet audio channel in shutdown; audio data dropped\n"); |
672 | } | 696 | GNUNET_SERVICE_client_continue(line->client); |
697 | return; | ||
698 | } | ||
673 | if (GNUNET_YES == ch->suspended_local) | 699 | if (GNUNET_YES == ch->suspended_local) |
674 | { | 700 | { |
675 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 701 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
676 | "This channel is suspended locally\n"); | 702 | "This channel is suspended locally\n"); |
677 | GNUNET_SERVICE_client_drop (line->client); | 703 | GNUNET_SERVICE_client_drop(line->client); |
678 | return; | 704 | return; |
679 | } | 705 | } |
680 | if (NULL != ch->env) | 706 | if (NULL != ch->env) |
681 | { | 707 | { |
682 | /* NOTE: we may want to not do this and instead combine the data */ | 708 | /* NOTE: we may want to not do this and instead combine the data */ |
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
684 | "Bandwidth insufficient; dropping previous audio data segment\n"); | 710 | "Bandwidth insufficient; dropping previous audio data segment\n"); |
685 | GNUNET_MQ_send_cancel (ch->env); | 711 | GNUNET_MQ_send_cancel(ch->env); |
686 | ch->env = NULL; | 712 | ch->env = NULL; |
687 | } | 713 | } |
688 | 714 | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 715 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
690 | "Received %u bytes of AUDIO data from client CID %u\n", | 716 | "Received %u bytes of AUDIO data from client CID %u\n", |
691 | (unsigned int) size, | 717 | (unsigned int)size, |
692 | msg->cid); | 718 | msg->cid); |
693 | ch->env = GNUNET_MQ_msg_extra (mam, | 719 | ch->env = GNUNET_MQ_msg_extra(mam, |
694 | size, | 720 | size, |
695 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); | 721 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); |
696 | GNUNET_memcpy (&mam[1], &msg[1], size); | 722 | GNUNET_memcpy(&mam[1], &msg[1], size); |
697 | /* FIXME: set options for unreliable transmission */ | 723 | /* FIXME: set options for unreliable transmission */ |
698 | GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch); | 724 | GNUNET_MQ_notify_sent(ch->env, &channel_audio_sent_notify, ch); |
699 | GNUNET_MQ_send (ch->mq, ch->env); | 725 | GNUNET_MQ_send(ch->mq, ch->env); |
700 | GNUNET_SERVICE_client_continue (line->client); | 726 | GNUNET_SERVICE_client_continue(line->client); |
701 | } | 727 | } |
702 | 728 | ||
703 | 729 | ||
@@ -708,7 +734,7 @@ handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) | |||
708 | * @param msg the incoming message | 734 | * @param msg the incoming message |
709 | */ | 735 | */ |
710 | static void | 736 | static void |
711 | handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | 737 | handle_cadet_ring_message(void *cls, const struct CadetPhoneRingMessage *msg) |
712 | { | 738 | { |
713 | struct Channel *ch = cls; | 739 | struct Channel *ch = cls; |
714 | struct Line *line = ch->line; | 740 | struct Line *line = ch->line; |
@@ -716,49 +742,49 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | |||
716 | struct ClientPhoneRingMessage *cring; | 742 | struct ClientPhoneRingMessage *cring; |
717 | struct CadetPhoneRingInfoPS rs; | 743 | struct CadetPhoneRingInfoPS rs; |
718 | 744 | ||
719 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 745 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
720 | rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); | 746 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); |
721 | rs.line_port = line->line_port; | 747 | rs.line_port = line->line_port; |
722 | rs.target_peer = my_identity; | 748 | rs.target_peer = my_identity; |
723 | rs.expiration_time = msg->expiration_time; | 749 | rs.expiration_time = msg->expiration_time; |
724 | 750 | ||
725 | if (GNUNET_OK != | 751 | if (GNUNET_OK != |
726 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, | 752 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, |
727 | &rs.purpose, | 753 | &rs.purpose, |
728 | &msg->signature, | 754 | &msg->signature, |
729 | &msg->caller_id)) | 755 | &msg->caller_id)) |
730 | { | 756 | { |
731 | GNUNET_break_op (0); | 757 | GNUNET_break_op(0); |
732 | destroy_line_cadet_channels (ch); | 758 | destroy_line_cadet_channels(ch); |
733 | return; | 759 | return; |
734 | } | 760 | } |
735 | if (0 == GNUNET_TIME_absolute_get_remaining ( | 761 | if (0 == GNUNET_TIME_absolute_get_remaining( |
736 | GNUNET_TIME_absolute_ntoh (msg->expiration_time)) | 762 | GNUNET_TIME_absolute_ntoh(msg->expiration_time)) |
737 | .rel_value_us) | 763 | .rel_value_us) |
738 | { | 764 | { |
739 | /* ancient call, replay? */ | 765 | /* ancient call, replay? */ |
740 | GNUNET_break_op (0); | 766 | GNUNET_break_op(0); |
741 | /* Note that our reliance on time here is awkward; better would be | 767 | /* Note that our reliance on time here is awkward; better would be |
742 | to use a more complex challenge-response protocol against | 768 | to use a more complex challenge-response protocol against |
743 | replay attacks. Left for future work ;-). */ | 769 | replay attacks. Left for future work ;-). */ |
744 | destroy_line_cadet_channels (ch); | 770 | destroy_line_cadet_channels(ch); |
745 | return; | 771 | return; |
746 | } | 772 | } |
747 | if (CS_CALLEE_INIT != ch->status) | 773 | if (CS_CALLEE_INIT != ch->status) |
748 | { | 774 | { |
749 | GNUNET_break_op (0); | 775 | GNUNET_break_op(0); |
750 | destroy_line_cadet_channels (ch); | 776 | destroy_line_cadet_channels(ch); |
751 | return; | 777 | return; |
752 | } | 778 | } |
753 | GNUNET_CADET_receive_done (ch->channel); | 779 | GNUNET_CADET_receive_done(ch->channel); |
754 | ch->status = CS_CALLEE_RINGING; | 780 | ch->status = CS_CALLEE_RINGING; |
755 | env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); | 781 | env = GNUNET_MQ_msg(cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); |
756 | cring->cid = ch->cid; | 782 | cring->cid = ch->cid; |
757 | cring->caller_id = msg->caller_id; | 783 | cring->caller_id = msg->caller_id; |
758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
759 | "Sending RING message to client. CID is %u\n", | 785 | "Sending RING message to client. CID is %u\n", |
760 | (unsigned int) ch->cid); | 786 | (unsigned int)ch->cid); |
761 | GNUNET_MQ_send (line->mq, env); | 787 | GNUNET_MQ_send(line->mq, env); |
762 | } | 788 | } |
763 | 789 | ||
764 | 790 | ||
@@ -769,8 +795,8 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | |||
769 | * @param message the incoming message | 795 | * @param message the incoming message |
770 | */ | 796 | */ |
771 | static void | 797 | static void |
772 | handle_cadet_hangup_message (void *cls, | 798 | handle_cadet_hangup_message(void *cls, |
773 | const struct CadetPhoneHangupMessage *message) | 799 | const struct CadetPhoneHangupMessage *message) |
774 | { | 800 | { |
775 | struct Channel *ch = cls; | 801 | struct Channel *ch = cls; |
776 | struct Line *line = ch->line; | 802 | struct Line *line = ch->line; |
@@ -779,31 +805,35 @@ handle_cadet_hangup_message (void *cls, | |||
779 | enum ChannelStatus status; | 805 | enum ChannelStatus status; |
780 | uint32_t cid; | 806 | uint32_t cid; |
781 | 807 | ||
782 | (void) message; | 808 | (void)message; |
783 | GNUNET_CADET_receive_done (ch->channel); | 809 | GNUNET_CADET_receive_done(ch->channel); |
784 | cid = ch->cid; | 810 | cid = ch->cid; |
785 | status = ch->status; | 811 | status = ch->status; |
786 | destroy_line_cadet_channels (ch); | 812 | destroy_line_cadet_channels(ch); |
787 | switch (status) | 813 | switch (status) |
788 | { | 814 | { |
789 | case CS_CALLEE_INIT: | 815 | case CS_CALLEE_INIT: |
790 | GNUNET_break_op (0); | 816 | GNUNET_break_op(0); |
791 | return; | 817 | return; |
792 | case CS_CALLEE_RINGING: | 818 | |
793 | case CS_CALLEE_CONNECTED: | 819 | case CS_CALLEE_RINGING: |
794 | break; | 820 | case CS_CALLEE_CONNECTED: |
795 | case CS_CALLEE_SHUTDOWN: | 821 | break; |
796 | return; | 822 | |
797 | case CS_CALLER_CALLING: | 823 | case CS_CALLEE_SHUTDOWN: |
798 | case CS_CALLER_CONNECTED: | 824 | return; |
799 | break; | 825 | |
800 | case CS_CALLER_SHUTDOWN: | 826 | case CS_CALLER_CALLING: |
801 | return; | 827 | case CS_CALLER_CONNECTED: |
802 | } | 828 | break; |
803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); | 829 | |
804 | env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 830 | case CS_CALLER_SHUTDOWN: |
831 | return; | ||
832 | } | ||
833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); | ||
834 | env = GNUNET_MQ_msg(hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | ||
805 | hup->cid = cid; | 835 | hup->cid = cid; |
806 | GNUNET_MQ_send (line->mq, env); | 836 | GNUNET_MQ_send(line->mq, env); |
807 | } | 837 | } |
808 | 838 | ||
809 | 839 | ||
@@ -814,44 +844,48 @@ handle_cadet_hangup_message (void *cls, | |||
814 | * @param message the incoming message | 844 | * @param message the incoming message |
815 | */ | 845 | */ |
816 | static void | 846 | static void |
817 | handle_cadet_pickup_message (void *cls, | 847 | handle_cadet_pickup_message(void *cls, |
818 | const struct CadetPhonePickupMessage *message) | 848 | const struct CadetPhonePickupMessage *message) |
819 | { | 849 | { |
820 | struct Channel *ch = cls; | 850 | struct Channel *ch = cls; |
821 | struct Line *line = ch->line; | 851 | struct Line *line = ch->line; |
822 | struct GNUNET_MQ_Envelope *env; | 852 | struct GNUNET_MQ_Envelope *env; |
823 | struct ClientPhonePickedupMessage *pick; | 853 | struct ClientPhonePickedupMessage *pick; |
824 | 854 | ||
825 | (void) message; | 855 | (void)message; |
826 | GNUNET_CADET_receive_done (ch->channel); | 856 | GNUNET_CADET_receive_done(ch->channel); |
827 | switch (ch->status) | 857 | switch (ch->status) |
828 | { | 858 | { |
829 | case CS_CALLEE_INIT: | 859 | case CS_CALLEE_INIT: |
830 | case CS_CALLEE_RINGING: | 860 | case CS_CALLEE_RINGING: |
831 | case CS_CALLEE_CONNECTED: | 861 | case CS_CALLEE_CONNECTED: |
832 | GNUNET_break_op (0); | 862 | GNUNET_break_op(0); |
833 | destroy_line_cadet_channels (ch); | 863 | destroy_line_cadet_channels(ch); |
834 | return; | 864 | return; |
835 | case CS_CALLEE_SHUTDOWN: | 865 | |
836 | GNUNET_break_op (0); | 866 | case CS_CALLEE_SHUTDOWN: |
837 | destroy_line_cadet_channels (ch); | 867 | GNUNET_break_op(0); |
838 | return; | 868 | destroy_line_cadet_channels(ch); |
839 | case CS_CALLER_CALLING: | 869 | return; |
840 | ch->status = CS_CALLER_CONNECTED; | 870 | |
841 | break; | 871 | case CS_CALLER_CALLING: |
842 | case CS_CALLER_CONNECTED: | 872 | ch->status = CS_CALLER_CONNECTED; |
843 | GNUNET_break_op (0); | 873 | break; |
844 | return; | 874 | |
845 | case CS_CALLER_SHUTDOWN: | 875 | case CS_CALLER_CONNECTED: |
846 | GNUNET_break_op (0); | 876 | GNUNET_break_op(0); |
847 | mq_done_finish_caller_shutdown (ch); | 877 | return; |
848 | return; | 878 | |
849 | } | 879 | case CS_CALLER_SHUTDOWN: |
850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); | 880 | GNUNET_break_op(0); |
881 | mq_done_finish_caller_shutdown(ch); | ||
882 | return; | ||
883 | } | ||
884 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); | ||
851 | env = | 885 | env = |
852 | GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); | 886 | GNUNET_MQ_msg(pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); |
853 | pick->cid = ch->cid; | 887 | pick->cid = ch->cid; |
854 | GNUNET_MQ_send (line->mq, env); | 888 | GNUNET_MQ_send(line->mq, env); |
855 | } | 889 | } |
856 | 890 | ||
857 | 891 | ||
@@ -862,43 +896,49 @@ handle_cadet_pickup_message (void *cls, | |||
862 | * @param message the incoming message | 896 | * @param message the incoming message |
863 | */ | 897 | */ |
864 | static void | 898 | static void |
865 | handle_cadet_suspend_message (void *cls, | 899 | handle_cadet_suspend_message(void *cls, |
866 | const struct CadetPhoneSuspendMessage *message) | 900 | const struct CadetPhoneSuspendMessage *message) |
867 | { | 901 | { |
868 | struct Channel *ch = cls; | 902 | struct Channel *ch = cls; |
869 | struct Line *line = ch->line; | 903 | struct Line *line = ch->line; |
870 | struct GNUNET_MQ_Envelope *env; | 904 | struct GNUNET_MQ_Envelope *env; |
871 | struct ClientPhoneSuspendMessage *suspend; | 905 | struct ClientPhoneSuspendMessage *suspend; |
872 | 906 | ||
873 | (void) message; | 907 | (void)message; |
874 | GNUNET_CADET_receive_done (ch->channel); | 908 | GNUNET_CADET_receive_done(ch->channel); |
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); | 909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); |
876 | switch (ch->status) | 910 | switch (ch->status) |
877 | { | 911 | { |
878 | case CS_CALLEE_INIT: | 912 | case CS_CALLEE_INIT: |
879 | GNUNET_break_op (0); | 913 | GNUNET_break_op(0); |
880 | break; | 914 | break; |
881 | case CS_CALLEE_RINGING: | 915 | |
882 | GNUNET_break_op (0); | 916 | case CS_CALLEE_RINGING: |
883 | break; | 917 | GNUNET_break_op(0); |
884 | case CS_CALLEE_CONNECTED: | 918 | break; |
885 | ch->suspended_remote = GNUNET_YES; | 919 | |
886 | break; | 920 | case CS_CALLEE_CONNECTED: |
887 | case CS_CALLEE_SHUTDOWN: | 921 | ch->suspended_remote = GNUNET_YES; |
888 | return; | 922 | break; |
889 | case CS_CALLER_CALLING: | 923 | |
890 | GNUNET_break_op (0); | 924 | case CS_CALLEE_SHUTDOWN: |
891 | break; | 925 | return; |
892 | case CS_CALLER_CONNECTED: | 926 | |
893 | ch->suspended_remote = GNUNET_YES; | 927 | case CS_CALLER_CALLING: |
894 | break; | 928 | GNUNET_break_op(0); |
895 | case CS_CALLER_SHUTDOWN: | 929 | break; |
896 | return; | 930 | |
897 | } | 931 | case CS_CALLER_CONNECTED: |
932 | ch->suspended_remote = GNUNET_YES; | ||
933 | break; | ||
934 | |||
935 | case CS_CALLER_SHUTDOWN: | ||
936 | return; | ||
937 | } | ||
898 | env = | 938 | env = |
899 | GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 939 | GNUNET_MQ_msg(suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
900 | suspend->cid = ch->cid; | 940 | suspend->cid = ch->cid; |
901 | GNUNET_MQ_send (line->mq, env); | 941 | GNUNET_MQ_send(line->mq, env); |
902 | } | 942 | } |
903 | 943 | ||
904 | 944 | ||
@@ -909,51 +949,57 @@ handle_cadet_suspend_message (void *cls, | |||
909 | * @param msg the incoming message | 949 | * @param msg the incoming message |
910 | */ | 950 | */ |
911 | static void | 951 | static void |
912 | handle_cadet_resume_message (void *cls, | 952 | handle_cadet_resume_message(void *cls, |
913 | const struct CadetPhoneResumeMessage *msg) | 953 | const struct CadetPhoneResumeMessage *msg) |
914 | { | 954 | { |
915 | struct Channel *ch = cls; | 955 | struct Channel *ch = cls; |
916 | struct Line *line; | 956 | struct Line *line; |
917 | struct GNUNET_MQ_Envelope *env; | 957 | struct GNUNET_MQ_Envelope *env; |
918 | struct ClientPhoneResumeMessage *resume; | 958 | struct ClientPhoneResumeMessage *resume; |
919 | 959 | ||
920 | (void) msg; | 960 | (void)msg; |
921 | line = ch->line; | 961 | line = ch->line; |
922 | GNUNET_CADET_receive_done (ch->channel); | 962 | GNUNET_CADET_receive_done(ch->channel); |
923 | if (GNUNET_YES != ch->suspended_remote) | 963 | if (GNUNET_YES != ch->suspended_remote) |
924 | { | 964 | { |
925 | GNUNET_log ( | 965 | GNUNET_log( |
926 | GNUNET_ERROR_TYPE_DEBUG, | 966 | GNUNET_ERROR_TYPE_DEBUG, |
927 | "RESUME message received for non-suspended channel, dropping channel.\n"); | 967 | "RESUME message received for non-suspended channel, dropping channel.\n"); |
928 | destroy_line_cadet_channels (ch); | 968 | destroy_line_cadet_channels(ch); |
929 | return; | 969 | return; |
930 | } | 970 | } |
931 | switch (ch->status) | 971 | switch (ch->status) |
932 | { | 972 | { |
933 | case CS_CALLEE_INIT: | 973 | case CS_CALLEE_INIT: |
934 | GNUNET_break (0); | 974 | GNUNET_break(0); |
935 | break; | 975 | break; |
936 | case CS_CALLEE_RINGING: | 976 | |
937 | GNUNET_break (0); | 977 | case CS_CALLEE_RINGING: |
938 | break; | 978 | GNUNET_break(0); |
939 | case CS_CALLEE_CONNECTED: | 979 | break; |
940 | ch->suspended_remote = GNUNET_NO; | 980 | |
941 | break; | 981 | case CS_CALLEE_CONNECTED: |
942 | case CS_CALLEE_SHUTDOWN: | 982 | ch->suspended_remote = GNUNET_NO; |
943 | return; | 983 | break; |
944 | case CS_CALLER_CALLING: | 984 | |
945 | GNUNET_break (0); | 985 | case CS_CALLEE_SHUTDOWN: |
946 | break; | 986 | return; |
947 | case CS_CALLER_CONNECTED: | 987 | |
948 | ch->suspended_remote = GNUNET_NO; | 988 | case CS_CALLER_CALLING: |
949 | break; | 989 | GNUNET_break(0); |
950 | case CS_CALLER_SHUTDOWN: | 990 | break; |
951 | return; | 991 | |
952 | } | 992 | case CS_CALLER_CONNECTED: |
993 | ch->suspended_remote = GNUNET_NO; | ||
994 | break; | ||
995 | |||
996 | case CS_CALLER_SHUTDOWN: | ||
997 | return; | ||
998 | } | ||
953 | env = | 999 | env = |
954 | GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 1000 | GNUNET_MQ_msg(resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
955 | resume->cid = ch->cid; | 1001 | resume->cid = ch->cid; |
956 | GNUNET_MQ_send (line->mq, env); | 1002 | GNUNET_MQ_send(line->mq, env); |
957 | } | 1003 | } |
958 | 1004 | ||
959 | 1005 | ||
@@ -965,10 +1011,10 @@ handle_cadet_resume_message (void *cls, | |||
965 | * @return #GNUNET_OK (always) | 1011 | * @return #GNUNET_OK (always) |
966 | */ | 1012 | */ |
967 | static int | 1013 | static int |
968 | check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | 1014 | check_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) |
969 | { | 1015 | { |
970 | (void) cls; | 1016 | (void)cls; |
971 | (void) msg; | 1017 | (void)msg; |
972 | return GNUNET_OK; /* any payload is fine */ | 1018 | return GNUNET_OK; /* any payload is fine */ |
973 | } | 1019 | } |
974 | 1020 | ||
@@ -980,33 +1026,33 @@ check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | |||
980 | * @param msg the incoming message | 1026 | * @param msg the incoming message |
981 | */ | 1027 | */ |
982 | static void | 1028 | static void |
983 | handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | 1029 | handle_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) |
984 | { | 1030 | { |
985 | struct Channel *ch = cls; | 1031 | struct Channel *ch = cls; |
986 | size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage); | 1032 | size_t msize = ntohs(msg->header.size) - sizeof(struct CadetAudioMessage); |
987 | struct GNUNET_MQ_Envelope *env; | 1033 | struct GNUNET_MQ_Envelope *env; |
988 | struct ClientAudioMessage *cam; | 1034 | struct ClientAudioMessage *cam; |
989 | 1035 | ||
990 | GNUNET_CADET_receive_done (ch->channel); | 1036 | GNUNET_CADET_receive_done(ch->channel); |
991 | if ((GNUNET_YES == ch->suspended_local) || | 1037 | if ((GNUNET_YES == ch->suspended_local) || |
992 | (GNUNET_YES == ch->suspended_remote)) | 1038 | (GNUNET_YES == ch->suspended_remote)) |
993 | { | 1039 | { |
994 | GNUNET_log ( | 1040 | GNUNET_log( |
995 | GNUNET_ERROR_TYPE_DEBUG, | 1041 | GNUNET_ERROR_TYPE_DEBUG, |
996 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", | 1042 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", |
997 | (unsigned int) msize, | 1043 | (unsigned int)msize, |
998 | ch->cid); | 1044 | ch->cid); |
999 | return; | 1045 | return; |
1000 | } | 1046 | } |
1001 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1047 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1002 | "Forwarding %u bytes of AUDIO data to client CID %u\n", | 1048 | "Forwarding %u bytes of AUDIO data to client CID %u\n", |
1003 | (unsigned int) msize, | 1049 | (unsigned int)msize, |
1004 | ch->cid); | 1050 | ch->cid); |
1005 | env = | 1051 | env = |
1006 | GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 1052 | GNUNET_MQ_msg_extra(cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
1007 | cam->cid = ch->cid; | 1053 | cam->cid = ch->cid; |
1008 | GNUNET_memcpy (&cam[1], &msg[1], msize); | 1054 | GNUNET_memcpy(&cam[1], &msg[1], msize); |
1009 | GNUNET_MQ_send (ch->line->mq, env); | 1055 | GNUNET_MQ_send(ch->line->mq, env); |
1010 | } | 1056 | } |
1011 | 1057 | ||
1012 | 1058 | ||
@@ -1018,16 +1064,16 @@ handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) | |||
1018 | * @param channel connection to the other end (henceforth invalid) | 1064 | * @param channel connection to the other end (henceforth invalid) |
1019 | */ | 1065 | */ |
1020 | static void | 1066 | static void |
1021 | inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) | 1067 | inbound_end(void *cls, const struct GNUNET_CADET_Channel *channel) |
1022 | { | 1068 | { |
1023 | struct Channel *ch = cls; | 1069 | struct Channel *ch = cls; |
1024 | 1070 | ||
1025 | GNUNET_assert (channel == ch->channel); | 1071 | GNUNET_assert(channel == ch->channel); |
1026 | ch->channel = NULL; | 1072 | ch->channel = NULL; |
1027 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1073 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1028 | "Channel destroyed by CADET in state %d\n", | 1074 | "Channel destroyed by CADET in state %d\n", |
1029 | ch->status); | 1075 | ch->status); |
1030 | clean_up_channel (ch); | 1076 | clean_up_channel(ch); |
1031 | } | 1077 | } |
1032 | 1078 | ||
1033 | 1079 | ||
@@ -1038,63 +1084,63 @@ inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
1038 | * @param msg the message from the client | 1084 | * @param msg the message from the client |
1039 | */ | 1085 | */ |
1040 | static void | 1086 | static void |
1041 | handle_client_call_message (void *cls, const struct ClientCallMessage *msg) | 1087 | handle_client_call_message(void *cls, const struct ClientCallMessage *msg) |
1042 | { | 1088 | { |
1043 | struct Line *line = cls; | 1089 | struct Line *line = cls; |
1044 | struct Channel *ch = GNUNET_new (struct Channel); | 1090 | struct Channel *ch = GNUNET_new(struct Channel); |
1045 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1091 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1046 | {GNUNET_MQ_hd_fixed_size (cadet_hangup_message, | 1092 | { GNUNET_MQ_hd_fixed_size(cadet_hangup_message, |
1047 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1093 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1048 | struct CadetPhoneHangupMessage, | 1094 | struct CadetPhoneHangupMessage, |
1049 | ch), | 1095 | ch), |
1050 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, | 1096 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, |
1051 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | 1097 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, |
1052 | struct CadetPhonePickupMessage, | 1098 | struct CadetPhonePickupMessage, |
1053 | ch), | 1099 | ch), |
1054 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, | 1100 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, |
1055 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | 1101 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, |
1056 | struct CadetPhoneSuspendMessage, | 1102 | struct CadetPhoneSuspendMessage, |
1057 | ch), | 1103 | ch), |
1058 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, | 1104 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, |
1059 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | 1105 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, |
1060 | struct CadetPhoneResumeMessage, | 1106 | struct CadetPhoneResumeMessage, |
1061 | ch), | ||
1062 | GNUNET_MQ_hd_var_size (cadet_audio_message, | ||
1063 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1064 | struct CadetAudioMessage, | ||
1065 | ch), | 1107 | ch), |
1066 | GNUNET_MQ_handler_end ()}; | 1108 | GNUNET_MQ_hd_var_size(cadet_audio_message, |
1109 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1110 | struct CadetAudioMessage, | ||
1111 | ch), | ||
1112 | GNUNET_MQ_handler_end() }; | ||
1067 | struct GNUNET_MQ_Envelope *e; | 1113 | struct GNUNET_MQ_Envelope *e; |
1068 | struct CadetPhoneRingMessage *ring; | 1114 | struct CadetPhoneRingMessage *ring; |
1069 | struct CadetPhoneRingInfoPS rs; | 1115 | struct CadetPhoneRingInfoPS rs; |
1070 | 1116 | ||
1071 | line->line_port = msg->line_port; | 1117 | line->line_port = msg->line_port; |
1072 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 1118 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
1073 | rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); | 1119 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); |
1074 | rs.line_port = line->line_port; | 1120 | rs.line_port = line->line_port; |
1075 | rs.target_peer = msg->target; | 1121 | rs.target_peer = msg->target; |
1076 | rs.expiration_time = | 1122 | rs.expiration_time = |
1077 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); | 1123 | GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(RING_TIMEOUT)); |
1078 | ch->line = line; | 1124 | ch->line = line; |
1079 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); | 1125 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); |
1080 | ch->status = CS_CALLER_CALLING; | 1126 | ch->status = CS_CALLER_CALLING; |
1081 | ch->channel = GNUNET_CADET_channel_create (cadet, | 1127 | ch->channel = GNUNET_CADET_channel_create(cadet, |
1082 | ch, | 1128 | ch, |
1083 | &msg->target, | 1129 | &msg->target, |
1084 | &msg->line_port, | 1130 | &msg->line_port, |
1085 | NULL, | 1131 | NULL, |
1086 | &inbound_end, | 1132 | &inbound_end, |
1087 | cadet_handlers); | 1133 | cadet_handlers); |
1088 | ch->mq = GNUNET_CADET_get_mq (ch->channel); | 1134 | ch->mq = GNUNET_CADET_get_mq(ch->channel); |
1089 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); | 1135 | e = GNUNET_MQ_msg(ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); |
1090 | GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id); | 1136 | GNUNET_CRYPTO_ecdsa_key_get_public(&msg->caller_id, &ring->caller_id); |
1091 | ring->expiration_time = rs.expiration_time; | 1137 | ring->expiration_time = rs.expiration_time; |
1092 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, | 1138 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign(&msg->caller_id, |
1093 | &rs.purpose, | 1139 | &rs.purpose, |
1094 | &ring->signature)); | 1140 | &ring->signature)); |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); | 1141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); |
1096 | GNUNET_MQ_send (ch->mq, e); | 1142 | GNUNET_MQ_send(ch->mq, e); |
1097 | GNUNET_SERVICE_client_continue (line->client); | 1143 | GNUNET_SERVICE_client_continue(line->client); |
1098 | } | 1144 | } |
1099 | 1145 | ||
1100 | 1146 | ||
@@ -1108,24 +1154,24 @@ handle_client_call_message (void *cls, const struct ClientCallMessage *msg) | |||
1108 | * @return initial channel context for the channel | 1154 | * @return initial channel context for the channel |
1109 | */ | 1155 | */ |
1110 | static void * | 1156 | static void * |
1111 | inbound_channel (void *cls, | 1157 | inbound_channel(void *cls, |
1112 | struct GNUNET_CADET_Channel *channel, | 1158 | struct GNUNET_CADET_Channel *channel, |
1113 | const struct GNUNET_PeerIdentity *initiator) | 1159 | const struct GNUNET_PeerIdentity *initiator) |
1114 | { | 1160 | { |
1115 | struct Line *line = cls; | 1161 | struct Line *line = cls; |
1116 | struct Channel *ch; | 1162 | struct Channel *ch; |
1117 | 1163 | ||
1118 | (void) initiator; | 1164 | (void)initiator; |
1119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1165 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1120 | "Received incoming cadet channel on line %p\n", | 1166 | "Received incoming cadet channel on line %p\n", |
1121 | line); | 1167 | line); |
1122 | ch = GNUNET_new (struct Channel); | 1168 | ch = GNUNET_new(struct Channel); |
1123 | ch->status = CS_CALLEE_INIT; | 1169 | ch->status = CS_CALLEE_INIT; |
1124 | ch->line = line; | 1170 | ch->line = line; |
1125 | ch->channel = channel; | 1171 | ch->channel = channel; |
1126 | ch->mq = GNUNET_CADET_get_mq (ch->channel); | 1172 | ch->mq = GNUNET_CADET_get_mq(ch->channel); |
1127 | ch->cid = line->cid_gen++; | 1173 | ch->cid = line->cid_gen++; |
1128 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); | 1174 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); |
1129 | return ch; | 1175 | return ch; |
1130 | } | 1176 | } |
1131 | 1177 | ||
@@ -1139,14 +1185,14 @@ inbound_channel (void *cls, | |||
1139 | * @return the `struct Line` for the client | 1185 | * @return the `struct Line` for the client |
1140 | */ | 1186 | */ |
1141 | static void * | 1187 | static void * |
1142 | client_connect_cb (void *cls, | 1188 | client_connect_cb(void *cls, |
1143 | struct GNUNET_SERVICE_Client *client, | 1189 | struct GNUNET_SERVICE_Client *client, |
1144 | struct GNUNET_MQ_Handle *mq) | 1190 | struct GNUNET_MQ_Handle *mq) |
1145 | { | 1191 | { |
1146 | struct Line *line; | 1192 | struct Line *line; |
1147 | 1193 | ||
1148 | (void) cls; | 1194 | (void)cls; |
1149 | line = GNUNET_new (struct Line); | 1195 | line = GNUNET_new(struct Line); |
1150 | line->client = client; | 1196 | line->client = client; |
1151 | line->mq = mq; | 1197 | line->mq = mq; |
1152 | return line; | 1198 | return line; |
@@ -1161,28 +1207,28 @@ client_connect_cb (void *cls, | |||
1161 | * @param app_ctx our `struct Line *` for @a client | 1207 | * @param app_ctx our `struct Line *` for @a client |
1162 | */ | 1208 | */ |
1163 | static void | 1209 | static void |
1164 | client_disconnect_cb (void *cls, | 1210 | client_disconnect_cb(void *cls, |
1165 | struct GNUNET_SERVICE_Client *client, | 1211 | struct GNUNET_SERVICE_Client *client, |
1166 | void *app_ctx) | 1212 | void *app_ctx) |
1167 | { | 1213 | { |
1168 | struct Line *line = app_ctx; | 1214 | struct Line *line = app_ctx; |
1169 | struct Channel *chn; | 1215 | struct Channel *chn; |
1170 | 1216 | ||
1171 | (void) cls; | 1217 | (void)cls; |
1172 | (void) client; | 1218 | (void)client; |
1173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); | 1219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); |
1174 | if (NULL != line->port) | 1220 | if (NULL != line->port) |
1175 | { | 1221 | { |
1176 | GNUNET_CADET_close_port (line->port); | 1222 | GNUNET_CADET_close_port(line->port); |
1177 | line->port = NULL; | 1223 | line->port = NULL; |
1178 | } | 1224 | } |
1179 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) | 1225 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) |
1180 | { | 1226 | { |
1181 | chn = ch->next; | 1227 | chn = ch->next; |
1182 | ch->line = NULL; | 1228 | ch->line = NULL; |
1183 | destroy_line_cadet_channels (ch); | 1229 | destroy_line_cadet_channels(ch); |
1184 | } | 1230 | } |
1185 | GNUNET_free (line); | 1231 | GNUNET_free(line); |
1186 | } | 1232 | } |
1187 | 1233 | ||
1188 | 1234 | ||
@@ -1193,54 +1239,54 @@ client_disconnect_cb (void *cls, | |||
1193 | * @param msg the message from the client | 1239 | * @param msg the message from the client |
1194 | */ | 1240 | */ |
1195 | static void | 1241 | static void |
1196 | handle_client_register_message (void *cls, | 1242 | handle_client_register_message(void *cls, |
1197 | const struct ClientPhoneRegisterMessage *msg) | 1243 | const struct ClientPhoneRegisterMessage *msg) |
1198 | { | 1244 | { |
1199 | struct Line *line = cls; | 1245 | struct Line *line = cls; |
1200 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1246 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1201 | {GNUNET_MQ_hd_fixed_size (cadet_ring_message, | 1247 | { GNUNET_MQ_hd_fixed_size(cadet_ring_message, |
1202 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, | 1248 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, |
1203 | struct CadetPhoneRingMessage, | 1249 | struct CadetPhoneRingMessage, |
1204 | NULL), | 1250 | NULL), |
1205 | GNUNET_MQ_hd_fixed_size (cadet_hangup_message, | 1251 | GNUNET_MQ_hd_fixed_size(cadet_hangup_message, |
1206 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1252 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1207 | struct CadetPhoneHangupMessage, | 1253 | struct CadetPhoneHangupMessage, |
1208 | NULL), | ||
1209 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, | ||
1210 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | ||
1211 | struct CadetPhonePickupMessage, | ||
1212 | NULL), | ||
1213 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, | ||
1214 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | ||
1215 | struct CadetPhoneSuspendMessage, | ||
1216 | NULL), | ||
1217 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, | ||
1218 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | ||
1219 | struct CadetPhoneResumeMessage, | ||
1220 | NULL), | ||
1221 | GNUNET_MQ_hd_var_size (cadet_audio_message, | ||
1222 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1223 | struct CadetAudioMessage, | ||
1224 | NULL), | 1254 | NULL), |
1225 | GNUNET_MQ_handler_end ()}; | 1255 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, |
1256 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | ||
1257 | struct CadetPhonePickupMessage, | ||
1258 | NULL), | ||
1259 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, | ||
1260 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | ||
1261 | struct CadetPhoneSuspendMessage, | ||
1262 | NULL), | ||
1263 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, | ||
1264 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | ||
1265 | struct CadetPhoneResumeMessage, | ||
1266 | NULL), | ||
1267 | GNUNET_MQ_hd_var_size(cadet_audio_message, | ||
1268 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | ||
1269 | struct CadetAudioMessage, | ||
1270 | NULL), | ||
1271 | GNUNET_MQ_handler_end() }; | ||
1226 | 1272 | ||
1227 | line->line_port = msg->line_port; | 1273 | line->line_port = msg->line_port; |
1228 | line->port = GNUNET_CADET_open_port (cadet, | 1274 | line->port = GNUNET_CADET_open_port(cadet, |
1229 | &msg->line_port, | 1275 | &msg->line_port, |
1230 | &inbound_channel, | 1276 | &inbound_channel, |
1231 | line, | 1277 | line, |
1232 | NULL, | 1278 | NULL, |
1233 | &inbound_end, | 1279 | &inbound_end, |
1234 | cadet_handlers); | 1280 | cadet_handlers); |
1235 | if (NULL == line->port) | 1281 | if (NULL == line->port) |
1236 | { | 1282 | { |
1237 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1283 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1238 | _ ("Could not open line, port %s already in use!\n"), | 1284 | _("Could not open line, port %s already in use!\n"), |
1239 | GNUNET_h2s (&msg->line_port)); | 1285 | GNUNET_h2s(&msg->line_port)); |
1240 | GNUNET_SERVICE_client_drop (line->client); | 1286 | GNUNET_SERVICE_client_drop(line->client); |
1241 | return; | 1287 | return; |
1242 | } | 1288 | } |
1243 | GNUNET_SERVICE_client_continue (line->client); | 1289 | GNUNET_SERVICE_client_continue(line->client); |
1244 | } | 1290 | } |
1245 | 1291 | ||
1246 | 1292 | ||
@@ -1250,14 +1296,14 @@ handle_client_register_message (void *cls, | |||
1250 | * @param cls closure, NULL | 1296 | * @param cls closure, NULL |
1251 | */ | 1297 | */ |
1252 | static void | 1298 | static void |
1253 | do_shutdown (void *cls) | 1299 | do_shutdown(void *cls) |
1254 | { | 1300 | { |
1255 | (void) cls; | 1301 | (void)cls; |
1256 | if (NULL != cadet) | 1302 | if (NULL != cadet) |
1257 | { | 1303 | { |
1258 | GNUNET_CADET_disconnect (cadet); | 1304 | GNUNET_CADET_disconnect(cadet); |
1259 | cadet = NULL; | 1305 | cadet = NULL; |
1260 | } | 1306 | } |
1261 | } | 1307 | } |
1262 | 1308 | ||
1263 | 1309 | ||
@@ -1269,65 +1315,65 @@ do_shutdown (void *cls) | |||
1269 | * @param service service handle | 1315 | * @param service service handle |
1270 | */ | 1316 | */ |
1271 | static void | 1317 | static void |
1272 | run (void *cls, | 1318 | run(void *cls, |
1273 | const struct GNUNET_CONFIGURATION_Handle *c, | 1319 | const struct GNUNET_CONFIGURATION_Handle *c, |
1274 | struct GNUNET_SERVICE_Handle *service) | 1320 | struct GNUNET_SERVICE_Handle *service) |
1275 | { | 1321 | { |
1276 | (void) cls; | 1322 | (void)cls; |
1277 | (void) service; | 1323 | (void)service; |
1278 | cfg = c; | 1324 | cfg = c; |
1279 | GNUNET_assert (GNUNET_OK == | 1325 | GNUNET_assert(GNUNET_OK == |
1280 | GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity)); | 1326 | GNUNET_CRYPTO_get_peer_identity(cfg, &my_identity)); |
1281 | cadet = GNUNET_CADET_connect (cfg); | 1327 | cadet = GNUNET_CADET_connect(cfg); |
1282 | if (NULL == cadet) | 1328 | if (NULL == cadet) |
1283 | { | 1329 | { |
1284 | GNUNET_break (0); | 1330 | GNUNET_break(0); |
1285 | GNUNET_SCHEDULER_shutdown (); | 1331 | GNUNET_SCHEDULER_shutdown(); |
1286 | return; | 1332 | return; |
1287 | } | 1333 | } |
1288 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1334 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
1289 | } | 1335 | } |
1290 | 1336 | ||
1291 | 1337 | ||
1292 | /** | 1338 | /** |
1293 | * Define "main" method using service macro. | 1339 | * Define "main" method using service macro. |
1294 | */ | 1340 | */ |
1295 | GNUNET_SERVICE_MAIN ( | 1341 | GNUNET_SERVICE_MAIN( |
1296 | "conversation", | 1342 | "conversation", |
1297 | GNUNET_SERVICE_OPTION_NONE, | 1343 | GNUNET_SERVICE_OPTION_NONE, |
1298 | &run, | 1344 | &run, |
1299 | &client_connect_cb, | 1345 | &client_connect_cb, |
1300 | &client_disconnect_cb, | 1346 | &client_disconnect_cb, |
1301 | NULL, | 1347 | NULL, |
1302 | GNUNET_MQ_hd_fixed_size (client_register_message, | 1348 | GNUNET_MQ_hd_fixed_size(client_register_message, |
1303 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, | 1349 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, |
1304 | struct ClientPhoneRegisterMessage, | 1350 | struct ClientPhoneRegisterMessage, |
1305 | NULL), | 1351 | NULL), |
1306 | GNUNET_MQ_hd_fixed_size (client_pickup_message, | 1352 | GNUNET_MQ_hd_fixed_size(client_pickup_message, |
1307 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, | 1353 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, |
1308 | struct ClientPhonePickupMessage, | 1354 | struct ClientPhonePickupMessage, |
1309 | NULL), | 1355 | NULL), |
1310 | GNUNET_MQ_hd_fixed_size (client_suspend_message, | 1356 | GNUNET_MQ_hd_fixed_size(client_suspend_message, |
1311 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 1357 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
1312 | struct ClientPhoneSuspendMessage, | 1358 | struct ClientPhoneSuspendMessage, |
1313 | NULL), | 1359 | NULL), |
1314 | GNUNET_MQ_hd_fixed_size (client_resume_message, | 1360 | GNUNET_MQ_hd_fixed_size(client_resume_message, |
1315 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 1361 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
1316 | struct ClientPhoneResumeMessage, | 1362 | struct ClientPhoneResumeMessage, |
1317 | NULL), | 1363 | NULL), |
1318 | GNUNET_MQ_hd_fixed_size (client_hangup_message, | 1364 | GNUNET_MQ_hd_fixed_size(client_hangup_message, |
1319 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 1365 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
1320 | struct ClientPhoneHangupMessage, | 1366 | struct ClientPhoneHangupMessage, |
1321 | NULL), | 1367 | NULL), |
1322 | GNUNET_MQ_hd_fixed_size (client_call_message, | 1368 | GNUNET_MQ_hd_fixed_size(client_call_message, |
1323 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, | 1369 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, |
1324 | struct ClientCallMessage, | 1370 | struct ClientCallMessage, |
1325 | NULL), | 1371 | NULL), |
1326 | GNUNET_MQ_hd_var_size (client_audio_message, | 1372 | GNUNET_MQ_hd_var_size(client_audio_message, |
1327 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 1373 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
1328 | struct ClientAudioMessage, | 1374 | struct ClientAudioMessage, |
1329 | NULL), | 1375 | NULL), |
1330 | GNUNET_MQ_handler_end ()); | 1376 | GNUNET_MQ_handler_end()); |
1331 | 1377 | ||
1332 | 1378 | ||
1333 | /* end of gnunet-service-conversation.c */ | 1379 | /* end of gnunet-service-conversation.c */ |
diff --git a/src/conversation/gnunet_gst.c b/src/conversation/gnunet_gst.c index c08468996..5db0d350c 100644 --- a/src/conversation/gnunet_gst.c +++ b/src/conversation/gnunet_gst.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2016 GNUnet e.V. | 3 | Copyright (C) 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet_gst.c | 21 | * @file conversation/gnunet_gst.c |
22 | * @brief FIXME | 22 | * @brief FIXME |
@@ -38,23 +38,26 @@ dump_buffer(unsigned n, const unsigned char* buf) | |||
38 | 38 | ||
39 | end = buf + n; | 39 | end = buf + n; |
40 | 40 | ||
41 | for (i = 0; ; i += 16) { | 41 | for (i = 0; ; i += 16) |
42 | p = buf + i; | 42 | { |
43 | for (j = 0; j < 16; j++) { | 43 | p = buf + i; |
44 | fprintf(stderr, "%02X ", p[j]); | 44 | for (j = 0; j < 16; j++) |
45 | if (p + j >= end) | 45 | { |
46 | goto BREAKOUT; | 46 | fprintf(stderr, "%02X ", p[j]); |
47 | } | 47 | if (p + j >= end) |
48 | fprintf(stderr, " "); | 48 | goto BREAKOUT; |
49 | p = buf + i; | 49 | } |
50 | for (j = 0; j < 16; j++) { | 50 | fprintf(stderr, " "); |
51 | fprintf(stderr, "%c", isprint(p[j]) ? p[j] : | 51 | p = buf + i; |
52 | '.'); | 52 | for (j = 0; j < 16; j++) |
53 | if (p + j >= end) | 53 | { |
54 | goto BREAKOUT; | 54 | fprintf(stderr, "%c", isprint(p[j]) ? p[j] : |
55 | '.'); | ||
56 | if (p + j >= end) | ||
57 | goto BREAKOUT; | ||
58 | } | ||
59 | fprintf(stderr, "\n"); | ||
55 | } | 60 | } |
56 | fprintf(stderr, "\n"); | ||
57 | } | ||
58 | BREAKOUT: | 61 | BREAKOUT: |
59 | return; | 62 | return; |
60 | } | 63 | } |
@@ -66,7 +69,8 @@ void | |||
66 | gg_load_configuration(GNUNET_gstData * d) | 69 | gg_load_configuration(GNUNET_gstData * d) |
67 | { | 70 | { |
68 | char *audiobackend_string; | 71 | char *audiobackend_string; |
69 | cfg = GNUNET_CONFIGURATION_create(); | 72 | |
73 | cfg = GNUNET_CONFIGURATION_create(); | ||
70 | GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); | 74 | GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); |
71 | 75 | ||
72 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in); | 76 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in); |
@@ -74,77 +78,88 @@ gg_load_configuration(GNUNET_gstData * d) | |||
74 | 78 | ||
75 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); | 79 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); |
76 | 80 | ||
77 | // printf("abstring: %s \n", audiobackend_string); | 81 | // printf("abstring: %s \n", audiobackend_string); |
78 | 82 | ||
79 | if (0 == strcasecmp (audiobackend_string, "AUTO")) | 83 | if (0 == strcasecmp(audiobackend_string, "AUTO")) |
80 | { | 84 | { |
81 | d->audiobackend = AUTO; | 85 | d->audiobackend = AUTO; |
82 | } else if (0 == strcasecmp (audiobackend_string, "JACK")) | 86 | } |
83 | { | 87 | else if (0 == strcasecmp(audiobackend_string, "JACK")) |
84 | d->audiobackend = JACK; | 88 | { |
85 | } else if (0 == strcasecmp (audiobackend_string, "ALSA")) | 89 | d->audiobackend = JACK; |
86 | { | 90 | } |
87 | d->audiobackend = ALSA; | 91 | else if (0 == strcasecmp(audiobackend_string, "ALSA")) |
88 | } else if (0 == strcasecmp (audiobackend_string, "FAKE")) | 92 | { |
89 | { | 93 | d->audiobackend = ALSA; |
90 | d->audiobackend = FAKE; | 94 | } |
91 | } else if (0 == strcasecmp (audiobackend_string, "TEST")) | 95 | else if (0 == strcasecmp(audiobackend_string, "FAKE")) |
92 | { | 96 | { |
93 | d->audiobackend = TEST; | 97 | d->audiobackend = FAKE; |
94 | } else | 98 | } |
95 | { | 99 | else if (0 == strcasecmp(audiobackend_string, "TEST")) |
96 | d->audiobackend = AUTO; | 100 | { |
97 | } | 101 | d->audiobackend = TEST; |
102 | } | ||
103 | else | ||
104 | { | ||
105 | d->audiobackend = AUTO; | ||
106 | } | ||
98 | 107 | ||
99 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) | 108 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) |
100 | { | 109 | { |
101 | d->dropsilence = TRUE; | 110 | d->dropsilence = TRUE; |
102 | } else { | 111 | } |
103 | d->dropsilence = FALSE; | 112 | else |
104 | } | 113 | { |
114 | d->dropsilence = FALSE; | ||
115 | } | ||
105 | 116 | ||
106 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) | 117 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) |
107 | { | 118 | { |
108 | d->pure_ogg = TRUE; | 119 | d->pure_ogg = TRUE; |
109 | } else { | 120 | } |
110 | d->pure_ogg = FALSE; | 121 | else |
111 | } | 122 | { |
123 | d->pure_ogg = FALSE; | ||
124 | } | ||
112 | 125 | ||
113 | 126 | ||
114 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) | 127 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) |
115 | { | 128 | { |
116 | d->usertp = TRUE; | 129 | d->usertp = TRUE; |
117 | } else { | 130 | } |
118 | d->usertp = FALSE; | 131 | else |
119 | } | 132 | { |
133 | d->usertp = FALSE; | ||
134 | } | ||
120 | 135 | ||
121 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); | 136 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); |
122 | |||
123 | } | 137 | } |
124 | 138 | ||
125 | static void | 139 | static void |
126 | write_data (const char *ptr, size_t msg_size) | 140 | write_data(const char *ptr, size_t msg_size) |
127 | { | 141 | { |
128 | ssize_t ret; | 142 | ssize_t ret; |
129 | size_t off; | 143 | size_t off; |
144 | |||
130 | off = 0; | 145 | off = 0; |
131 | while (off < msg_size) | 146 | while (off < msg_size) |
132 | { | ||
133 | ret = write (1, &ptr[off], msg_size - off); | ||
134 | if (0 >= ret) | ||
135 | { | 147 | { |
136 | if (-1 == ret) | 148 | ret = write(1, &ptr[off], msg_size - off); |
137 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write"); | 149 | if (0 >= ret) |
150 | { | ||
151 | if (-1 == ret) | ||
152 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "write"); | ||
138 | // quit (2); | 153 | // quit (2); |
154 | } | ||
155 | off += ret; | ||
139 | } | 156 | } |
140 | off += ret; | ||
141 | } | ||
142 | } | 157 | } |
143 | 158 | ||
144 | 159 | ||
145 | 160 | ||
146 | extern GstFlowReturn | 161 | extern GstFlowReturn |
147 | on_appsink_new_sample (GstElement * element, GNUNET_gstData * d) | 162 | on_appsink_new_sample(GstElement * element, GNUNET_gstData * d) |
148 | { | 163 | { |
149 | //size of message including gnunet header | 164 | //size of message including gnunet header |
150 | size_t msg_size; | 165 | size_t msg_size; |
@@ -152,72 +167,70 @@ on_appsink_new_sample (GstElement * element, GNUNET_gstData * d) | |||
152 | GstSample *s; | 167 | GstSample *s; |
153 | GstBuffer *b; | 168 | GstBuffer *b; |
154 | GstMapInfo map; | 169 | GstMapInfo map; |
170 | |||
155 | /* | 171 | /* |
156 | const GstStructure *si; | 172 | const GstStructure *si; |
157 | char *si_str; | 173 | char *si_str; |
158 | GstCaps *s_caps; | 174 | GstCaps *s_caps; |
159 | char *caps_str; | 175 | char *caps_str; |
160 | */ | 176 | */ |
161 | 177 | ||
162 | if (gst_app_sink_is_eos(GST_APP_SINK(element))) | 178 | if (gst_app_sink_is_eos(GST_APP_SINK(element))) |
163 | return GST_FLOW_OK; | 179 | return GST_FLOW_OK; |
164 | 180 | ||
165 | //pull sample from appsink | 181 | //pull sample from appsink |
166 | s = gst_app_sink_pull_sample (GST_APP_SINK(element)); | 182 | s = gst_app_sink_pull_sample(GST_APP_SINK(element)); |
167 | 183 | ||
168 | if (s == NULL) | 184 | if (s == NULL) |
169 | return GST_FLOW_OK; | 185 | return GST_FLOW_OK; |
170 | 186 | ||
171 | if (!GST_IS_SAMPLE (s)) | 187 | if (!GST_IS_SAMPLE(s)) |
172 | return GST_FLOW_OK; | 188 | return GST_FLOW_OK; |
173 | 189 | ||
174 | b = gst_sample_get_buffer(s); | 190 | b = gst_sample_get_buffer(s); |
175 | 191 | ||
176 | GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s)); | 192 | GST_WARNING("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s)); |
177 | 193 | ||
178 | 194 | ||
179 | 195 | ||
180 | gst_buffer_map (b, &map, GST_MAP_READ); | 196 | gst_buffer_map(b, &map, GST_MAP_READ); |
181 | 197 | ||
182 | size_t len; | 198 | size_t len; |
183 | len = map.size; | 199 | len = map.size; |
184 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 200 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) |
185 | { | 201 | { |
186 | // this should never happen? | 202 | // this should never happen? |
187 | printf("GSTREAMER sample too big! \n"); | 203 | printf("GSTREAMER sample too big! \n"); |
188 | exit(20); | 204 | exit(20); |
189 | len = UINT16_MAX - sizeof (struct AudioMessage); | 205 | len = UINT16_MAX - sizeof(struct AudioMessage); |
190 | } | 206 | } |
191 | 207 | ||
192 | msg_size = sizeof (struct AudioMessage) + len; | 208 | msg_size = sizeof(struct AudioMessage) + len; |
193 | 209 | ||
194 | // copy the data into audio_message | 210 | // copy the data into audio_message |
195 | GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len); | 211 | GNUNET_memcpy(((char *)&(d->audio_message)[1]), map.data, len); |
196 | (d->audio_message)->header.size = htons ((uint16_t) msg_size); | 212 | (d->audio_message)->header.size = htons((uint16_t)msg_size); |
197 | if (d->pure_ogg) | 213 | if (d->pure_ogg) |
198 | // write the audio_message without the gnunet headers | 214 | // write the audio_message without the gnunet headers |
199 | write_data ((const char *) &(d->audio_message)[1], len); | 215 | write_data((const char *)&(d->audio_message)[1], len); |
200 | else | 216 | else |
201 | write_data ((const char *) d->audio_message, msg_size); | 217 | write_data((const char *)d->audio_message, msg_size); |
202 | 218 | ||
203 | gst_sample_unref(s); | 219 | gst_sample_unref(s); |
204 | return GST_FLOW_OK; | 220 | return GST_FLOW_OK; |
205 | } | 221 | } |
206 | 222 | ||
207 | /*** | 223 | /*** |
208 | * Dump a pipeline graph | 224 | * Dump a pipeline graph |
209 | */ | 225 | */ |
210 | extern void | 226 | extern void |
211 | pl_graph(GstElement * pipeline) | 227 | pl_graph(GstElement * pipeline) |
212 | { | 228 | { |
213 | |||
214 | #ifdef IS_SPEAKER | 229 | #ifdef IS_SPEAKER |
215 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot"); | 230 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot"); |
216 | |||
217 | #endif | 231 | #endif |
218 | #ifdef IS_MIC | 232 | #ifdef IS_MIC |
219 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot"); | 233 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot"); |
220 | |||
221 | #endif | 234 | #endif |
222 | 235 | ||
223 | 236 | ||
@@ -227,142 +240,145 @@ pl_graph(GstElement * pipeline) | |||
227 | 240 | ||
228 | 241 | ||
229 | extern gboolean | 242 | extern gboolean |
230 | gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data) | 243 | gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) |
231 | { | 244 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
233 | "Bus message\n"); | 246 | "Bus message\n"); |
234 | switch (GST_MESSAGE_TYPE (msg)) | 247 | switch (GST_MESSAGE_TYPE(msg)) |
235 | { | 248 | { |
236 | case GST_MESSAGE_EOS: | 249 | case GST_MESSAGE_EOS: |
237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 250 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
238 | "End of stream\n"); | 251 | "End of stream\n"); |
239 | exit (10); | 252 | exit(10); |
240 | break; | 253 | break; |
241 | 254 | ||
242 | case GST_MESSAGE_ERROR: | 255 | case GST_MESSAGE_ERROR: |
243 | { | 256 | { |
244 | gchar *debug; | 257 | gchar *debug; |
245 | GError *error; | 258 | GError *error; |
246 | 259 | ||
247 | gst_message_parse_error (msg, &error, &debug); | 260 | gst_message_parse_error(msg, &error, &debug); |
248 | g_free (debug); | 261 | g_free(debug); |
249 | 262 | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 263 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
251 | "Error: %s\n", | 264 | "Error: %s\n", |
252 | error->message); | 265 | error->message); |
253 | g_error_free (error); | 266 | g_error_free(error); |
254 | 267 | ||
255 | exit (10); | 268 | exit(10); |
269 | break; | ||
270 | } | ||
271 | |||
272 | default: | ||
256 | break; | 273 | break; |
257 | } | 274 | } |
258 | default: | ||
259 | break; | ||
260 | } | ||
261 | 275 | ||
262 | return TRUE; | 276 | return TRUE; |
263 | } | 277 | } |
264 | 278 | ||
265 | /* called when pipeline changes state */ | 279 | /* called when pipeline changes state */ |
266 | extern void | 280 | extern void |
267 | state_changed_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * d) | 281 | state_changed_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * d) |
268 | { | 282 | { |
269 | GstState old_state, new_state, pending_state; | 283 | GstState old_state, new_state, pending_state; |
270 | 284 | ||
271 | gst_message_parse_state_changed (msg, &old_state, &new_state, | 285 | gst_message_parse_state_changed(msg, &old_state, &new_state, |
272 | &pending_state); | 286 | &pending_state); |
273 | switch (new_state) | 287 | switch (new_state) |
274 | { | 288 | { |
275 | |||
276 | case GST_STATE_READY: | 289 | case GST_STATE_READY: |
277 | // printf("ready.... \n"); | 290 | // printf("ready.... \n"); |
278 | //pl_graph(GST_ELEMENT(d->pipeline)); | 291 | //pl_graph(GST_ELEMENT(d->pipeline)); |
279 | break; | 292 | break; |
293 | |||
280 | case GST_STATE_PLAYING: | 294 | case GST_STATE_PLAYING: |
281 | 295 | ||
282 | //GST_LOG ("caps are %" GST_PTR_FORMAT, caps); | 296 | //GST_LOG ("caps are %" GST_PTR_FORMAT, caps); |
283 | 297 | ||
284 | // printf("Playing.... \n"); | 298 | // printf("Playing.... \n"); |
285 | pl_graph(GST_ELEMENT(d->pipeline)); | 299 | pl_graph(GST_ELEMENT(d->pipeline)); |
286 | break; | 300 | break; |
301 | |||
287 | case GST_STATE_VOID_PENDING: | 302 | case GST_STATE_VOID_PENDING: |
288 | // printf("void_pending.... \n"); | 303 | // printf("void_pending.... \n"); |
289 | //pl_graph(GST_ELEMENT(d->pipeline)); | 304 | //pl_graph(GST_ELEMENT(d->pipeline)); |
290 | break; | 305 | break; |
306 | |||
291 | case GST_STATE_NULL: | 307 | case GST_STATE_NULL: |
292 | // printf("null.... \n"); | 308 | // printf("null.... \n"); |
293 | //pl_graph(GST_ELEMENT(d->pipeline)); | 309 | //pl_graph(GST_ELEMENT(d->pipeline)); |
294 | break; | 310 | break; |
295 | 311 | ||
296 | case GST_STATE_PAUSED: | 312 | case GST_STATE_PAUSED: |
297 | // printf("paused.... \n"); | 313 | // printf("paused.... \n"); |
298 | //pl_graph(GST_ELEMENT(d->pipeline)); | 314 | //pl_graph(GST_ELEMENT(d->pipeline)); |
299 | break; | 315 | break; |
300 | } | 316 | } |
301 | } | 317 | } |
302 | 318 | ||
303 | static void | 319 | static void |
304 | application_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 320 | application_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
305 | { | 321 | { |
306 | // printf("application cb"); | 322 | // printf("application cb"); |
307 | return; | 323 | return; |
308 | } | 324 | } |
309 | 325 | ||
310 | static void | 326 | static void |
311 | error_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 327 | error_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
312 | { | 328 | { |
313 | // printf("error cb"); | 329 | // printf("error cb"); |
314 | return; | 330 | return; |
315 | } | 331 | } |
316 | 332 | ||
317 | static void | 333 | static void |
318 | eos_cb (GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 334 | eos_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) |
319 | { | 335 | { |
320 | // printf("eos cb"); | 336 | // printf("eos cb"); |
321 | return; | 337 | return; |
322 | } | 338 | } |
323 | 339 | ||
324 | extern void | 340 | extern void |
325 | gg_setup_gst_bus (GNUNET_gstData * d) | 341 | gg_setup_gst_bus(GNUNET_gstData * d) |
326 | { | 342 | { |
327 | GstBus *bus; | 343 | GstBus *bus; |
328 | bus = gst_element_get_bus (GST_ELEMENT(d->pipeline)); | ||
329 | gst_bus_add_signal_watch (bus); | ||
330 | g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb, | ||
331 | d); | ||
332 | g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, | ||
333 | d); | ||
334 | g_signal_connect (G_OBJECT (bus), "message::state-changed", | ||
335 | (GCallback) state_changed_cb, d); | ||
336 | g_signal_connect (G_OBJECT (bus), "message::application", | ||
337 | (GCallback) application_cb, d); | ||
338 | g_signal_connect (G_OBJECT (bus), "message::about-to-finish", | ||
339 | (GCallback) application_cb, d); | ||
340 | gst_object_unref (bus); | ||
341 | 344 | ||
345 | bus = gst_element_get_bus(GST_ELEMENT(d->pipeline)); | ||
346 | gst_bus_add_signal_watch(bus); | ||
347 | g_signal_connect(G_OBJECT(bus), "message::error", (GCallback)error_cb, | ||
348 | d); | ||
349 | g_signal_connect(G_OBJECT(bus), "message::eos", (GCallback)eos_cb, | ||
350 | d); | ||
351 | g_signal_connect(G_OBJECT(bus), "message::state-changed", | ||
352 | (GCallback)state_changed_cb, d); | ||
353 | g_signal_connect(G_OBJECT(bus), "message::application", | ||
354 | (GCallback)application_cb, d); | ||
355 | g_signal_connect(G_OBJECT(bus), "message::about-to-finish", | ||
356 | (GCallback)application_cb, d); | ||
357 | gst_object_unref(bus); | ||
342 | } | 358 | } |
343 | 359 | ||
344 | /* | 360 | /* |
345 | * take buffer from gstreamer and feed it to gnunet | 361 | * take buffer from gstreamer and feed it to gnunet |
346 | */ | 362 | */ |
347 | /* | 363 | /* |
348 | extern int | 364 | extern int |
349 | feed_buffer_to_gnunet (GNUNET_gstData * d) | 365 | feed_buffer_to_gnunet (GNUNET_gstData * d) |
350 | { | 366 | { |
351 | GstSample *s; | 367 | GstSample *s; |
352 | GstBuffer *b; | 368 | GstBuffer *b; |
353 | GstMapInfo m; | 369 | GstMapInfo m; |
354 | size_t len, msg_size; | 370 | size_t len, msg_size; |
355 | const char *ptr; | 371 | const char *ptr; |
356 | int phase; | 372 | int phase; |
357 | 373 | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); | 374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); |
359 | s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink)); | 375 | s = gst_app_sink_pull_sample (GST_APP_SINK(d->appsink)); |
360 | if (NULL == s) | 376 | if (NULL == s) |
361 | { | 377 | { |
362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); |
363 | return OK; | 379 | return OK; |
364 | } | 380 | } |
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); | 381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); |
366 | 382 | ||
367 | const GstStructure *si; | 383 | const GstStructure *si; |
368 | char *si_str; | 384 | char *si_str; |
@@ -393,39 +409,39 @@ feed_buffer_to_gnunet (GNUNET_gstData * d) | |||
393 | else | 409 | else |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); |
395 | 411 | ||
396 | b = gst_sample_get_buffer (s); | 412 | b = gst_sample_get_buffer (s); |
397 | if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) | 413 | if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) |
398 | { | 414 | { |
399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); |
400 | gst_sample_unref (s); | 416 | gst_sample_unref (s); |
401 | return FAIL; | 417 | return FAIL; |
402 | } | 418 | } |
403 | 419 | ||
404 | len = m.size; | 420 | len = m.size; |
405 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) | 421 | if (len > UINT16_MAX - sizeof (struct AudioMessage)) |
406 | { | 422 | { |
407 | GNUNET_break (0); | 423 | GNUNET_break (0); |
408 | len = UINT16_MAX - sizeof (struct AudioMessage); | 424 | len = UINT16_MAX - sizeof (struct AudioMessage); |
409 | } | 425 | } |
410 | msg_size = sizeof (struct AudioMessage) + len; | 426 | msg_size = sizeof (struct AudioMessage) + len; |
411 | audio_message.header.size = htons ((uint16_t) msg_size); | 427 | audio_message.header.size = htons ((uint16_t) msg_size); |
412 | 428 | ||
413 | 429 | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
415 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); | 431 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); |
416 | for (phase = 0; phase < 2; phase++) | 432 | for (phase = 0; phase < 2; phase++) |
417 | { | 433 | { |
418 | size_t offset; | 434 | size_t offset; |
419 | size_t to_send; | 435 | size_t to_send; |
420 | ssize_t ret; | 436 | ssize_t ret; |
421 | if (0 == phase && !d->pure_ogg) | 437 | if (0 == phase && !d->pure_ogg) |
422 | { | 438 | { |
423 | //#ifdef DEBUG_RECORD_PURE_OGG | 439 | //#ifdef DEBUG_RECORD_PURE_OGG |
424 | 440 | ||
425 | // if (d->pure_ogg) | 441 | // if (d->pure_ogg) |
426 | // break; | 442 | // break; |
427 | 443 | ||
428 | //#endif | 444 | //#endif |
429 | ptr = (const char *) &audio_message; | 445 | ptr = (const char *) &audio_message; |
430 | to_send = sizeof (audio_message); | 446 | to_send = sizeof (audio_message); |
431 | } | 447 | } |
@@ -451,65 +467,68 @@ feed_buffer_to_gnunet (GNUNET_gstData * d) | |||
451 | } | 467 | } |
452 | } | 468 | } |
453 | 469 | ||
454 | // if (abort_send) | 470 | // if (abort_send) |
455 | // break; | 471 | // break; |
456 | 472 | ||
457 | } | 473 | } |
458 | gst_buffer_unmap (b, &m); | 474 | gst_buffer_unmap (b, &m); |
459 | gst_sample_unref (s); | 475 | gst_sample_unref (s); |
460 | } | 476 | } |
461 | */ | 477 | */ |
462 | 478 | ||
463 | 479 | ||
464 | extern int | 480 | extern int |
465 | feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d) | 481 | feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData * d) |
466 | { | 482 | { |
467 | GstBuffer *b; | 483 | GstBuffer *b; |
468 | gchar *bufspace; | 484 | gchar *bufspace; |
469 | GstFlowReturn flow; | 485 | GstFlowReturn flow; |
470 | 486 | ||
471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 487 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
472 | "Feeding %u bytes to GStreamer\n", | 488 | "Feeding %u bytes to GStreamer\n", |
473 | (unsigned int) b_len); | 489 | (unsigned int)b_len); |
474 | 490 | ||
475 | bufspace = g_memdup (audio, b_len); | 491 | bufspace = g_memdup(audio, b_len); |
476 | b = gst_buffer_new_wrapped (bufspace, b_len); | 492 | b = gst_buffer_new_wrapped(bufspace, b_len); |
477 | if (NULL == b) | 493 | if (NULL == b) |
478 | { | 494 | { |
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
480 | "Failed to wrap a buffer\n"); | 496 | "Failed to wrap a buffer\n"); |
481 | g_free (bufspace); | 497 | g_free(bufspace); |
482 | return GNUNET_SYSERR; | 498 | return GNUNET_SYSERR; |
483 | } | 499 | } |
484 | if (GST_APP_SRC(d->appsrc) == NULL) | 500 | if (GST_APP_SRC(d->appsrc) == NULL) |
485 | exit(10); | 501 | exit(10); |
486 | flow = gst_app_src_push_buffer (GST_APP_SRC(d->appsrc), b); | 502 | flow = gst_app_src_push_buffer(GST_APP_SRC(d->appsrc), b); |
487 | /* They all return GNUNET_OK, because currently player stops when | 503 | /* They all return GNUNET_OK, because currently player stops when |
488 | * data stops coming. This might need to be changed for the player | 504 | * data stops coming. This might need to be changed for the player |
489 | * to also stop when pipeline breaks. | 505 | * to also stop when pipeline breaks. |
490 | */ | 506 | */ |
491 | switch (flow) | 507 | switch (flow) |
492 | { | 508 | { |
493 | case GST_FLOW_OK: | 509 | case GST_FLOW_OK: |
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 510 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
495 | "Fed %u bytes to the pipeline\n", | 511 | "Fed %u bytes to the pipeline\n", |
496 | (unsigned int) b_len); | 512 | (unsigned int)b_len); |
497 | break; | 513 | break; |
498 | case GST_FLOW_FLUSHING: | 514 | |
499 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ | 515 | case GST_FLOW_FLUSHING: |
500 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 516 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ |
501 | "Dropped a buffer\n"); | 517 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
502 | break; | 518 | "Dropped a buffer\n"); |
503 | case GST_FLOW_EOS: | 519 | break; |
504 | /* end of stream */ | 520 | |
505 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 521 | case GST_FLOW_EOS: |
506 | "EOS\n"); | 522 | /* end of stream */ |
507 | break; | 523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
508 | default: | 524 | "EOS\n"); |
509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 525 | break; |
510 | "Unexpected push result\n"); | 526 | |
511 | break; | 527 | default: |
512 | } | 528 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
529 | "Unexpected push result\n"); | ||
530 | break; | ||
531 | } | ||
513 | return GNUNET_OK; | 532 | return GNUNET_OK; |
514 | } | 533 | } |
515 | 534 | ||
@@ -518,35 +537,37 @@ feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData * d) | |||
518 | /** | 537 | /** |
519 | * debug making elements | 538 | * debug making elements |
520 | */ | 539 | */ |
521 | extern GstElement * | 540 | extern GstElement * |
522 | gst_element_factory_make_debug( gchar *factoryname, gchar *name) | 541 | gst_element_factory_make_debug(gchar *factoryname, gchar *name) |
523 | { | 542 | { |
524 | GstElement *element; | 543 | GstElement *element; |
525 | 544 | ||
526 | element = gst_element_factory_make(factoryname,name); | 545 | element = gst_element_factory_make(factoryname, name); |
527 | |||
528 | if (element == NULL) { | ||
529 | 546 | ||
530 | printf ("\n Failed to create element - type: %s name: %s \n", factoryname, name); | 547 | if (element == NULL) |
531 | exit(10); | 548 | { |
532 | return element; | 549 | printf("\n Failed to create element - type: %s name: %s \n", factoryname, name); |
533 | } else { | 550 | exit(10); |
534 | return element; | 551 | return element; |
535 | } | 552 | } |
553 | else | ||
554 | { | ||
555 | return element; | ||
556 | } | ||
536 | } | 557 | } |
537 | 558 | ||
538 | /* | 559 | /* |
539 | static gboolean | 560 | static gboolean |
540 | gst_element_link_many_debug(...) | 561 | gst_element_link_many_debug(...) |
541 | { | 562 | { |
542 | va_list arguments; | 563 | va_list arguments; |
543 | gst_element_link_many(argptr); | 564 | gst_element_link_many(argptr); |
544 | } | 565 | } |
545 | 566 | ||
546 | #define gst_element_link_many(...) \ | 567 | #define gst_element_link_many(...) \ |
547 | gst_element_link_many_debug(__VA_ARGS__) | 568 | gst_element_link_many_debug(__VA_ARGS__) |
548 | */ | 569 | */ |
549 | extern void | 570 | extern void |
550 | lf(char * msg) | 571 | lf(char * msg) |
551 | { | 572 | { |
552 | printf("linking elements failed: %s", msg); | 573 | printf("linking elements failed: %s", msg); |
@@ -557,26 +578,26 @@ lf(char * msg) | |||
557 | * used to set properties on autoaudiosink's chosen sink | 578 | * used to set properties on autoaudiosink's chosen sink |
558 | */ | 579 | */ |
559 | static void | 580 | static void |
560 | autoaudiosink_child_added (GstChildProxy *child_proxy, | 581 | autoaudiosink_child_added(GstChildProxy *child_proxy, |
561 | GObject *object, | 582 | GObject *object, |
562 | gchar *name, | 583 | gchar *name, |
563 | gpointer user_data) | 584 | gpointer user_data) |
564 | { | 585 | { |
565 | if (GST_IS_AUDIO_BASE_SRC (object)) | 586 | if (GST_IS_AUDIO_BASE_SRC(object)) |
566 | g_object_set (object, | 587 | g_object_set(object, |
567 | "buffer-time", (gint64) BUFFER_TIME, | 588 | "buffer-time", (gint64)BUFFER_TIME, |
568 | "latency-time", (gint64) LATENCY_TIME, | 589 | "latency-time", (gint64)LATENCY_TIME, |
569 | NULL); | 590 | NULL); |
570 | } | 591 | } |
571 | 592 | ||
572 | /*** | 593 | /*** |
573 | * used to set properties on autoaudiosource's chosen sink | 594 | * used to set properties on autoaudiosource's chosen sink |
574 | */ | 595 | */ |
575 | static void | 596 | static void |
576 | autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) | 597 | autoaudiosource_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) |
577 | { | 598 | { |
578 | if (GST_IS_AUDIO_BASE_SRC (object)) | 599 | if (GST_IS_AUDIO_BASE_SRC(object)) |
579 | g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); | 600 | g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); |
580 | } | 601 | } |
581 | 602 | ||
582 | 603 | ||
@@ -585,66 +606,67 @@ get_pipeline(GstElement *element) | |||
585 | { | 606 | { |
586 | GstPipeline *p; | 607 | GstPipeline *p; |
587 | 608 | ||
588 | p = GST_PIPELINE (gst_object_get_parent(GST_OBJECT (element))); | 609 | p = GST_PIPELINE(gst_object_get_parent(GST_OBJECT(element))); |
589 | 610 | ||
590 | return GST_ELEMENT (p); | 611 | return GST_ELEMENT(p); |
591 | } | 612 | } |
592 | 613 | ||
593 | static void | 614 | static void |
594 | decoder_ogg_pad_added (GstElement *element, | 615 | decoder_ogg_pad_added(GstElement *element, |
595 | GstPad *pad, | 616 | GstPad *pad, |
596 | gpointer data) | 617 | gpointer data) |
597 | { | 618 | { |
598 | GstPad *sinkpad; | 619 | GstPad *sinkpad; |
599 | GstElement *decoder = (GstElement *) data; | 620 | GstElement *decoder = (GstElement *)data; |
600 | 621 | ||
601 | printf("==== ogg pad added callback \n"); | 622 | printf("==== ogg pad added callback \n"); |
602 | /* We can now link this pad with the opus-decoder sink pad */ | 623 | /* We can now link this pad with the opus-decoder sink pad */ |
603 | // pl_graph(get_pipeline(element)); | 624 | // pl_graph(get_pipeline(element)); |
604 | sinkpad = gst_element_get_static_pad (decoder, "sink"); | 625 | sinkpad = gst_element_get_static_pad(decoder, "sink"); |
605 | 626 | ||
606 | gst_pad_link (pad, sinkpad); | 627 | gst_pad_link(pad, sinkpad); |
607 | gst_element_link_many(element, decoder, NULL); | 628 | gst_element_link_many(element, decoder, NULL); |
608 | gst_object_unref (sinkpad); | 629 | gst_object_unref(sinkpad); |
609 | } | 630 | } |
610 | 631 | ||
611 | 632 | ||
612 | int | 633 | int |
613 | gnunet_read (GNUNET_gstData * d) | 634 | gnunet_read(GNUNET_gstData * d) |
614 | { | 635 | { |
615 | char readbuf[MAXLINE]; | 636 | char readbuf[MAXLINE]; |
616 | int ret; | 637 | int ret; |
638 | |||
617 | printf("read \n"); | 639 | printf("read \n"); |
618 | ret = read (0, readbuf, sizeof (readbuf)); | 640 | ret = read(0, readbuf, sizeof(readbuf)); |
619 | if (0 > ret) | 641 | if (0 > ret) |
620 | { | 642 | { |
621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 643 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
622 | _("Read error from STDIN: %d %s\n"), | 644 | _("Read error from STDIN: %d %s\n"), |
623 | ret, strerror (errno)); | 645 | ret, strerror(errno)); |
624 | return FAIL; | 646 | return FAIL; |
625 | } | 647 | } |
626 | //toff += ret; | 648 | //toff += ret; |
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
628 | "Received %d bytes of audio data\n", | 650 | "Received %d bytes of audio data\n", |
629 | (int) ret); | 651 | (int)ret); |
630 | if (0 == ret) | 652 | if (0 == ret) |
631 | return FAIL; | 653 | return FAIL; |
632 | //#ifdef DEBUG_READ_PURE_OGG | 654 | //#ifdef DEBUG_READ_PURE_OGG |
633 | 655 | ||
634 | if (d->pure_ogg) | 656 | if (d->pure_ogg) |
635 | { | 657 | { |
636 | feed_buffer_to_gst (readbuf, ret, d); | 658 | feed_buffer_to_gst(readbuf, ret, d); |
637 | } | 659 | } |
638 | else | 660 | else |
639 | { | 661 | { |
640 | //#endif | 662 | //#endif |
641 | GNUNET_MST_from_buffer (d->stdin_mst, | 663 | GNUNET_MST_from_buffer(d->stdin_mst, |
642 | readbuf, | 664 | readbuf, |
643 | ret, | 665 | ret, |
644 | GNUNET_NO, | 666 | GNUNET_NO, |
645 | GNUNET_NO); | 667 | GNUNET_NO); |
646 | } | 668 | } |
647 | return 0; | 669 | return 0; |
648 | } | 670 | } |
649 | 671 | ||
650 | /** | 672 | /** |
@@ -656,29 +678,30 @@ gnunet_read (GNUNET_gstData * d) | |||
656 | * #GNUNET_SYSERR to stop further processing due to error | 678 | * #GNUNET_SYSERR to stop further processing due to error |
657 | */ | 679 | */ |
658 | static int | 680 | static int |
659 | stdin_receiver (void *cls, | 681 | stdin_receiver(void *cls, |
660 | const struct GNUNET_MessageHeader *msg) | 682 | const struct GNUNET_MessageHeader *msg) |
661 | { | 683 | { |
662 | struct AudioMessage *audio; | 684 | struct AudioMessage *audio; |
663 | size_t b_len; | 685 | size_t b_len; |
664 | 686 | ||
665 | printf("stdin receiver \n "); | 687 | printf("stdin receiver \n "); |
666 | dump_buffer (sizeof(msg), | 688 | dump_buffer(sizeof(msg), |
667 | (const unsigned char *) msg); | 689 | (const unsigned char *)msg); |
668 | 690 | ||
669 | switch (ntohs (msg->type)) | 691 | switch (ntohs(msg->type)) |
670 | { | 692 | { |
671 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 693 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
672 | audio = (struct AudioMessage *) msg; | 694 | audio = (struct AudioMessage *)msg; |
673 | 695 | ||
674 | b_len = ntohs (audio->header.size) - sizeof (struct AudioMessage); | 696 | b_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); |
675 | printf("feeding buffer to gst \n "); | 697 | printf("feeding buffer to gst \n "); |
676 | feed_buffer_to_gst ((const char *) &audio[1], b_len, cls); | 698 | feed_buffer_to_gst((const char *)&audio[1], b_len, cls); |
677 | break; | 699 | break; |
678 | default: | 700 | |
679 | printf("No audio message: %u \n ", ntohs(msg->type)); | 701 | default: |
680 | break; | 702 | printf("No audio message: %u \n ", ntohs(msg->type)); |
681 | } | 703 | break; |
704 | } | ||
682 | return GNUNET_OK; | 705 | return GNUNET_OK; |
683 | } | 706 | } |
684 | 707 | ||
@@ -689,92 +712,92 @@ get_app(GNUNET_gstData *d, int type) | |||
689 | GstBin *bin; | 712 | GstBin *bin; |
690 | GstPad *pad, *ghostpad; | 713 | GstPad *pad, *ghostpad; |
691 | 714 | ||
692 | if ( type == SOURCE ) | 715 | if (type == SOURCE) |
693 | { | 716 | { |
694 | bin = GST_BIN(gst_bin_new("Gnunet appsrc")); | 717 | bin = GST_BIN(gst_bin_new("Gnunet appsrc")); |
695 | 718 | ||
696 | 719 | ||
697 | GNUNET_assert (GNUNET_OK == | 720 | GNUNET_assert(GNUNET_OK == |
698 | GNUNET_log_setup ("gnunet-helper-audio-playback", | 721 | GNUNET_log_setup("gnunet-helper-audio-playback", |
699 | "WARNING", | 722 | "WARNING", |
700 | NULL)); | 723 | NULL)); |
701 | 724 | ||
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 725 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
703 | "Audio playback starts\n"); | 726 | "Audio playback starts\n"); |
704 | printf(" creating appsrc \n "); | 727 | printf(" creating appsrc \n "); |
705 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 728 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
706 | 729 | ||
707 | // d->audio_message = GNUNET_malloc (UINT16_MAX); | 730 | // d->audio_message = GNUNET_malloc (UINT16_MAX); |
708 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); | 731 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); |
709 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); | 732 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); |
710 | 733 | ||
711 | 734 | ||
712 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 735 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
713 | 736 | ||
714 | 737 | ||
715 | d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d); | 738 | d->stdin_mst = GNUNET_MST_create(&stdin_receiver, d); |
716 | 739 | ||
717 | if ( d->stdin_mst == NULL) | 740 | if (d->stdin_mst == NULL) |
718 | printf("stdin_mst = NULL"); | 741 | printf("stdin_mst = NULL"); |
719 | 742 | ||
720 | d->appsrc = gst_element_factory_make ("appsrc", "appsrc"); | 743 | d->appsrc = gst_element_factory_make("appsrc", "appsrc"); |
721 | 744 | ||
722 | gst_bin_add_many( bin, d->appsrc, NULL); | 745 | gst_bin_add_many(bin, d->appsrc, NULL); |
723 | // gst_element_link_many ( encoder, muxer, NULL); | 746 | // gst_element_link_many ( encoder, muxer, NULL); |
724 | 747 | ||
725 | pad = gst_element_get_static_pad (d->appsrc, "src"); | 748 | pad = gst_element_get_static_pad(d->appsrc, "src"); |
726 | ghostpad = gst_ghost_pad_new ("src", pad); | 749 | ghostpad = gst_ghost_pad_new("src", pad); |
727 | } | 750 | } |
728 | if ( type == SINK ) | 751 | if (type == SINK) |
729 | { | 752 | { |
730 | bin = GST_BIN(gst_bin_new("Gnunet appsink")); | 753 | bin = GST_BIN(gst_bin_new("Gnunet appsink")); |
731 | 754 | ||
732 | 755 | ||
733 | GNUNET_assert (GNUNET_OK == | 756 | GNUNET_assert(GNUNET_OK == |
734 | GNUNET_log_setup ("gnunet-helper-audio-record", | 757 | GNUNET_log_setup("gnunet-helper-audio-record", |
735 | "WARNING", | 758 | "WARNING", |
736 | NULL)); | 759 | NULL)); |
737 | 760 | ||
738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
739 | "Audio source starts\n"); | 762 | "Audio source starts\n"); |
740 | 763 | ||
741 | d->appsink = gst_element_factory_make ("appsink", "appsink"); | 764 | d->appsink = gst_element_factory_make("appsink", "appsink"); |
742 | 765 | ||
743 | // Move this out of here! | 766 | // Move this out of here! |
744 | d->audio_message = GNUNET_malloc (UINT16_MAX); | 767 | d->audio_message = GNUNET_malloc(UINT16_MAX); |
745 | (d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 768 | (d->audio_message)->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
746 | g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); | 769 | g_object_set(G_OBJECT(d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); |
747 | 770 | ||
748 | g_signal_connect (d->appsink, "new-sample", | 771 | g_signal_connect(d->appsink, "new-sample", |
749 | G_CALLBACK (on_appsink_new_sample), &d); | 772 | G_CALLBACK(on_appsink_new_sample), &d); |
750 | 773 | ||
751 | gst_bin_add_many( bin, d->appsink, NULL); | 774 | gst_bin_add_many(bin, d->appsink, NULL); |
752 | // gst_element_link_many ( encoder, muxer, NULL); | 775 | // gst_element_link_many ( encoder, muxer, NULL); |
753 | 776 | ||
754 | pad = gst_element_get_static_pad (d->appsink, "sink"); | 777 | pad = gst_element_get_static_pad(d->appsink, "sink"); |
755 | ghostpad = gst_ghost_pad_new ("sink", pad); | 778 | ghostpad = gst_ghost_pad_new("sink", pad); |
756 | } | 779 | } |
757 | 780 | ||
758 | /* set the bin pads */ | 781 | /* set the bin pads */ |
759 | gst_pad_set_active (ghostpad, TRUE); | 782 | gst_pad_set_active(ghostpad, TRUE); |
760 | gst_element_add_pad (GST_ELEMENT(bin), ghostpad); | 783 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); |
761 | 784 | ||
762 | gst_object_unref (pad); | 785 | gst_object_unref(pad); |
763 | 786 | ||
764 | return bin; | 787 | return bin; |
765 | } | 788 | } |
766 | 789 | ||
767 | extern GstBin * | 790 | extern GstBin * |
768 | get_coder(GNUNET_gstData *d , int type) | 791 | get_coder(GNUNET_gstData *d, int type) |
769 | { | 792 | { |
770 | GstBin *bin; | 793 | GstBin *bin; |
771 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; | 794 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; |
772 | GstCaps *rtpcaps; | 795 | GstCaps *rtpcaps; |
773 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter; | 796 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter; |
774 | 797 | ||
775 | if ( d->usertp == TRUE ) | 798 | if (d->usertp == TRUE) |
776 | { | 799 | { |
777 | /* | 800 | /* |
778 | * application/x-rtp, media=(string)audio, clock-rate=(int)48000, encoding-name=(string)OPUS, sprop-maxcapturerate=(string)48000, sprop-stereo=(string)0, payload=(int)96, encoding-params=(string)2, ssrc=(uint)630297634, timestamp-offset=(uint)678334141, seqnum-offset=(uint)16938 */ | 801 | * application/x-rtp, media=(string)audio, clock-rate=(int)48000, encoding-name=(string)OPUS, sprop-maxcapturerate=(string)48000, sprop-stereo=(string)0, payload=(int)96, encoding-params=(string)2, ssrc=(uint)630297634, timestamp-offset=(uint)678334141, seqnum-offset=(uint)16938 */ |
779 | /* | 802 | /* |
780 | rtpcaps = gst_caps_new_simple ("application/x-rtp", | 803 | rtpcaps = gst_caps_new_simple ("application/x-rtp", |
@@ -785,110 +808,110 @@ get_coder(GNUNET_gstData *d , int type) | |||
785 | "sprop-stereo", G_TYPE_STRING, "0", | 808 | "sprop-stereo", G_TYPE_STRING, "0", |
786 | "encoding-params", G_TYPE_STRING, "2", | 809 | "encoding-params", G_TYPE_STRING, "2", |
787 | NULL); | 810 | NULL); |
788 | */ | 811 | */ |
789 | rtpcaps = gst_caps_new_simple ("application/x-rtp", | 812 | rtpcaps = gst_caps_new_simple("application/x-rtp", |
790 | "media", G_TYPE_STRING, "audio", | 813 | "media", G_TYPE_STRING, "audio", |
791 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, | 814 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, |
792 | "encoding-name", G_TYPE_STRING, "OPUS", | 815 | "encoding-name", G_TYPE_STRING, "OPUS", |
793 | "payload", G_TYPE_INT, 96, | 816 | "payload", G_TYPE_INT, 96, |
794 | "sprop-stereo", G_TYPE_STRING, "0", | 817 | "sprop-stereo", G_TYPE_STRING, "0", |
795 | "encoding-params", G_TYPE_STRING, "2", | 818 | "encoding-params", G_TYPE_STRING, "2", |
796 | NULL); | 819 | NULL); |
797 | 820 | ||
798 | 821 | ||
799 | rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter"); | 822 | rtpcapsfilter = gst_element_factory_make("capsfilter", "rtpcapsfilter"); |
800 | 823 | ||
801 | g_object_set (G_OBJECT (rtpcapsfilter), | 824 | g_object_set(G_OBJECT(rtpcapsfilter), |
802 | "caps", rtpcaps, | 825 | "caps", rtpcaps, |
803 | NULL); | 826 | NULL); |
804 | gst_caps_unref (rtpcaps); | 827 | gst_caps_unref(rtpcaps); |
805 | 828 | } | |
806 | } | ||
807 | |||
808 | 829 | ||
809 | if ( type == ENCODER ) | ||
810 | { | ||
811 | bin = GST_BIN(gst_bin_new("Gnunet audioencoder")); | ||
812 | 830 | ||
813 | encoder = gst_element_factory_make ("opusenc", "opus-encoder"); | 831 | if (type == ENCODER) |
814 | if ( d->usertp == TRUE ) | ||
815 | { | 832 | { |
816 | muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader"); | 833 | bin = GST_BIN(gst_bin_new("Gnunet audioencoder")); |
817 | } else { | ||
818 | muxer = gst_element_factory_make ("oggmux", "ogg-muxer"); | ||
819 | } | ||
820 | g_object_set (G_OBJECT (encoder), | ||
821 | /* "bitrate", 64000, */ | ||
822 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | ||
823 | "inband-fec", INBAND_FEC_MODE, | ||
824 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | ||
825 | "max-payload-size", MAX_PAYLOAD_SIZE, | ||
826 | "audio", TRUE, /* VoIP, not audio */ | ||
827 | "frame-size", OPUS_FRAME_SIZE, | ||
828 | NULL); | ||
829 | |||
830 | if ( d->usertp != TRUE) | ||
831 | { | ||
832 | g_object_set (G_OBJECT (muxer), | ||
833 | "max-delay", OGG_MAX_DELAY, | ||
834 | "max-page-delay", OGG_MAX_PAGE_DELAY, | ||
835 | NULL); | ||
836 | } | ||
837 | 834 | ||
838 | gst_bin_add_many( bin, encoder, muxer, NULL); | 835 | encoder = gst_element_factory_make("opusenc", "opus-encoder"); |
839 | gst_element_link_many ( encoder, muxer, NULL); | 836 | if (d->usertp == TRUE) |
840 | sinkpad = gst_element_get_static_pad(encoder, "sink"); | 837 | { |
841 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); | 838 | muxer = gst_element_factory_make("rtpopuspay", "rtp-payloader"); |
842 | 839 | } | |
843 | srcpad = gst_element_get_static_pad(muxer, "src"); | 840 | else |
844 | srcghostpad = gst_ghost_pad_new ("src", srcpad); | 841 | { |
842 | muxer = gst_element_factory_make("oggmux", "ogg-muxer"); | ||
843 | } | ||
844 | g_object_set(G_OBJECT(encoder), | ||
845 | /* "bitrate", 64000, */ | ||
846 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | ||
847 | "inband-fec", INBAND_FEC_MODE, | ||
848 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | ||
849 | "max-payload-size", MAX_PAYLOAD_SIZE, | ||
850 | "audio", TRUE, /* VoIP, not audio */ | ||
851 | "frame-size", OPUS_FRAME_SIZE, | ||
852 | NULL); | ||
853 | |||
854 | if (d->usertp != TRUE) | ||
855 | { | ||
856 | g_object_set(G_OBJECT(muxer), | ||
857 | "max-delay", OGG_MAX_DELAY, | ||
858 | "max-page-delay", OGG_MAX_PAGE_DELAY, | ||
859 | NULL); | ||
860 | } | ||
845 | 861 | ||
846 | } | 862 | gst_bin_add_many(bin, encoder, muxer, NULL); |
847 | if ( type == DECODER ) | 863 | gst_element_link_many(encoder, muxer, NULL); |
848 | { | 864 | sinkpad = gst_element_get_static_pad(encoder, "sink"); |
849 | bin = GST_BIN(gst_bin_new("Gnunet audiodecoder")); | 865 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); |
850 | 866 | ||
851 | // decoder | 867 | srcpad = gst_element_get_static_pad(muxer, "src"); |
852 | if ( d->usertp == TRUE ) | 868 | srcghostpad = gst_ghost_pad_new("src", srcpad); |
853 | { | ||
854 | |||
855 | demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer"); | ||
856 | jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", "rtpjitterbuffer"); | ||
857 | } else { | ||
858 | demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); | ||
859 | } | 869 | } |
860 | decoder = gst_element_factory_make ("opusdec", "opus-decoder"); | 870 | if (type == DECODER) |
861 | |||
862 | if ( d->usertp == TRUE ) | ||
863 | { | 871 | { |
864 | gst_bin_add_many( bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | 872 | bin = GST_BIN(gst_bin_new("Gnunet audiodecoder")); |
865 | gst_element_link_many ( rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | ||
866 | sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink"); | ||
867 | 873 | ||
874 | // decoder | ||
875 | if (d->usertp == TRUE) | ||
876 | { | ||
877 | demuxer = gst_element_factory_make("rtpopusdepay", "ogg-demuxer"); | ||
878 | jitterbuffer = gst_element_factory_make("rtpjitterbuffer", "rtpjitterbuffer"); | ||
879 | } | ||
880 | else | ||
881 | { | ||
882 | demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer"); | ||
883 | } | ||
884 | decoder = gst_element_factory_make("opusdec", "opus-decoder"); | ||
868 | 885 | ||
869 | } else { | 886 | if (d->usertp == TRUE) |
870 | gst_bin_add_many( bin, demuxer, decoder, NULL); | 887 | { |
871 | 888 | gst_bin_add_many(bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | |
872 | g_signal_connect (demuxer, | 889 | gst_element_link_many(rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); |
873 | "pad-added", | 890 | sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink"); |
874 | G_CALLBACK (decoder_ogg_pad_added), | 891 | } |
875 | decoder); | 892 | else |
893 | { | ||
894 | gst_bin_add_many(bin, demuxer, decoder, NULL); | ||
876 | 895 | ||
877 | sinkpad = gst_element_get_static_pad(demuxer, "sink"); | 896 | g_signal_connect(demuxer, |
878 | } | 897 | "pad-added", |
879 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); | 898 | G_CALLBACK(decoder_ogg_pad_added), |
899 | decoder); | ||
880 | 900 | ||
881 | srcpad = gst_element_get_static_pad(decoder, "src"); | 901 | sinkpad = gst_element_get_static_pad(demuxer, "sink"); |
882 | srcghostpad = gst_ghost_pad_new ("src", srcpad); | 902 | } |
903 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); | ||
883 | 904 | ||
884 | } | 905 | srcpad = gst_element_get_static_pad(decoder, "src"); |
906 | srcghostpad = gst_ghost_pad_new("src", srcpad); | ||
907 | } | ||
885 | 908 | ||
886 | // add pads to the bin | 909 | // add pads to the bin |
887 | gst_pad_set_active (sinkghostpad, TRUE); | 910 | gst_pad_set_active(sinkghostpad, TRUE); |
888 | gst_element_add_pad (GST_ELEMENT(bin), sinkghostpad); | 911 | gst_element_add_pad(GST_ELEMENT(bin), sinkghostpad); |
889 | 912 | ||
890 | gst_pad_set_active (srcghostpad, TRUE); | 913 | gst_pad_set_active(srcghostpad, TRUE); |
891 | gst_element_add_pad (GST_ELEMENT(bin), srcghostpad); | 914 | gst_element_add_pad(GST_ELEMENT(bin), srcghostpad); |
892 | 915 | ||
893 | 916 | ||
894 | return bin; | 917 | return bin; |
@@ -896,82 +919,80 @@ get_coder(GNUNET_gstData *d , int type) | |||
896 | 919 | ||
897 | 920 | ||
898 | extern GstBin * | 921 | extern GstBin * |
899 | get_audiobin(GNUNET_gstData *d , int type) | 922 | get_audiobin(GNUNET_gstData *d, int type) |
900 | { | 923 | { |
901 | GstBin *bin; | 924 | GstBin *bin; |
902 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; | 925 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; |
903 | GstPad *pad, *ghostpad; | 926 | GstPad *pad, *ghostpad; |
904 | GstCaps *caps; | 927 | GstCaps *caps; |
905 | if ( type == SINK ) { | ||
906 | |||
907 | bin = GST_BIN(gst_bin_new("Gnunet audiosink")); | ||
908 | 928 | ||
909 | /* Create all the elements */ | 929 | if (type == SINK) |
910 | if ( d->dropsilence == TRUE ) | ||
911 | { | 930 | { |
912 | queue = gst_element_factory_make ("queue", "queue"); | 931 | bin = GST_BIN(gst_bin_new("Gnunet audiosink")); |
913 | removesilence = gst_element_factory_make ("removesilence", "removesilence"); | ||
914 | } | ||
915 | 932 | ||
916 | conv = gst_element_factory_make ("audioconvert", "converter"); | 933 | /* Create all the elements */ |
917 | resampler= gst_element_factory_make ("audioresample", "resampler"); | 934 | if (d->dropsilence == TRUE) |
918 | 935 | { | |
919 | if ( d->audiobackend == AUTO ) | 936 | queue = gst_element_factory_make("queue", "queue"); |
920 | { | 937 | removesilence = gst_element_factory_make("removesilence", "removesilence"); |
921 | sink = gst_element_factory_make ("autoaudiosink", "audiosink"); | 938 | } |
922 | g_signal_connect (sink, "child-added", G_CALLBACK (autoaudiosink_child_added), NULL); | ||
923 | 939 | ||
924 | } | 940 | conv = gst_element_factory_make("audioconvert", "converter"); |
941 | resampler = gst_element_factory_make("audioresample", "resampler"); | ||
925 | 942 | ||
926 | if ( d->audiobackend == ALSA ) | 943 | if (d->audiobackend == AUTO) |
927 | { | 944 | { |
928 | sink = gst_element_factory_make ("alsaaudiosink", "audiosink"); | 945 | sink = gst_element_factory_make("autoaudiosink", "audiosink"); |
929 | } | 946 | g_signal_connect(sink, "child-added", G_CALLBACK(autoaudiosink_child_added), NULL); |
947 | } | ||
930 | 948 | ||
931 | if ( d->audiobackend == JACK ) | 949 | if (d->audiobackend == ALSA) |
932 | { | 950 | { |
933 | sink = gst_element_factory_make ("jackaudiosink", "audiosink"); | 951 | sink = gst_element_factory_make("alsaaudiosink", "audiosink"); |
952 | } | ||
934 | 953 | ||
935 | g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL); | 954 | if (d->audiobackend == JACK) |
955 | { | ||
956 | sink = gst_element_factory_make("jackaudiosink", "audiosink"); | ||
936 | 957 | ||
937 | if (g_object_class_find_property | 958 | g_object_set(G_OBJECT(sink), "client-name", "gnunet", NULL); |
938 | (G_OBJECT_GET_CLASS (sink), "port-pattern")) | ||
939 | { | ||
940 | 959 | ||
960 | if (g_object_class_find_property | ||
961 | (G_OBJECT_GET_CLASS(sink), "port-pattern")) | ||
962 | { | ||
941 | // char *portpattern = "system"; | 963 | // char *portpattern = "system"; |
942 | 964 | ||
943 | g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out, | 965 | g_object_set(G_OBJECT(sink), "port-pattern", d->jack_pp_out, |
944 | NULL); | 966 | NULL); |
945 | } | 967 | } |
946 | 968 | } | |
947 | } | ||
948 | 969 | ||
949 | if ( d->audiobackend == FAKE ) | 970 | if (d->audiobackend == FAKE) |
950 | { | 971 | { |
951 | sink = gst_element_factory_make ("fakesink", "audiosink"); | 972 | sink = gst_element_factory_make("fakesink", "audiosink"); |
952 | } | 973 | } |
953 | 974 | ||
954 | g_object_set (sink, | 975 | g_object_set(sink, |
955 | "buffer-time", (gint64) BUFFER_TIME, | 976 | "buffer-time", (gint64)BUFFER_TIME, |
956 | "latency-time", (gint64) LATENCY_TIME, | 977 | "latency-time", (gint64)LATENCY_TIME, |
957 | NULL); | 978 | NULL); |
958 | 979 | ||
959 | if ( d->dropsilence == TRUE ) | 980 | if (d->dropsilence == TRUE) |
960 | { | 981 | { |
961 | // Do not remove silence by default | 982 | // Do not remove silence by default |
962 | g_object_set( removesilence, "remove", FALSE, NULL); | 983 | g_object_set(removesilence, "remove", FALSE, NULL); |
963 | g_object_set( queue, "max-size-buffers", 12, NULL); | 984 | g_object_set(queue, "max-size-buffers", 12, NULL); |
964 | /* | 985 | /* |
965 | g_signal_connect (source, | 986 | g_signal_connect (source, |
966 | "need-data", | 987 | "need-data", |
967 | G_CALLBACK(appsrc_need_data), | 988 | G_CALLBACK(appsrc_need_data), |
968 | NULL); | 989 | NULL); |
969 | 990 | ||
970 | g_signal_connect (source, | 991 | g_signal_connect (source, |
971 | "enough-data", | 992 | "enough-data", |
972 | G_CALLBACK(appsrc_enough_data), | 993 | G_CALLBACK(appsrc_enough_data), |
973 | NULL); | 994 | NULL); |
974 | */ | 995 | */ |
975 | /* | 996 | /* |
976 | g_signal_connect (queue, | 997 | g_signal_connect (queue, |
977 | "notify::current-level-bytes", | 998 | "notify::current-level-bytes", |
@@ -998,109 +1019,109 @@ get_audiobin(GNUNET_gstData *d , int type) | |||
998 | G_CALLBACK(queue_pushing), | 1019 | G_CALLBACK(queue_pushing), |
999 | NULL); | 1020 | NULL); |
1000 | */ | 1021 | */ |
1022 | } | ||
1001 | 1023 | ||
1002 | } | ||
1003 | |||
1004 | |||
1005 | |||
1006 | |||
1007 | |||
1008 | gst_bin_add_many (bin , conv, resampler, sink, NULL); | ||
1009 | gst_element_link_many ( conv, resampler, sink, NULL); | ||
1010 | |||
1011 | if ( d->dropsilence == TRUE ) | ||
1012 | { | ||
1013 | gst_bin_add_many (bin , queue ,removesilence , NULL); | ||
1014 | |||
1015 | if ( !gst_element_link_many ( queue, removesilence, conv, NULL) ) | ||
1016 | lf ("queue, removesilence, conv "); | ||
1017 | |||
1018 | pad = gst_element_get_static_pad (queue, "sink"); | ||
1019 | 1024 | ||
1020 | } else { | ||
1021 | 1025 | ||
1022 | pad = gst_element_get_static_pad(conv, "sink"); | ||
1023 | 1026 | ||
1024 | } | ||
1025 | 1027 | ||
1026 | ghostpad = gst_ghost_pad_new ("sink", pad); | 1028 | gst_bin_add_many(bin, conv, resampler, sink, NULL); |
1029 | gst_element_link_many(conv, resampler, sink, NULL); | ||
1027 | 1030 | ||
1028 | } else { | 1031 | if (d->dropsilence == TRUE) |
1029 | // SOURCE | 1032 | { |
1033 | gst_bin_add_many(bin, queue, removesilence, NULL); | ||
1030 | 1034 | ||
1031 | bin = GST_BIN(gst_bin_new("Gnunet audiosource")); | 1035 | if (!gst_element_link_many(queue, removesilence, conv, NULL)) |
1036 | lf("queue, removesilence, conv "); | ||
1032 | 1037 | ||
1033 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); | 1038 | pad = gst_element_get_static_pad(queue, "sink"); |
1039 | } | ||
1040 | else | ||
1041 | { | ||
1042 | pad = gst_element_get_static_pad(conv, "sink"); | ||
1043 | } | ||
1034 | 1044 | ||
1035 | if (d->audiobackend == AUTO ) | 1045 | ghostpad = gst_ghost_pad_new("sink", pad); |
1036 | { | ||
1037 | source = gst_element_factory_make ("autoaudiosrc", "audiosource"); | ||
1038 | } | ||
1039 | if (d->audiobackend == ALSA ) | ||
1040 | { | ||
1041 | source = gst_element_factory_make ("alsasrc", "audiosource"); | ||
1042 | } | ||
1043 | if (d->audiobackend == JACK ) | ||
1044 | { | ||
1045 | source = gst_element_factory_make ("jackaudiosrc", "audiosource"); | ||
1046 | } | 1046 | } |
1047 | if (d->audiobackend == TEST ) | 1047 | else |
1048 | { | 1048 | { |
1049 | source = gst_element_factory_make ("audiotestsrc", "audiosource"); | 1049 | // SOURCE |
1050 | } | ||
1051 | 1050 | ||
1052 | filter = gst_element_factory_make ("capsfilter", "filter"); | 1051 | bin = GST_BIN(gst_bin_new("Gnunet audiosource")); |
1053 | conv = gst_element_factory_make ("audioconvert", "converter"); | ||
1054 | resampler= gst_element_factory_make ("audioresample", "resampler"); | ||
1055 | 1052 | ||
1056 | if (d->audiobackend == AUTO ) { | 1053 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); |
1057 | g_signal_connect (source, "child-added", G_CALLBACK (autoaudiosource_child_added), NULL); | ||
1058 | 1054 | ||
1059 | } else { | 1055 | if (d->audiobackend == AUTO) |
1060 | if (GST_IS_AUDIO_BASE_SRC (source)) | 1056 | { |
1061 | g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, "latency-time", (gint64) LATENCY_TIME, NULL); | 1057 | source = gst_element_factory_make("autoaudiosrc", "audiosource"); |
1062 | if ( d->audiobackend == JACK ) { | 1058 | } |
1063 | g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL); | 1059 | if (d->audiobackend == ALSA) |
1064 | if (g_object_class_find_property | 1060 | { |
1065 | (G_OBJECT_GET_CLASS (source), "port-pattern")) | 1061 | source = gst_element_factory_make("alsasrc", "audiosource"); |
1062 | } | ||
1063 | if (d->audiobackend == JACK) | ||
1064 | { | ||
1065 | source = gst_element_factory_make("jackaudiosrc", "audiosource"); | ||
1066 | } | ||
1067 | if (d->audiobackend == TEST) | ||
1066 | { | 1068 | { |
1069 | source = gst_element_factory_make("audiotestsrc", "audiosource"); | ||
1070 | } | ||
1067 | 1071 | ||
1068 | char *portpattern = "moc"; | 1072 | filter = gst_element_factory_make("capsfilter", "filter"); |
1073 | conv = gst_element_factory_make("audioconvert", "converter"); | ||
1074 | resampler = gst_element_factory_make("audioresample", "resampler"); | ||
1069 | 1075 | ||
1070 | g_object_set (G_OBJECT (source), "port-pattern", portpattern, | 1076 | if (d->audiobackend == AUTO) |
1071 | NULL); | 1077 | { |
1078 | g_signal_connect(source, "child-added", G_CALLBACK(autoaudiosource_child_added), NULL); | ||
1079 | } | ||
1080 | else | ||
1081 | { | ||
1082 | if (GST_IS_AUDIO_BASE_SRC(source)) | ||
1083 | g_object_set(source, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); | ||
1084 | if (d->audiobackend == JACK) | ||
1085 | { | ||
1086 | g_object_set(G_OBJECT(source), "client-name", "gnunet", NULL); | ||
1087 | if (g_object_class_find_property | ||
1088 | (G_OBJECT_GET_CLASS(source), "port-pattern")) | ||
1089 | { | ||
1090 | char *portpattern = "moc"; | ||
1091 | |||
1092 | g_object_set(G_OBJECT(source), "port-pattern", portpattern, | ||
1093 | NULL); | ||
1094 | } | ||
1095 | } | ||
1072 | } | 1096 | } |
1073 | } | ||
1074 | } | ||
1075 | |||
1076 | caps = gst_caps_new_simple ("audio/x-raw", | ||
1077 | /* "format", G_TYPE_STRING, "S16LE", */ | ||
1078 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ | ||
1079 | "channels", G_TYPE_INT, OPUS_CHANNELS, | ||
1080 | /* "layout", G_TYPE_STRING, "interleaved",*/ | ||
1081 | NULL); | ||
1082 | 1097 | ||
1083 | g_object_set (G_OBJECT (filter), | 1098 | caps = gst_caps_new_simple("audio/x-raw", |
1084 | "caps", caps, | 1099 | /* "format", G_TYPE_STRING, "S16LE", */ |
1085 | NULL); | 1100 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ |
1086 | gst_caps_unref (caps); | 1101 | "channels", G_TYPE_INT, OPUS_CHANNELS, |
1102 | /* "layout", G_TYPE_STRING, "interleaved",*/ | ||
1103 | NULL); | ||
1087 | 1104 | ||
1088 | gst_bin_add_many (bin , source, filter, conv, resampler, NULL); | 1105 | g_object_set(G_OBJECT(filter), |
1089 | gst_element_link_many ( source, filter, conv, resampler, NULL); | 1106 | "caps", caps, |
1107 | NULL); | ||
1108 | gst_caps_unref(caps); | ||
1090 | 1109 | ||
1091 | pad = gst_element_get_static_pad (resampler, "src"); | 1110 | gst_bin_add_many(bin, source, filter, conv, resampler, NULL); |
1111 | gst_element_link_many(source, filter, conv, resampler, NULL); | ||
1092 | 1112 | ||
1113 | pad = gst_element_get_static_pad(resampler, "src"); | ||
1093 | 1114 | ||
1094 | /* pads */ | ||
1095 | ghostpad = gst_ghost_pad_new ("src", pad); | ||
1096 | 1115 | ||
1097 | } | 1116 | /* pads */ |
1117 | ghostpad = gst_ghost_pad_new("src", pad); | ||
1118 | } | ||
1098 | 1119 | ||
1099 | /* set the bin pads */ | 1120 | /* set the bin pads */ |
1100 | gst_pad_set_active (ghostpad, TRUE); | 1121 | gst_pad_set_active(ghostpad, TRUE); |
1101 | gst_element_add_pad (GST_ELEMENT(bin), ghostpad); | 1122 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); |
1102 | 1123 | ||
1103 | gst_object_unref (pad); | 1124 | gst_object_unref(pad); |
1104 | 1125 | ||
1105 | return bin; | 1126 | return bin; |
1106 | } | 1127 | } |
diff --git a/src/conversation/gnunet_gst.h b/src/conversation/gnunet_gst.h index 88e2dc100..8667a823b 100644 --- a/src/conversation/gnunet_gst.h +++ b/src/conversation/gnunet_gst.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2016 GNUnet e.V. | 3 | Copyright (C) 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet_gst.c | 21 | * @file conversation/gnunet_gst.c |
22 | * @brief FIXME | 22 | * @brief FIXME |
@@ -27,35 +27,35 @@ | |||
27 | // | 27 | // |
28 | 28 | ||
29 | /* | 29 | /* |
30 | int audiobackend = JACK; | 30 | int audiobackend = JACK; |
31 | int dropsilence = TRUE; | 31 | int dropsilence = TRUE; |
32 | int enough = 0; | 32 | int enough = 0; |
33 | int usertp = TRUE; | 33 | int usertp = TRUE; |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #define gst_element_factory_make(element, name) gst_element_factory_make_debug (element, name); | 36 | #define gst_element_factory_make(element, name) gst_element_factory_make_debug(element, name); |
37 | 37 | ||
38 | extern void pl_graph(); | 38 | extern void pl_graph(); |
39 | 39 | ||
40 | 40 | ||
41 | extern GstElement * | 41 | extern GstElement * |
42 | gst_element_factory_make_debug( gchar *, gchar *); | 42 | gst_element_factory_make_debug(gchar *, gchar *); |
43 | 43 | ||
44 | extern GstBin * | 44 | extern GstBin * |
45 | get_audiobin(GNUNET_gstData *, int); | 45 | get_audiobin(GNUNET_gstData *, int); |
46 | 46 | ||
47 | extern GstBin * | 47 | extern GstBin * |
48 | get_coder(GNUNET_gstData *, int); | 48 | get_coder(GNUNET_gstData *, int); |
49 | 49 | ||
50 | 50 | ||
51 | extern gboolean | 51 | extern gboolean |
52 | gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data); | 52 | gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data); |
53 | 53 | ||
54 | extern void | 54 | extern void |
55 | gg_setup_gst_bus (GNUNET_gstData * d); | 55 | gg_setup_gst_bus(GNUNET_gstData * d); |
56 | 56 | ||
57 | extern void | 57 | extern void |
58 | gg_load_configuration (GNUNET_gstData * d); | 58 | gg_load_configuration(GNUNET_gstData * d); |
59 | 59 | ||
60 | extern GstFlowReturn | 60 | extern GstFlowReturn |
61 | on_appsink_new_sample (GstElement *, GNUNET_gstData *); | 61 | on_appsink_new_sample(GstElement *, GNUNET_gstData *); |
diff --git a/src/conversation/gnunet_gst_def.h b/src/conversation/gnunet_gst_def.h index 131dc4f7d..341341f24 100644 --- a/src/conversation/gnunet_gst_def.h +++ b/src/conversation/gnunet_gst_def.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2016 GNUnet e.V. | 3 | Copyright (C) 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet_gst_def.h | 21 | * @file conversation/gnunet_gst_def.h |
22 | * @brief FIXME | 22 | * @brief FIXME |
@@ -43,20 +43,20 @@ | |||
43 | #include "gnunet_common.h" | 43 | #include "gnunet_common.h" |
44 | 44 | ||
45 | /* | 45 | /* |
46 | #include <gst/gst.h> | 46 | #include <gst/gst.h> |
47 | #include <gst/audio/gstaudiobasesrc.h> | 47 | #include <gst/audio/gstaudiobasesrc.h> |
48 | #include <gst/app/gstappsrc.h> | 48 | #include <gst/app/gstappsrc.h> |
49 | */ | 49 | */ |
50 | 50 | ||
51 | /* huh | 51 | /* huh |
52 | #include <glib-2.0/glib.h> | 52 | #include <glib-2.0/glib.h> |
53 | 53 | ||
54 | #include <gstreamer-1.0/gst/gst.h> | 54 | #include <gstreamer-1.0/gst/gst.h> |
55 | #include <gstreamer-1.0/gst/pbutils/pbutils.h> | 55 | #include <gstreamer-1.0/gst/pbutils/pbutils.h> |
56 | #include <gstreamer-1.0/gst/video/videooverlay.h> | 56 | #include <gstreamer-1.0/gst/video/videooverlay.h> |
57 | #include <gstreamer-1.0/gst/audio/gstaudiobasesrc.h> | 57 | #include <gstreamer-1.0/gst/audio/gstaudiobasesrc.h> |
58 | #include <gstreamer-1.0/gst/app/gstappsrc.h> | 58 | #include <gstreamer-1.0/gst/app/gstappsrc.h> |
59 | */ | 59 | */ |
60 | 60 | ||
61 | #include <gst/gst.h> | 61 | #include <gst/gst.h> |
62 | #include <gst/audio/gstaudiobasesrc.h> | 62 | #include <gst/audio/gstaudiobasesrc.h> |
@@ -190,29 +190,29 @@ struct GNUNET_gstData { | |||
190 | #define SAMPLING_RATE 48000 | 190 | #define SAMPLING_RATE 48000 |
191 | 191 | ||
192 | enum { | 192 | enum { |
193 | AUTO, | 193 | AUTO, |
194 | JACK, | 194 | JACK, |
195 | ALSA, | 195 | ALSA, |
196 | FAKE, | 196 | FAKE, |
197 | TEST | 197 | TEST |
198 | }; | 198 | }; |
199 | 199 | ||
200 | enum { | 200 | enum { |
201 | SOURCE, | 201 | SOURCE, |
202 | SINK | 202 | SINK |
203 | }; | 203 | }; |
204 | 204 | ||
205 | enum { | 205 | enum { |
206 | ENCODER, | 206 | ENCODER, |
207 | DECODER | 207 | DECODER |
208 | }; | 208 | }; |
209 | 209 | ||
210 | enum { | 210 | enum { |
211 | FAIL, | 211 | FAIL, |
212 | OK | 212 | OK |
213 | }; | 213 | }; |
214 | 214 | ||
215 | enum { | 215 | enum { |
216 | SPEAKER, | 216 | SPEAKER, |
217 | MICROPHONE | 217 | MICROPHONE |
218 | }; | 218 | }; |
diff --git a/src/conversation/gnunet_gst_test.c b/src/conversation/gnunet_gst_test.c index f52130fa4..60e920f10 100644 --- a/src/conversation/gnunet_gst_test.c +++ b/src/conversation/gnunet_gst_test.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2016 GNUnet e.V. | 3 | Copyright (C) 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/gnunet_gst_test.c | 21 | * @file conversation/gnunet_gst_test.c |
22 | * @brief FIXME | 22 | * @brief FIXME |
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet_gst.h" | 27 | #include "gnunet_gst.h" |
28 | 28 | ||
29 | int | 29 | int |
30 | main (int argc, char *argv[]) | 30 | main(int argc, char *argv[]) |
31 | { | 31 | { |
32 | struct GNUNET_gstData *gst; | 32 | struct GNUNET_gstData *gst; |
33 | // GstBus *bus; | 33 | // GstBus *bus; |
@@ -48,14 +48,14 @@ main (int argc, char *argv[]) | |||
48 | 48 | ||
49 | gg_load_configuration(gst); | 49 | gg_load_configuration(gst); |
50 | /* | 50 | /* |
51 | gst->audiobackend = JACK; | 51 | gst->audiobackend = JACK; |
52 | gst->dropsilence = TRUE; | 52 | gst->dropsilence = TRUE; |
53 | gst->usertp = FALSE; | 53 | gst->usertp = FALSE; |
54 | */ | 54 | */ |
55 | /* Initialize GStreamer */ | 55 | /* Initialize GStreamer */ |
56 | gst_init (&argc, &argv); | 56 | gst_init(&argc, &argv); |
57 | 57 | ||
58 | gst->pipeline = GST_PIPELINE(gst_pipeline_new ("gnunet-media-helper")); | 58 | gst->pipeline = GST_PIPELINE(gst_pipeline_new("gnunet-media-helper")); |
59 | 59 | ||
60 | #ifdef IS_SPEAKER | 60 | #ifdef IS_SPEAKER |
61 | int type = SPEAKER; | 61 | int type = SPEAKER; |
@@ -64,39 +64,34 @@ main (int argc, char *argv[]) | |||
64 | #ifdef IS_MIC | 64 | #ifdef IS_MIC |
65 | int type = MICROPHONE; | 65 | int type = MICROPHONE; |
66 | printf("this is the microphone \n"); | 66 | printf("this is the microphone \n"); |
67 | |||
68 | #endif | 67 | #endif |
69 | if ( type == SPEAKER) | 68 | if (type == SPEAKER) |
70 | { | 69 | { |
71 | 70 | gnunetsrc = GST_ELEMENT(get_app(gst, SOURCE)); | |
72 | gnunetsrc = GST_ELEMENT(get_app(gst, SOURCE)); | 71 | |
73 | 72 | sink = GST_ELEMENT(get_audiobin(gst, SINK)); | |
74 | sink = GST_ELEMENT(get_audiobin(gst, SINK)); | 73 | decoder = GST_ELEMENT(get_coder(gst, DECODER)); |
75 | decoder = GST_ELEMENT(get_coder(gst, DECODER)); | 74 | gst_bin_add_many(GST_BIN(gst->pipeline), gnunetsrc, decoder, sink, NULL); |
76 | gst_bin_add_many( GST_BIN(gst->pipeline), gnunetsrc, decoder, sink, NULL); | 75 | gst_element_link_many(gnunetsrc, decoder, sink, NULL); |
77 | gst_element_link_many( gnunetsrc, decoder, sink , NULL); | 76 | } |
78 | 77 | if (type == MICROPHONE) | |
79 | } | 78 | { |
80 | if ( type == MICROPHONE ) { | 79 | source = GST_ELEMENT(get_audiobin(gst, SOURCE)); |
81 | |||
82 | source = GST_ELEMENT(get_audiobin(gst, SOURCE)); | ||
83 | |||
84 | encoder = GST_ELEMENT(get_coder(gst, ENCODER)); | ||
85 | |||
86 | gnunetsink = GST_ELEMENT(get_app(gst, SINK)); | ||
87 | 80 | ||
88 | gst_bin_add_many( GST_BIN(gst->pipeline), source, encoder, gnunetsink, NULL); | 81 | encoder = GST_ELEMENT(get_coder(gst, ENCODER)); |
89 | gst_element_link_many( source, encoder, gnunetsink , NULL); | ||
90 | 82 | ||
83 | gnunetsink = GST_ELEMENT(get_app(gst, SINK)); | ||
91 | 84 | ||
92 | } | 85 | gst_bin_add_many(GST_BIN(gst->pipeline), source, encoder, gnunetsink, NULL); |
86 | gst_element_link_many(source, encoder, gnunetsink, NULL); | ||
87 | } | ||
93 | /* | 88 | /* |
94 | gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL); | 89 | gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL); |
95 | gst_element_link_many( source, encoder, decoder, sink , NULL); | 90 | gst_element_link_many( source, encoder, decoder, sink , NULL); |
96 | */ | 91 | */ |
97 | pl_graph(gst->pipeline); | 92 | pl_graph(gst->pipeline); |
98 | /* Start playing */ | 93 | /* Start playing */ |
99 | gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_PLAYING); | 94 | gst_element_set_state(GST_ELEMENT(gst->pipeline), GST_STATE_PLAYING); |
100 | 95 | ||
101 | //pl_graph(gst->pipeline); | 96 | //pl_graph(gst->pipeline); |
102 | 97 | ||
@@ -109,14 +104,12 @@ main (int argc, char *argv[]) | |||
109 | 104 | ||
110 | 105 | ||
111 | // start pushing buffers | 106 | // start pushing buffers |
112 | if ( type == MICROPHONE ) | 107 | if (type == MICROPHONE) |
113 | { | 108 | { |
114 | 109 | GMainLoop *loop; | |
110 | loop = g_main_loop_new(NULL, FALSE); | ||
115 | 111 | ||
116 | GMainLoop *loop; | 112 | g_main_loop_run(loop); |
117 | loop = g_main_loop_new (NULL, FALSE); | ||
118 | |||
119 | g_main_loop_run (loop); | ||
120 | 113 | ||
121 | /* | 114 | /* |
122 | while ( 1 ) | 115 | while ( 1 ) |
@@ -124,21 +117,21 @@ main (int argc, char *argv[]) | |||
124 | GstFlowReturn flow; | 117 | GstFlowReturn flow; |
125 | flow = on_appsink_new_sample (gst->appsink, gst); | 118 | flow = on_appsink_new_sample (gst->appsink, gst); |
126 | } | 119 | } |
127 | */ | 120 | */ |
128 | } | 121 | } |
129 | if ( type == SPEAKER ) | 122 | if (type == SPEAKER) |
130 | { | 123 | { |
131 | while ( 1 ) | 124 | while (1) |
132 | { | 125 | { |
133 | // printf("read.. \n"); | 126 | // printf("read.. \n"); |
134 | gnunet_read(gst); | 127 | gnunet_read(gst); |
135 | } | 128 | } |
136 | } | 129 | } |
137 | g_print ("Returned, stopping playback\n"); | 130 | g_print("Returned, stopping playback\n"); |
138 | 131 | ||
139 | // gst_object_unref (bus); | 132 | // gst_object_unref (bus); |
140 | gst_element_set_state (GST_ELEMENT(gst->pipeline), GST_STATE_NULL); | 133 | gst_element_set_state(GST_ELEMENT(gst->pipeline), GST_STATE_NULL); |
141 | gst_object_unref (gst->pipeline); | 134 | gst_object_unref(gst->pipeline); |
142 | 135 | ||
143 | return 0; | 136 | return 0; |
144 | } | 137 | } |
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c index 57588f05a..01f8adb1e 100644 --- a/src/conversation/microphone.c +++ b/src/conversation/microphone.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -34,9 +34,7 @@ | |||
34 | /** | 34 | /** |
35 | * Internal data structures for the microphone. | 35 | * Internal data structures for the microphone. |
36 | */ | 36 | */ |
37 | struct Microphone | 37 | struct Microphone { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Our configuration. | 39 | * Our configuration. |
42 | */ | 40 | */ |
@@ -56,7 +54,6 @@ struct Microphone | |||
56 | * Closure for @e rdc. | 54 | * Closure for @e rdc. |
57 | */ | 55 | */ |
58 | void *rdc_cls; | 56 | void *rdc_cls; |
59 | |||
60 | }; | 57 | }; |
61 | 58 | ||
62 | 59 | ||
@@ -70,21 +67,21 @@ struct Microphone | |||
70 | * #GNUNET_SYSERR to stop further processing with error | 67 | * #GNUNET_SYSERR to stop further processing with error |
71 | */ | 68 | */ |
72 | static int | 69 | static int |
73 | process_record_messages (void *cls, | 70 | process_record_messages(void *cls, |
74 | const struct GNUNET_MessageHeader *msg) | 71 | const struct GNUNET_MessageHeader *msg) |
75 | { | 72 | { |
76 | struct Microphone *mic = cls; | 73 | struct Microphone *mic = cls; |
77 | const struct AudioMessage *am; | 74 | const struct AudioMessage *am; |
78 | 75 | ||
79 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) | 76 | if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) |
80 | { | 77 | { |
81 | GNUNET_break (0); | 78 | GNUNET_break(0); |
82 | return GNUNET_SYSERR; | 79 | return GNUNET_SYSERR; |
83 | } | 80 | } |
84 | am = (const struct AudioMessage *) msg; | 81 | am = (const struct AudioMessage *)msg; |
85 | mic->rdc (mic->rdc_cls, | 82 | mic->rdc(mic->rdc_cls, |
86 | ntohs (msg->size) - sizeof (struct AudioMessage), | 83 | ntohs(msg->size) - sizeof(struct AudioMessage), |
87 | &am[1]); | 84 | &am[1]); |
88 | return GNUNET_OK; | 85 | return GNUNET_OK; |
89 | } | 86 | } |
90 | 87 | ||
@@ -97,9 +94,9 @@ process_record_messages (void *cls, | |||
97 | * @param rdc_cls closure for @a dc | 94 | * @param rdc_cls closure for @a dc |
98 | */ | 95 | */ |
99 | static int | 96 | static int |
100 | enable (void *cls, | 97 | enable(void *cls, |
101 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 98 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
102 | void *rdc_cls) | 99 | void *rdc_cls) |
103 | { | 100 | { |
104 | struct Microphone *mic = cls; | 101 | struct Microphone *mic = cls; |
105 | static char * const record_helper_argv[] = | 102 | static char * const record_helper_argv[] = |
@@ -110,17 +107,17 @@ enable (void *cls, | |||
110 | 107 | ||
111 | mic->rdc = rdc; | 108 | mic->rdc = rdc; |
112 | mic->rdc_cls = rdc_cls; | 109 | mic->rdc_cls = rdc_cls; |
113 | mic->record_helper = GNUNET_HELPER_start (GNUNET_NO, | 110 | mic->record_helper = GNUNET_HELPER_start(GNUNET_NO, |
114 | "gnunet-helper-audio-record", | 111 | "gnunet-helper-audio-record", |
115 | record_helper_argv, | 112 | record_helper_argv, |
116 | &process_record_messages, | 113 | &process_record_messages, |
117 | NULL, mic); | 114 | NULL, mic); |
118 | if (NULL == mic->record_helper) | 115 | if (NULL == mic->record_helper) |
119 | { | 116 | { |
120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 117 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
121 | _("Could not start record audio helper\n")); | 118 | _("Could not start record audio helper\n")); |
122 | return GNUNET_SYSERR; | 119 | return GNUNET_SYSERR; |
123 | } | 120 | } |
124 | return GNUNET_OK; | 121 | return GNUNET_OK; |
125 | } | 122 | } |
126 | 123 | ||
@@ -131,18 +128,18 @@ enable (void *cls, | |||
131 | * @param cls clsoure | 128 | * @param cls clsoure |
132 | */ | 129 | */ |
133 | static void | 130 | static void |
134 | disable (void *cls) | 131 | disable(void *cls) |
135 | { | 132 | { |
136 | struct Microphone *mic = cls; | 133 | struct Microphone *mic = cls; |
137 | 134 | ||
138 | if (NULL == mic->record_helper) | 135 | if (NULL == mic->record_helper) |
139 | { | 136 | { |
140 | GNUNET_break (0); | 137 | GNUNET_break(0); |
141 | return; | 138 | return; |
142 | } | 139 | } |
143 | GNUNET_break (GNUNET_OK == | 140 | GNUNET_break(GNUNET_OK == |
144 | GNUNET_HELPER_kill (mic->record_helper, GNUNET_NO)); | 141 | GNUNET_HELPER_kill(mic->record_helper, GNUNET_NO)); |
145 | GNUNET_HELPER_destroy (mic->record_helper); | 142 | GNUNET_HELPER_destroy(mic->record_helper); |
146 | mic->record_helper = NULL; | 143 | mic->record_helper = NULL; |
147 | } | 144 | } |
148 | 145 | ||
@@ -153,12 +150,12 @@ disable (void *cls) | |||
153 | * @param cls clsoure | 150 | * @param cls clsoure |
154 | */ | 151 | */ |
155 | static void | 152 | static void |
156 | destroy (void *cls) | 153 | destroy(void *cls) |
157 | { | 154 | { |
158 | struct Microphone *mic = cls; | 155 | struct Microphone *mic = cls; |
159 | 156 | ||
160 | if (NULL != mic->record_helper) | 157 | if (NULL != mic->record_helper) |
161 | disable (mic); | 158 | disable(mic); |
162 | } | 159 | } |
163 | 160 | ||
164 | 161 | ||
@@ -170,14 +167,14 @@ destroy (void *cls) | |||
170 | * @return NULL on error | 167 | * @return NULL on error |
171 | */ | 168 | */ |
172 | struct GNUNET_MICROPHONE_Handle * | 169 | struct GNUNET_MICROPHONE_Handle * |
173 | GNUNET_MICROPHONE_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg) |
174 | { | 171 | { |
175 | struct GNUNET_MICROPHONE_Handle *microphone; | 172 | struct GNUNET_MICROPHONE_Handle *microphone; |
176 | struct Microphone *mic; | 173 | struct Microphone *mic; |
177 | 174 | ||
178 | mic = GNUNET_new (struct Microphone); | 175 | mic = GNUNET_new(struct Microphone); |
179 | mic->cfg = cfg; | 176 | mic->cfg = cfg; |
180 | microphone = GNUNET_new (struct GNUNET_MICROPHONE_Handle); | 177 | microphone = GNUNET_new(struct GNUNET_MICROPHONE_Handle); |
181 | microphone->cls = mic; | 178 | microphone->cls = mic; |
182 | microphone->enable_microphone = &enable; | 179 | microphone->enable_microphone = &enable; |
183 | microphone->disable_microphone = &disable; | 180 | microphone->disable_microphone = &disable; |
@@ -192,10 +189,10 @@ GNUNET_MICROPHONE_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle | |||
192 | * @param microphone microphone to destroy | 189 | * @param microphone microphone to destroy |
193 | */ | 190 | */ |
194 | void | 191 | void |
195 | GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone) | 192 | GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone) |
196 | { | 193 | { |
197 | microphone->destroy_microphone (microphone->cls); | 194 | microphone->destroy_microphone(microphone->cls); |
198 | GNUNET_free (microphone); | 195 | GNUNET_free(microphone); |
199 | } | 196 | } |
200 | 197 | ||
201 | /* end of microphone.c */ | 198 | /* end of microphone.c */ |
diff --git a/src/conversation/plugin_gnsrecord_conversation.c b/src/conversation/plugin_gnsrecord_conversation.c index 41c09ade9..adf397333 100644 --- a/src/conversation/plugin_gnsrecord_conversation.c +++ b/src/conversation/plugin_gnsrecord_conversation.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file conversation/plugin_gnsrecord_conversation.c | 22 | * @file conversation/plugin_gnsrecord_conversation.c |
@@ -44,50 +44,51 @@ | |||
44 | * @return NULL on error, otherwise human-readable representation of the value | 44 | * @return NULL on error, otherwise human-readable representation of the value |
45 | */ | 45 | */ |
46 | static char * | 46 | static char * |
47 | conversation_value_to_string (void *cls, | 47 | conversation_value_to_string(void *cls, |
48 | uint32_t type, | 48 | uint32_t type, |
49 | const void *data, | 49 | const void *data, |
50 | size_t data_size) | 50 | size_t data_size) |
51 | { | 51 | { |
52 | char *s; | 52 | char *s; |
53 | 53 | ||
54 | (void) cls; | 54 | (void)cls; |
55 | switch (type) | 55 | switch (type) |
56 | { | 56 | { |
57 | case GNUNET_GNSRECORD_TYPE_PHONE: | 57 | case GNUNET_GNSRECORD_TYPE_PHONE: |
58 | { | 58 | { |
59 | const struct GNUNET_CONVERSATION_PhoneRecord *pr; | 59 | const struct GNUNET_CONVERSATION_PhoneRecord *pr; |
60 | char *ret; | 60 | char *ret; |
61 | char *pkey; | 61 | char *pkey; |
62 | 62 | ||
63 | if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord)) | 63 | if (data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord)) |
64 | { | 64 | { |
65 | GNUNET_break_op (0); | 65 | GNUNET_break_op(0); |
66 | return NULL; | 66 | return NULL; |
67 | } | 67 | } |
68 | pr = data; | 68 | pr = data; |
69 | if (1 != ntohl (pr->version)) | 69 | if (1 != ntohl(pr->version)) |
70 | { | 70 | { |
71 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 71 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
72 | _("PHONE version %u not supported\n"), | 72 | _("PHONE version %u not supported\n"), |
73 | ntohl (pr->version)); | 73 | ntohl(pr->version)); |
74 | return NULL; | 74 | return NULL; |
75 | } | 75 | } |
76 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key); | 76 | pkey = GNUNET_CRYPTO_eddsa_public_key_to_string(&pr->peer.public_key); |
77 | s = GNUNET_STRINGS_data_to_string_alloc (&pr->line_port, | 77 | s = GNUNET_STRINGS_data_to_string_alloc(&pr->line_port, |
78 | sizeof (struct GNUNET_HashCode)); | 78 | sizeof(struct GNUNET_HashCode)); |
79 | 79 | ||
80 | GNUNET_asprintf (&ret, | 80 | GNUNET_asprintf(&ret, |
81 | "%s-%s", | 81 | "%s-%s", |
82 | s, | 82 | s, |
83 | pkey); | 83 | pkey); |
84 | GNUNET_free (s); | 84 | GNUNET_free(s); |
85 | GNUNET_free (pkey); | 85 | GNUNET_free(pkey); |
86 | return ret; | 86 | return ret; |
87 | } | 87 | } |
88 | default: | 88 | |
89 | return NULL; | 89 | default: |
90 | } | 90 | return NULL; |
91 | } | ||
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
@@ -103,62 +104,63 @@ conversation_value_to_string (void *cls, | |||
103 | * @return #GNUNET_OK on success | 104 | * @return #GNUNET_OK on success |
104 | */ | 105 | */ |
105 | static int | 106 | static int |
106 | conversation_string_to_value (void *cls, | 107 | conversation_string_to_value(void *cls, |
107 | uint32_t type, | 108 | uint32_t type, |
108 | const char *s, | 109 | const char *s, |
109 | void **data, | 110 | void **data, |
110 | size_t *data_size) | 111 | size_t *data_size) |
111 | { | 112 | { |
112 | (void) cls; | 113 | (void)cls; |
113 | if (NULL == s) | 114 | if (NULL == s) |
114 | { | 115 | { |
115 | GNUNET_break (0); | 116 | GNUNET_break(0); |
116 | return GNUNET_SYSERR; | 117 | return GNUNET_SYSERR; |
117 | } | 118 | } |
118 | switch (type) | 119 | switch (type) |
119 | { | 120 | { |
120 | case GNUNET_GNSRECORD_TYPE_PHONE: | 121 | case GNUNET_GNSRECORD_TYPE_PHONE: |
121 | { | 122 | { |
122 | struct GNUNET_CONVERSATION_PhoneRecord *pr; | 123 | struct GNUNET_CONVERSATION_PhoneRecord *pr; |
123 | char line_port[103]; | 124 | char line_port[103]; |
124 | const char *dash; | 125 | const char *dash; |
125 | struct GNUNET_PeerIdentity peer; | 126 | struct GNUNET_PeerIdentity peer; |
126 | 127 | ||
127 | if ( (NULL == (dash = strchr (s, '-'))) || | 128 | if ((NULL == (dash = strchr(s, '-'))) || |
128 | (1 != sscanf (s, "%103s-", line_port)) || | 129 | (1 != sscanf(s, "%103s-", line_port)) || |
129 | (GNUNET_OK != | 130 | (GNUNET_OK != |
130 | GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, | 131 | GNUNET_CRYPTO_eddsa_public_key_from_string(dash + 1, |
131 | strlen (dash + 1), | 132 | strlen(dash + 1), |
132 | &peer.public_key)) ) | 133 | &peer.public_key))) |
133 | { | 134 | { |
134 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 135 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
135 | _("Unable to parse PHONE record `%s'\n"), | 136 | _("Unable to parse PHONE record `%s'\n"), |
136 | s); | 137 | s); |
137 | return GNUNET_SYSERR; | 138 | return GNUNET_SYSERR; |
138 | } | 139 | } |
139 | pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord); | 140 | pr = GNUNET_new(struct GNUNET_CONVERSATION_PhoneRecord); |
140 | pr->version = htonl (1); | 141 | pr->version = htonl(1); |
141 | pr->reserved = htonl (0); | 142 | pr->reserved = htonl(0); |
142 | if (GNUNET_OK != | 143 | if (GNUNET_OK != |
143 | GNUNET_STRINGS_string_to_data (line_port, | 144 | GNUNET_STRINGS_string_to_data(line_port, |
144 | strlen (line_port), | 145 | strlen(line_port), |
145 | &pr->line_port, | 146 | &pr->line_port, |
146 | sizeof (struct GNUNET_HashCode))) | 147 | sizeof(struct GNUNET_HashCode))) |
147 | { | 148 | { |
148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 149 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
149 | _("Unable to parse PHONE record `%s'\n"), | 150 | _("Unable to parse PHONE record `%s'\n"), |
150 | s); | 151 | s); |
151 | GNUNET_free (pr); | 152 | GNUNET_free(pr); |
152 | return GNUNET_SYSERR; | 153 | return GNUNET_SYSERR; |
153 | } | 154 | } |
154 | pr->peer = peer; | 155 | pr->peer = peer; |
155 | *data = pr; | 156 | *data = pr; |
156 | *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord); | 157 | *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord); |
157 | return GNUNET_OK; | 158 | return GNUNET_OK; |
158 | } | 159 | } |
159 | default: | 160 | |
160 | return GNUNET_SYSERR; | 161 | default: |
161 | } | 162 | return GNUNET_SYSERR; |
163 | } | ||
162 | } | 164 | } |
163 | 165 | ||
164 | 166 | ||
@@ -170,7 +172,7 @@ static struct { | |||
170 | const char *name; | 172 | const char *name; |
171 | uint32_t number; | 173 | uint32_t number; |
172 | } name_map[] = { | 174 | } name_map[] = { |
173 | { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE }, | 175 | { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE }, |
174 | { NULL, UINT32_MAX } | 176 | { NULL, UINT32_MAX } |
175 | }; | 177 | }; |
176 | 178 | ||
@@ -183,15 +185,15 @@ static struct { | |||
183 | * @return corresponding number, UINT32_MAX on error | 185 | * @return corresponding number, UINT32_MAX on error |
184 | */ | 186 | */ |
185 | static uint32_t | 187 | static uint32_t |
186 | conversation_typename_to_number (void *cls, | 188 | conversation_typename_to_number(void *cls, |
187 | const char *gns_typename) | 189 | const char *gns_typename) |
188 | { | 190 | { |
189 | unsigned int i; | 191 | unsigned int i; |
190 | 192 | ||
191 | (void) cls; | 193 | (void)cls; |
192 | i=0; | 194 | i = 0; |
193 | while ( (name_map[i].name != NULL) && | 195 | while ((name_map[i].name != NULL) && |
194 | (0 != strcasecmp (gns_typename, name_map[i].name)) ) | 196 | (0 != strcasecmp(gns_typename, name_map[i].name))) |
195 | i++; | 197 | i++; |
196 | return name_map[i].number; | 198 | return name_map[i].number; |
197 | } | 199 | } |
@@ -205,15 +207,15 @@ conversation_typename_to_number (void *cls, | |||
205 | * @return corresponding typestring, NULL on error | 207 | * @return corresponding typestring, NULL on error |
206 | */ | 208 | */ |
207 | static const char * | 209 | static const char * |
208 | conversation_number_to_typename (void *cls, | 210 | conversation_number_to_typename(void *cls, |
209 | uint32_t type) | 211 | uint32_t type) |
210 | { | 212 | { |
211 | unsigned int i; | 213 | unsigned int i; |
212 | 214 | ||
213 | (void) cls; | 215 | (void)cls; |
214 | i=0; | 216 | i = 0; |
215 | while ( (name_map[i].name != NULL) && | 217 | while ((name_map[i].name != NULL) && |
216 | (type != name_map[i].number) ) | 218 | (type != name_map[i].number)) |
217 | i++; | 219 | i++; |
218 | return name_map[i].name; | 220 | return name_map[i].name; |
219 | } | 221 | } |
@@ -226,12 +228,12 @@ conversation_number_to_typename (void *cls, | |||
226 | * @return the exported block API | 228 | * @return the exported block API |
227 | */ | 229 | */ |
228 | void * | 230 | void * |
229 | libgnunet_plugin_gnsrecord_conversation_init (void *cls) | 231 | libgnunet_plugin_gnsrecord_conversation_init(void *cls) |
230 | { | 232 | { |
231 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 233 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
232 | 234 | ||
233 | (void) cls; | 235 | (void)cls; |
234 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); | 236 | api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); |
235 | api->value_to_string = &conversation_value_to_string; | 237 | api->value_to_string = &conversation_value_to_string; |
236 | api->string_to_value = &conversation_string_to_value; | 238 | api->string_to_value = &conversation_string_to_value; |
237 | api->typename_to_number = &conversation_typename_to_number; | 239 | api->typename_to_number = &conversation_typename_to_number; |
@@ -247,11 +249,11 @@ libgnunet_plugin_gnsrecord_conversation_init (void *cls) | |||
247 | * @return NULL | 249 | * @return NULL |
248 | */ | 250 | */ |
249 | void * | 251 | void * |
250 | libgnunet_plugin_gnsrecord_conversation_done (void *cls) | 252 | libgnunet_plugin_gnsrecord_conversation_done(void *cls) |
251 | { | 253 | { |
252 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 254 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
253 | 255 | ||
254 | GNUNET_free (api); | 256 | GNUNET_free(api); |
255 | return NULL; | 257 | return NULL; |
256 | } | 258 | } |
257 | 259 | ||
diff --git a/src/conversation/speaker.c b/src/conversation/speaker.c index e2ace9115..96fd42b8d 100644 --- a/src/conversation/speaker.c +++ b/src/conversation/speaker.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -33,8 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Internal data structures for the speaker. | 34 | * Internal data structures for the speaker. |
35 | */ | 35 | */ |
36 | struct Speaker | 36 | struct Speaker { |
37 | { | ||
38 | /** | 37 | /** |
39 | * Our configuration. | 38 | * Our configuration. |
40 | */ | 39 | */ |
@@ -44,7 +43,6 @@ struct Speaker | |||
44 | * Handle for the playback helper | 43 | * Handle for the playback helper |
45 | */ | 44 | */ |
46 | struct GNUNET_HELPER_Handle *playback_helper; | 45 | struct GNUNET_HELPER_Handle *playback_helper; |
47 | |||
48 | }; | 46 | }; |
49 | 47 | ||
50 | 48 | ||
@@ -55,7 +53,7 @@ struct Speaker | |||
55 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 53 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
56 | */ | 54 | */ |
57 | static int | 55 | static int |
58 | enable (void *cls) | 56 | enable(void *cls) |
59 | { | 57 | { |
60 | struct Speaker *spe = cls; | 58 | struct Speaker *spe = cls; |
61 | static char *playback_helper_argv[] = | 59 | static char *playback_helper_argv[] = |
@@ -64,17 +62,17 @@ enable (void *cls) | |||
64 | NULL | 62 | NULL |
65 | }; | 63 | }; |
66 | 64 | ||
67 | spe->playback_helper = GNUNET_HELPER_start (GNUNET_NO, | 65 | spe->playback_helper = GNUNET_HELPER_start(GNUNET_NO, |
68 | "gnunet-helper-audio-playback", | 66 | "gnunet-helper-audio-playback", |
69 | playback_helper_argv, | 67 | playback_helper_argv, |
70 | NULL, | 68 | NULL, |
71 | NULL, spe); | 69 | NULL, spe); |
72 | if (NULL == spe->playback_helper) | 70 | if (NULL == spe->playback_helper) |
73 | { | 71 | { |
74 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 72 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
75 | _("Could not start playback audio helper.\n")); | 73 | _("Could not start playback audio helper.\n")); |
76 | return GNUNET_SYSERR; | 74 | return GNUNET_SYSERR; |
77 | } | 75 | } |
78 | return GNUNET_OK; | 76 | return GNUNET_OK; |
79 | } | 77 | } |
80 | 78 | ||
@@ -85,18 +83,18 @@ enable (void *cls) | |||
85 | * @param cls closure with the `struct Speaker` | 83 | * @param cls closure with the `struct Speaker` |
86 | */ | 84 | */ |
87 | static void | 85 | static void |
88 | disable (void *cls) | 86 | disable(void *cls) |
89 | { | 87 | { |
90 | struct Speaker *spe = cls; | 88 | struct Speaker *spe = cls; |
91 | 89 | ||
92 | if (NULL == spe->playback_helper) | 90 | if (NULL == spe->playback_helper) |
93 | { | 91 | { |
94 | GNUNET_break (0); | 92 | GNUNET_break(0); |
95 | return; | 93 | return; |
96 | } | 94 | } |
97 | GNUNET_break (GNUNET_OK == | 95 | GNUNET_break(GNUNET_OK == |
98 | GNUNET_HELPER_kill (spe->playback_helper, GNUNET_NO)); | 96 | GNUNET_HELPER_kill(spe->playback_helper, GNUNET_NO)); |
99 | GNUNET_HELPER_destroy (spe->playback_helper); | 97 | GNUNET_HELPER_destroy(spe->playback_helper); |
100 | spe->playback_helper = NULL; | 98 | spe->playback_helper = NULL; |
101 | } | 99 | } |
102 | 100 | ||
@@ -107,12 +105,12 @@ disable (void *cls) | |||
107 | * @param cls closure with the `struct Speaker` | 105 | * @param cls closure with the `struct Speaker` |
108 | */ | 106 | */ |
109 | static void | 107 | static void |
110 | destroy (void *cls) | 108 | destroy(void *cls) |
111 | { | 109 | { |
112 | struct Speaker *spe = cls; | 110 | struct Speaker *spe = cls; |
113 | 111 | ||
114 | if (NULL != spe->playback_helper) | 112 | if (NULL != spe->playback_helper) |
115 | disable (spe); | 113 | disable(spe); |
116 | } | 114 | } |
117 | 115 | ||
118 | 116 | ||
@@ -125,27 +123,27 @@ destroy (void *cls) | |||
125 | * opaque to the API but should be OPUS. | 123 | * opaque to the API but should be OPUS. |
126 | */ | 124 | */ |
127 | static void | 125 | static void |
128 | play (void *cls, | 126 | play(void *cls, |
129 | size_t data_size, | 127 | size_t data_size, |
130 | const void *data) | 128 | const void *data) |
131 | { | 129 | { |
132 | struct Speaker *spe = cls; | 130 | struct Speaker *spe = cls; |
133 | char buf[sizeof (struct AudioMessage) + data_size]; | 131 | char buf[sizeof(struct AudioMessage) + data_size]; |
134 | struct AudioMessage *am; | 132 | struct AudioMessage *am; |
135 | 133 | ||
136 | if (NULL == spe->playback_helper) | 134 | if (NULL == spe->playback_helper) |
137 | { | 135 | { |
138 | GNUNET_break (0); | 136 | GNUNET_break(0); |
139 | return; | 137 | return; |
140 | } | 138 | } |
141 | am = (struct AudioMessage *) buf; | 139 | am = (struct AudioMessage *)buf; |
142 | am->header.size = htons (sizeof (struct AudioMessage) + data_size); | 140 | am->header.size = htons(sizeof(struct AudioMessage) + data_size); |
143 | am->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 141 | am->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
144 | GNUNET_memcpy (&am[1], data, data_size); | 142 | GNUNET_memcpy(&am[1], data, data_size); |
145 | (void) GNUNET_HELPER_send (spe->playback_helper, | 143 | (void)GNUNET_HELPER_send(spe->playback_helper, |
146 | &am->header, | 144 | &am->header, |
147 | GNUNET_NO, | 145 | GNUNET_NO, |
148 | NULL, NULL); | 146 | NULL, NULL); |
149 | } | 147 | } |
150 | 148 | ||
151 | 149 | ||
@@ -157,14 +155,14 @@ play (void *cls, | |||
157 | * @return NULL on error | 155 | * @return NULL on error |
158 | */ | 156 | */ |
159 | struct GNUNET_SPEAKER_Handle * | 157 | struct GNUNET_SPEAKER_Handle * |
160 | GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg) |
161 | { | 159 | { |
162 | struct GNUNET_SPEAKER_Handle *speaker; | 160 | struct GNUNET_SPEAKER_Handle *speaker; |
163 | struct Speaker *spe; | 161 | struct Speaker *spe; |
164 | 162 | ||
165 | spe = GNUNET_new (struct Speaker); | 163 | spe = GNUNET_new(struct Speaker); |
166 | spe->cfg = cfg; | 164 | spe->cfg = cfg; |
167 | speaker = GNUNET_new (struct GNUNET_SPEAKER_Handle); | 165 | speaker = GNUNET_new(struct GNUNET_SPEAKER_Handle); |
168 | speaker->cls = spe; | 166 | speaker->cls = spe; |
169 | speaker->enable_speaker = &enable; | 167 | speaker->enable_speaker = &enable; |
170 | speaker->play = &play; | 168 | speaker->play = &play; |
@@ -180,10 +178,10 @@ GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *c | |||
180 | * @param speaker speaker to destroy | 178 | * @param speaker speaker to destroy |
181 | */ | 179 | */ |
182 | void | 180 | void |
183 | GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker) | 181 | GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker) |
184 | { | 182 | { |
185 | speaker->destroy_speaker (speaker->cls); | 183 | speaker->destroy_speaker(speaker->cls); |
186 | GNUNET_free (speaker); | 184 | GNUNET_free(speaker); |
187 | } | 185 | } |
188 | 186 | ||
189 | /* end of speaker.c */ | 187 | /* end of speaker.c */ |
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c index a7b394dc3..e58f89e7a 100644 --- a/src/conversation/test_conversation_api.c +++ b/src/conversation/test_conversation_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/test_conversation_api.c | 21 | * @file conversation/test_conversation_api.c |
22 | * @brief testcase for conversation_api.c | 22 | * @brief testcase for conversation_api.c |
@@ -33,9 +33,9 @@ | |||
33 | #include "gnunet_identity_service.h" | 33 | #include "gnunet_identity_service.h" |
34 | #include "gnunet_namestore_service.h" | 34 | #include "gnunet_namestore_service.h" |
35 | 35 | ||
36 | #define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) | 36 | #define FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) |
37 | 37 | ||
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 25) |
39 | 39 | ||
40 | static int ok = 1; | 40 | static int ok = 1; |
41 | 41 | ||
@@ -73,174 +73,174 @@ static struct GNUNET_SCHEDULER_Task *call_task; | |||
73 | 73 | ||
74 | 74 | ||
75 | static void | 75 | static void |
76 | phone_send (void *cls) | 76 | phone_send(void *cls) |
77 | { | 77 | { |
78 | static unsigned int i; | 78 | static unsigned int i; |
79 | char buf[32]; | 79 | char buf[32]; |
80 | 80 | ||
81 | (void) cls; | 81 | (void)cls; |
82 | GNUNET_assert (NULL != phone_rdc); | 82 | GNUNET_assert(NULL != phone_rdc); |
83 | GNUNET_snprintf (buf, sizeof (buf), "phone-%u", i++); | 83 | GNUNET_snprintf(buf, sizeof(buf), "phone-%u", i++); |
84 | phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); | 84 | phone_rdc(phone_rdc_cls, strlen(buf) + 1, buf); |
85 | phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL); | 85 | phone_task = GNUNET_SCHEDULER_add_delayed(FREQ, &phone_send, NULL); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | static void | 89 | static void |
90 | call_send (void *cls) | 90 | call_send(void *cls) |
91 | { | 91 | { |
92 | static unsigned int i; | 92 | static unsigned int i; |
93 | char buf[32]; | 93 | char buf[32]; |
94 | 94 | ||
95 | (void) cls; | 95 | (void)cls; |
96 | GNUNET_assert (NULL != call_rdc); | 96 | GNUNET_assert(NULL != call_rdc); |
97 | GNUNET_snprintf (buf, sizeof (buf), "call-%u", i++); | 97 | GNUNET_snprintf(buf, sizeof(buf), "call-%u", i++); |
98 | call_rdc (call_rdc_cls, strlen (buf) + 1, buf); | 98 | call_rdc(call_rdc_cls, strlen(buf) + 1, buf); |
99 | call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, NULL); | 99 | call_task = GNUNET_SCHEDULER_add_delayed(FREQ, &call_send, NULL); |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | static int | 103 | static int |
104 | enable_speaker (void *cls) | 104 | enable_speaker(void *cls) |
105 | { | 105 | { |
106 | const char *origin = cls; | 106 | const char *origin = cls; |
107 | 107 | ||
108 | fprintf (stderr, "Speaker %s enabled\n", origin); | 108 | fprintf(stderr, "Speaker %s enabled\n", origin); |
109 | return GNUNET_OK; | 109 | return GNUNET_OK; |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | static void | 113 | static void |
114 | disable_speaker (void *cls) | 114 | disable_speaker(void *cls) |
115 | { | 115 | { |
116 | const char *origin = cls; | 116 | const char *origin = cls; |
117 | 117 | ||
118 | fprintf (stderr, "Speaker %s disabled\n", origin); | 118 | fprintf(stderr, "Speaker %s disabled\n", origin); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | static void | 122 | static void |
123 | play (void *cls, size_t data_size, const void *data) | 123 | play(void *cls, size_t data_size, const void *data) |
124 | { | 124 | { |
125 | const char *origin = cls; | 125 | const char *origin = cls; |
126 | static unsigned int phone_i = 1; | 126 | static unsigned int phone_i = 1; |
127 | static unsigned int call_i; | 127 | static unsigned int call_i; |
128 | char buf[32]; | 128 | char buf[32]; |
129 | 129 | ||
130 | if (0 == strcmp (origin, "phone")) | 130 | if (0 == strcmp(origin, "phone")) |
131 | GNUNET_snprintf (buf, sizeof (buf), "call-%u", call_i++); | 131 | GNUNET_snprintf(buf, sizeof(buf), "call-%u", call_i++); |
132 | else | 132 | else |
133 | GNUNET_snprintf (buf, sizeof (buf), "phone-%u", phone_i++); | 133 | GNUNET_snprintf(buf, sizeof(buf), "phone-%u", phone_i++); |
134 | if ((data_size != strlen (buf) + 1) || (0 != strncmp (buf, data, data_size))) | 134 | if ((data_size != strlen(buf) + 1) || (0 != strncmp(buf, data, data_size))) |
135 | { | 135 | { |
136 | fprintf (stderr, | 136 | fprintf(stderr, |
137 | "Expected %s, received %.*s\n", | 137 | "Expected %s, received %.*s\n", |
138 | buf, | 138 | buf, |
139 | (int) data_size, | 139 | (int)data_size, |
140 | (const char *) data); | 140 | (const char *)data); |
141 | } | 141 | } |
142 | else | 142 | else |
143 | { | 143 | { |
144 | fprintf (stderr, "."); | 144 | fprintf(stderr, "."); |
145 | } | 145 | } |
146 | if ((20 < call_i) && (20 < phone_i) && (NULL != call)) | 146 | if ((20 < call_i) && (20 < phone_i) && (NULL != call)) |
147 | { | 147 | { |
148 | /* time to hang up ... */ | 148 | /* time to hang up ... */ |
149 | GNUNET_CONVERSATION_call_stop (call); | 149 | GNUNET_CONVERSATION_call_stop(call); |
150 | call = NULL; | 150 | call = NULL; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | static void | 155 | static void |
156 | destroy_speaker (void *cls) | 156 | destroy_speaker(void *cls) |
157 | { | 157 | { |
158 | const char *origin = cls; | 158 | const char *origin = cls; |
159 | 159 | ||
160 | fprintf (stderr, "Speaker %s destroyed\n", origin); | 160 | fprintf(stderr, "Speaker %s destroyed\n", origin); |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | static struct GNUNET_SPEAKER_Handle call_speaker = {&enable_speaker, | 164 | static struct GNUNET_SPEAKER_Handle call_speaker = { &enable_speaker, |
165 | &play, | ||
166 | &disable_speaker, | ||
167 | &destroy_speaker, | ||
168 | "caller"}; | ||
169 | |||
170 | |||
171 | static struct GNUNET_SPEAKER_Handle phone_speaker = {&enable_speaker, | ||
172 | &play, | 165 | &play, |
173 | &disable_speaker, | 166 | &disable_speaker, |
174 | &destroy_speaker, | 167 | &destroy_speaker, |
175 | "phone"}; | 168 | "caller" }; |
169 | |||
170 | |||
171 | static struct GNUNET_SPEAKER_Handle phone_speaker = { &enable_speaker, | ||
172 | &play, | ||
173 | &disable_speaker, | ||
174 | &destroy_speaker, | ||
175 | "phone" }; | ||
176 | 176 | ||
177 | 177 | ||
178 | static int | 178 | static int |
179 | enable_mic (void *cls, | 179 | enable_mic(void *cls, |
180 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 180 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
181 | void *rdc_cls) | 181 | void *rdc_cls) |
182 | { | 182 | { |
183 | const char *origin = cls; | 183 | const char *origin = cls; |
184 | 184 | ||
185 | fprintf (stderr, "Mic %s enabled\n", origin); | 185 | fprintf(stderr, "Mic %s enabled\n", origin); |
186 | if (0 == strcmp (origin, "phone")) | 186 | if (0 == strcmp(origin, "phone")) |
187 | { | 187 | { |
188 | phone_rdc = rdc; | 188 | phone_rdc = rdc; |
189 | phone_rdc_cls = rdc_cls; | 189 | phone_rdc_cls = rdc_cls; |
190 | phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL); | 190 | phone_task = GNUNET_SCHEDULER_add_now(&phone_send, NULL); |
191 | } | 191 | } |
192 | else | 192 | else |
193 | { | 193 | { |
194 | call_rdc = rdc; | 194 | call_rdc = rdc; |
195 | call_rdc_cls = rdc_cls; | 195 | call_rdc_cls = rdc_cls; |
196 | call_task = GNUNET_SCHEDULER_add_now (&call_send, NULL); | 196 | call_task = GNUNET_SCHEDULER_add_now(&call_send, NULL); |
197 | } | 197 | } |
198 | return GNUNET_OK; | 198 | return GNUNET_OK; |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | static void | 202 | static void |
203 | disable_mic (void *cls) | 203 | disable_mic(void *cls) |
204 | { | 204 | { |
205 | const char *origin = cls; | 205 | const char *origin = cls; |
206 | 206 | ||
207 | fprintf (stderr, "Mic %s disabled\n", origin); | 207 | fprintf(stderr, "Mic %s disabled\n", origin); |
208 | if (0 == strcmp (origin, "phone")) | 208 | if (0 == strcmp(origin, "phone")) |
209 | { | 209 | { |
210 | phone_rdc = NULL; | 210 | phone_rdc = NULL; |
211 | phone_rdc_cls = NULL; | 211 | phone_rdc_cls = NULL; |
212 | GNUNET_SCHEDULER_cancel (phone_task); | 212 | GNUNET_SCHEDULER_cancel(phone_task); |
213 | phone_task = NULL; | 213 | phone_task = NULL; |
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | call_rdc = NULL; | 217 | call_rdc = NULL; |
218 | call_rdc_cls = NULL; | 218 | call_rdc_cls = NULL; |
219 | GNUNET_SCHEDULER_cancel (call_task); | 219 | GNUNET_SCHEDULER_cancel(call_task); |
220 | call_task = NULL; | 220 | call_task = NULL; |
221 | } | 221 | } |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | static void | 225 | static void |
226 | destroy_mic (void *cls) | 226 | destroy_mic(void *cls) |
227 | { | 227 | { |
228 | const char *origin = cls; | 228 | const char *origin = cls; |
229 | 229 | ||
230 | fprintf (stderr, "Mic %s destroyed\n", origin); | 230 | fprintf(stderr, "Mic %s destroyed\n", origin); |
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | static struct GNUNET_MICROPHONE_Handle call_mic = {&enable_mic, | 234 | static struct GNUNET_MICROPHONE_Handle call_mic = { &enable_mic, |
235 | &disable_mic, | ||
236 | &destroy_mic, | ||
237 | "caller"}; | ||
238 | |||
239 | |||
240 | static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic, | ||
241 | &disable_mic, | 235 | &disable_mic, |
242 | &destroy_mic, | 236 | &destroy_mic, |
243 | "phone"}; | 237 | "caller" }; |
238 | |||
239 | |||
240 | static struct GNUNET_MICROPHONE_Handle phone_mic = { &enable_mic, | ||
241 | &disable_mic, | ||
242 | &destroy_mic, | ||
243 | "phone" }; | ||
244 | 244 | ||
245 | 245 | ||
246 | /** | 246 | /** |
@@ -249,248 +249,254 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic, | |||
249 | * @param cls closure | 249 | * @param cls closure |
250 | */ | 250 | */ |
251 | static void | 251 | static void |
252 | end_test (void *cls) | 252 | end_test(void *cls) |
253 | { | 253 | { |
254 | (void) cls; | 254 | (void)cls; |
255 | GNUNET_SCHEDULER_shutdown (); | 255 | GNUNET_SCHEDULER_shutdown(); |
256 | if (NULL != op) | 256 | if (NULL != op) |
257 | { | 257 | { |
258 | GNUNET_IDENTITY_cancel (op); | 258 | GNUNET_IDENTITY_cancel(op); |
259 | op = NULL; | 259 | op = NULL; |
260 | } | 260 | } |
261 | if (NULL != call) | 261 | if (NULL != call) |
262 | { | 262 | { |
263 | GNUNET_CONVERSATION_call_stop (call); | 263 | GNUNET_CONVERSATION_call_stop(call); |
264 | call = NULL; | 264 | call = NULL; |
265 | } | 265 | } |
266 | if (NULL != phone) | 266 | if (NULL != phone) |
267 | { | 267 | { |
268 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | 268 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); |
269 | GNUNET_CONVERSATION_phone_destroy (phone); | 269 | GNUNET_CONVERSATION_phone_destroy(phone); |
270 | phone = NULL; | 270 | phone = NULL; |
271 | } | 271 | } |
272 | if (NULL != id) | 272 | if (NULL != id) |
273 | { | 273 | { |
274 | GNUNET_IDENTITY_disconnect (id); | 274 | GNUNET_IDENTITY_disconnect(id); |
275 | id = NULL; | 275 | id = NULL; |
276 | } | 276 | } |
277 | if (NULL != qe) | 277 | if (NULL != qe) |
278 | { | 278 | { |
279 | GNUNET_NAMESTORE_cancel (qe); | 279 | GNUNET_NAMESTORE_cancel(qe); |
280 | qe = NULL; | 280 | qe = NULL; |
281 | } | 281 | } |
282 | if (NULL != ns) | 282 | if (NULL != ns) |
283 | { | 283 | { |
284 | GNUNET_NAMESTORE_disconnect (ns); | 284 | GNUNET_NAMESTORE_disconnect(ns); |
285 | ns = NULL; | 285 | ns = NULL; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | static void | 290 | static void |
291 | caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | 291 | caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) |
292 | { | 292 | { |
293 | (void) cls; | 293 | (void)cls; |
294 | switch (code) | 294 | switch (code) |
295 | { | 295 | { |
296 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | 296 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: |
297 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | 297 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: |
298 | fprintf (stderr, "Unexpected caller code: %d\n", code); | 298 | fprintf(stderr, "Unexpected caller code: %d\n", code); |
299 | break; | 299 | break; |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | static void | 304 | static void |
305 | phone_event_handler (void *cls, | 305 | phone_event_handler(void *cls, |
306 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 306 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
307 | struct GNUNET_CONVERSATION_Caller *caller, | 307 | struct GNUNET_CONVERSATION_Caller *caller, |
308 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 308 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
309 | { | 309 | { |
310 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = | 310 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = |
311 | GNUNET_CONVERSATION_EC_PHONE_RING; | 311 | GNUNET_CONVERSATION_EC_PHONE_RING; |
312 | 312 | ||
313 | (void) cls; | 313 | (void)cls; |
314 | (void) caller_id; | 314 | (void)caller_id; |
315 | GNUNET_break (code == expect); | 315 | GNUNET_break(code == expect); |
316 | switch (code) | 316 | switch (code) |
317 | { | 317 | { |
318 | case GNUNET_CONVERSATION_EC_PHONE_RING: | 318 | case GNUNET_CONVERSATION_EC_PHONE_RING: |
319 | active_caller = caller; | 319 | active_caller = caller; |
320 | GNUNET_CONVERSATION_caller_pick_up (caller, | 320 | GNUNET_CONVERSATION_caller_pick_up(caller, |
321 | &caller_event_handler, | 321 | &caller_event_handler, |
322 | NULL, | 322 | NULL, |
323 | &phone_speaker, | 323 | &phone_speaker, |
324 | &phone_mic); | 324 | &phone_mic); |
325 | expect = GNUNET_CONVERSATION_EC_PHONE_HUNG_UP; | 325 | expect = GNUNET_CONVERSATION_EC_PHONE_HUNG_UP; |
326 | break; | 326 | break; |
327 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | 327 | |
328 | GNUNET_break (caller == active_caller); | 328 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: |
329 | active_caller = NULL; | 329 | GNUNET_break(caller == active_caller); |
330 | if (1 == ok) | 330 | active_caller = NULL; |
331 | ok = 0; | 331 | if (1 == ok) |
332 | GNUNET_SCHEDULER_shutdown (); | 332 | ok = 0; |
333 | break; | 333 | GNUNET_SCHEDULER_shutdown(); |
334 | default: | 334 | break; |
335 | fprintf (stderr, "Unexpected phone code: %d\n", code); | 335 | |
336 | break; | 336 | default: |
337 | } | 337 | fprintf(stderr, "Unexpected phone code: %d\n", code); |
338 | break; | ||
339 | } | ||
338 | } | 340 | } |
339 | 341 | ||
340 | 342 | ||
341 | static void | 343 | static void |
342 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 344 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
343 | { | 345 | { |
344 | static enum GNUNET_CONVERSATION_CallEventCode expect = | 346 | static enum GNUNET_CONVERSATION_CallEventCode expect = |
345 | GNUNET_CONVERSATION_EC_CALL_RINGING; | 347 | GNUNET_CONVERSATION_EC_CALL_RINGING; |
346 | 348 | ||
347 | (void) cls; | 349 | (void)cls; |
348 | GNUNET_break (code == expect); | 350 | GNUNET_break(code == expect); |
349 | switch (code) | 351 | switch (code) |
350 | { | 352 | { |
351 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 353 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
352 | expect = GNUNET_CONVERSATION_EC_CALL_PICKED_UP; | 354 | expect = GNUNET_CONVERSATION_EC_CALL_PICKED_UP; |
353 | break; | 355 | break; |
354 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 356 | |
355 | expect = -1; | 357 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
356 | break; | 358 | expect = -1; |
357 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 359 | break; |
358 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 360 | |
359 | call = NULL; | 361 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
360 | ok = 2; | 362 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
361 | GNUNET_break (0); | 363 | call = NULL; |
362 | fprintf (stderr, "Unexpected call code: %d\n", code); | 364 | ok = 2; |
363 | break; | 365 | GNUNET_break(0); |
364 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 366 | fprintf(stderr, "Unexpected call code: %d\n", code); |
365 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 367 | break; |
366 | GNUNET_break (0); | 368 | |
367 | fprintf (stderr, "Unexpected call code: %d\n", code); | 369 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
368 | ok = 2; | 370 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
369 | break; | 371 | GNUNET_break(0); |
370 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 372 | fprintf(stderr, "Unexpected call code: %d\n", code); |
371 | GNUNET_break (0); | 373 | ok = 2; |
372 | fprintf (stderr, "Unexpected call code: %d\n", code); | 374 | break; |
373 | call = NULL; | 375 | |
374 | ok = 2; | 376 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
375 | break; | 377 | GNUNET_break(0); |
376 | } | 378 | fprintf(stderr, "Unexpected call code: %d\n", code); |
379 | call = NULL; | ||
380 | ok = 2; | ||
381 | break; | ||
382 | } | ||
377 | } | 383 | } |
378 | 384 | ||
379 | 385 | ||
380 | static void | 386 | static void |
381 | caller_ego_create_cont (void *cls, | 387 | caller_ego_create_cont(void *cls, |
382 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 388 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
383 | const char *emsg) | 389 | const char *emsg) |
384 | { | 390 | { |
385 | (void) cls; | 391 | (void)cls; |
386 | op = NULL; | 392 | op = NULL; |
387 | GNUNET_assert (NULL == emsg); | 393 | GNUNET_assert(NULL == emsg); |
388 | } | 394 | } |
389 | 395 | ||
390 | 396 | ||
391 | static void | 397 | static void |
392 | namestore_put_cont (void *cls, int32_t success, const char *emsg) | 398 | namestore_put_cont(void *cls, int32_t success, const char *emsg) |
393 | { | 399 | { |
394 | (void) cls; | 400 | (void)cls; |
395 | qe = NULL; | 401 | qe = NULL; |
396 | GNUNET_assert (GNUNET_YES == success); | 402 | GNUNET_assert(GNUNET_YES == success); |
397 | GNUNET_assert (NULL == emsg); | 403 | GNUNET_assert(NULL == emsg); |
398 | GNUNET_assert (NULL == op); | 404 | GNUNET_assert(NULL == op); |
399 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 405 | op = GNUNET_IDENTITY_create(id, "caller-ego", &caller_ego_create_cont, NULL); |
400 | } | 406 | } |
401 | 407 | ||
402 | 408 | ||
403 | static void | 409 | static void |
404 | identity_cb (void *cls, | 410 | identity_cb(void *cls, |
405 | struct GNUNET_IDENTITY_Ego *ego, | 411 | struct GNUNET_IDENTITY_Ego *ego, |
406 | void **ctx, | 412 | void **ctx, |
407 | const char *name) | 413 | const char *name) |
408 | { | 414 | { |
409 | struct GNUNET_GNSRECORD_Data rd; | 415 | struct GNUNET_GNSRECORD_Data rd; |
410 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 416 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
411 | 417 | ||
412 | (void) cls; | 418 | (void)cls; |
413 | (void) ctx; | 419 | (void)ctx; |
414 | if (NULL == name) | 420 | if (NULL == name) |
415 | return; | 421 | return; |
416 | if (NULL == ego) | 422 | if (NULL == ego) |
417 | return; | 423 | return; |
418 | if (0 == strcmp (name, "phone-ego")) | 424 | if (0 == strcmp(name, "phone-ego")) |
419 | { | 425 | { |
420 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 426 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
421 | GNUNET_asprintf (&gns_name, | 427 | GNUNET_asprintf(&gns_name, |
422 | "phone.%s", | 428 | "phone.%s", |
423 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 429 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
424 | phone = | 430 | phone = |
425 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); | 431 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); |
426 | GNUNET_assert (NULL != phone); | 432 | GNUNET_assert(NULL != phone); |
427 | memset (&rd, 0, sizeof (rd)); | 433 | memset(&rd, 0, sizeof(rd)); |
428 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | 434 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); |
429 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 435 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
430 | rd.expiration_time = UINT64_MAX; | 436 | rd.expiration_time = UINT64_MAX; |
431 | qe = | 437 | qe = |
432 | GNUNET_NAMESTORE_records_store (ns, | 438 | GNUNET_NAMESTORE_records_store(ns, |
433 | GNUNET_IDENTITY_ego_get_private_key (ego), | 439 | GNUNET_IDENTITY_ego_get_private_key(ego), |
434 | "phone" /* GNS label */, | 440 | "phone" /* GNS label */, |
435 | 1, | 441 | 1, |
436 | &rd, | 442 | &rd, |
437 | &namestore_put_cont, | 443 | &namestore_put_cont, |
438 | NULL); | 444 | NULL); |
439 | return; | 445 | return; |
440 | } | 446 | } |
441 | if (0 == strcmp (name, "caller-ego")) | 447 | if (0 == strcmp(name, "caller-ego")) |
442 | { | 448 | { |
443 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 449 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
444 | GNUNET_asprintf (&gns_caller_id, | 450 | GNUNET_asprintf(&gns_caller_id, |
445 | "%s", | 451 | "%s", |
446 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 452 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
447 | call = GNUNET_CONVERSATION_call_start (cfg, | 453 | call = GNUNET_CONVERSATION_call_start(cfg, |
448 | ego, | 454 | ego, |
449 | gns_name, | 455 | gns_name, |
450 | &call_speaker, | 456 | &call_speaker, |
451 | &call_mic, | 457 | &call_mic, |
452 | &call_event_handler, | 458 | &call_event_handler, |
453 | NULL); | 459 | NULL); |
454 | return; | 460 | return; |
455 | } | 461 | } |
456 | } | 462 | } |
457 | 463 | ||
458 | 464 | ||
459 | static void | 465 | static void |
460 | phone_ego_create_cont (void *cls, | 466 | phone_ego_create_cont(void *cls, |
461 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 467 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
462 | const char *emsg) | 468 | const char *emsg) |
463 | { | 469 | { |
464 | (void) cls; | 470 | (void)cls; |
465 | op = NULL; | 471 | op = NULL; |
466 | GNUNET_assert (NULL == emsg); | 472 | GNUNET_assert(NULL == emsg); |
467 | } | 473 | } |
468 | 474 | ||
469 | 475 | ||
470 | static void | 476 | static void |
471 | run (void *cls, | 477 | run(void *cls, |
472 | const struct GNUNET_CONFIGURATION_Handle *c, | 478 | const struct GNUNET_CONFIGURATION_Handle *c, |
473 | struct GNUNET_TESTING_Peer *peer) | 479 | struct GNUNET_TESTING_Peer *peer) |
474 | { | 480 | { |
475 | (void) cls; | 481 | (void)cls; |
476 | (void) peer; | 482 | (void)peer; |
477 | cfg = c; | 483 | cfg = c; |
478 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 484 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); |
479 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 485 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); |
480 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 486 | op = GNUNET_IDENTITY_create(id, "phone-ego", &phone_ego_create_cont, NULL); |
481 | ns = GNUNET_NAMESTORE_connect (cfg); | 487 | ns = GNUNET_NAMESTORE_connect(cfg); |
482 | } | 488 | } |
483 | 489 | ||
484 | 490 | ||
485 | int | 491 | int |
486 | main (int argc, char *argv[]) | 492 | main(int argc, char *argv[]) |
487 | { | 493 | { |
488 | (void) argc; | 494 | (void)argc; |
489 | (void) argv; | 495 | (void)argv; |
490 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", | 496 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api", |
491 | "test_conversation.conf", | 497 | "test_conversation.conf", |
492 | &run, | 498 | &run, |
493 | NULL)) | 499 | NULL)) |
494 | return 1; | 500 | return 1; |
495 | return ok; | 501 | return ok; |
496 | } | 502 | } |
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c index b0a479dc2..2d7a56e3d 100644 --- a/src/conversation/test_conversation_api_reject.c +++ b/src/conversation/test_conversation_api_reject.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/test_conversation_api_reject.c | 21 | * @file conversation/test_conversation_api_reject.c |
22 | * @brief testcase for conversation_api.c | 22 | * @brief testcase for conversation_api.c |
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_identity_service.h" | 33 | #include "gnunet_identity_service.h" |
34 | #include "gnunet_namestore_service.h" | 34 | #include "gnunet_namestore_service.h" |
35 | 35 | ||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) | 36 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 25) |
37 | 37 | ||
38 | static int ok = 1; | 38 | static int ok = 1; |
39 | 39 | ||
@@ -57,78 +57,78 @@ static char *gns_caller_id; | |||
57 | 57 | ||
58 | 58 | ||
59 | static int | 59 | static int |
60 | enable_speaker (void *cls) | 60 | enable_speaker(void *cls) |
61 | { | 61 | { |
62 | (void) cls; | 62 | (void)cls; |
63 | GNUNET_break (0); | 63 | GNUNET_break(0); |
64 | return GNUNET_SYSERR; | 64 | return GNUNET_SYSERR; |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | static void | 68 | static void |
69 | disable_speaker (void *cls) | 69 | disable_speaker(void *cls) |
70 | { | 70 | { |
71 | (void) cls; | 71 | (void)cls; |
72 | GNUNET_break (0); | 72 | GNUNET_break(0); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static void | 76 | static void |
77 | play (void *cls, size_t data_size, const void *data) | 77 | play(void *cls, size_t data_size, const void *data) |
78 | { | 78 | { |
79 | (void) cls; | 79 | (void)cls; |
80 | (void) data_size; | 80 | (void)data_size; |
81 | (void) data; | 81 | (void)data; |
82 | GNUNET_break (0); | 82 | GNUNET_break(0); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | static void | 86 | static void |
87 | destroy_speaker (void *cls) | 87 | destroy_speaker(void *cls) |
88 | { | 88 | { |
89 | (void) cls; | 89 | (void)cls; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | static struct GNUNET_SPEAKER_Handle call_speaker = {&enable_speaker, | 93 | static struct GNUNET_SPEAKER_Handle call_speaker = { &enable_speaker, |
94 | &play, | 94 | &play, |
95 | &disable_speaker, | 95 | &disable_speaker, |
96 | &destroy_speaker, | 96 | &destroy_speaker, |
97 | "caller"}; | 97 | "caller" }; |
98 | 98 | ||
99 | 99 | ||
100 | static int | 100 | static int |
101 | enable_mic (void *cls, | 101 | enable_mic(void *cls, |
102 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 102 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
103 | void *rdc_cls) | 103 | void *rdc_cls) |
104 | { | 104 | { |
105 | (void) cls; | 105 | (void)cls; |
106 | (void) rdc; | 106 | (void)rdc; |
107 | (void) rdc_cls; | 107 | (void)rdc_cls; |
108 | GNUNET_break (0); | 108 | GNUNET_break(0); |
109 | return GNUNET_SYSERR; | 109 | return GNUNET_SYSERR; |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | static void | 113 | static void |
114 | disable_mic (void *cls) | 114 | disable_mic(void *cls) |
115 | { | 115 | { |
116 | (void) cls; | 116 | (void)cls; |
117 | GNUNET_break (0); | 117 | GNUNET_break(0); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | static void | 121 | static void |
122 | destroy_mic (void *cls) | 122 | destroy_mic(void *cls) |
123 | { | 123 | { |
124 | (void) cls; | 124 | (void)cls; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | static struct GNUNET_MICROPHONE_Handle call_mic = {&enable_mic, | 128 | static struct GNUNET_MICROPHONE_Handle call_mic = { &enable_mic, |
129 | &disable_mic, | 129 | &disable_mic, |
130 | &destroy_mic, | 130 | &destroy_mic, |
131 | "caller"}; | 131 | "caller" }; |
132 | 132 | ||
133 | 133 | ||
134 | /** | 134 | /** |
@@ -137,215 +137,219 @@ static struct GNUNET_MICROPHONE_Handle call_mic = {&enable_mic, | |||
137 | * @param cls closure | 137 | * @param cls closure |
138 | */ | 138 | */ |
139 | static void | 139 | static void |
140 | end_test (void *cls) | 140 | end_test(void *cls) |
141 | { | 141 | { |
142 | (void) cls; | 142 | (void)cls; |
143 | GNUNET_SCHEDULER_shutdown (); | 143 | GNUNET_SCHEDULER_shutdown(); |
144 | if (NULL != op) | 144 | if (NULL != op) |
145 | { | 145 | { |
146 | GNUNET_IDENTITY_cancel (op); | 146 | GNUNET_IDENTITY_cancel(op); |
147 | op = NULL; | 147 | op = NULL; |
148 | } | 148 | } |
149 | if (NULL != call) | 149 | if (NULL != call) |
150 | { | 150 | { |
151 | GNUNET_CONVERSATION_call_stop (call); | 151 | GNUNET_CONVERSATION_call_stop(call); |
152 | call = NULL; | 152 | call = NULL; |
153 | } | 153 | } |
154 | if (NULL != phone) | 154 | if (NULL != phone) |
155 | { | 155 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | 156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); |
157 | GNUNET_CONVERSATION_phone_destroy (phone); | 157 | GNUNET_CONVERSATION_phone_destroy(phone); |
158 | phone = NULL; | 158 | phone = NULL; |
159 | } | 159 | } |
160 | if (NULL != id) | 160 | if (NULL != id) |
161 | { | 161 | { |
162 | GNUNET_IDENTITY_disconnect (id); | 162 | GNUNET_IDENTITY_disconnect(id); |
163 | id = NULL; | 163 | id = NULL; |
164 | } | 164 | } |
165 | if (NULL != qe) | 165 | if (NULL != qe) |
166 | { | 166 | { |
167 | GNUNET_NAMESTORE_cancel (qe); | 167 | GNUNET_NAMESTORE_cancel(qe); |
168 | qe = NULL; | 168 | qe = NULL; |
169 | } | 169 | } |
170 | if (NULL != ns) | 170 | if (NULL != ns) |
171 | { | 171 | { |
172 | GNUNET_NAMESTORE_disconnect (ns); | 172 | GNUNET_NAMESTORE_disconnect(ns); |
173 | ns = NULL; | 173 | ns = NULL; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
178 | static void | 178 | static void |
179 | phone_event_handler (void *cls, | 179 | phone_event_handler(void *cls, |
180 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 180 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
181 | struct GNUNET_CONVERSATION_Caller *caller, | 181 | struct GNUNET_CONVERSATION_Caller *caller, |
182 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 182 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
183 | { | 183 | { |
184 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = | 184 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = |
185 | GNUNET_CONVERSATION_EC_PHONE_RING; | 185 | GNUNET_CONVERSATION_EC_PHONE_RING; |
186 | 186 | ||
187 | (void) cls; | 187 | (void)cls; |
188 | (void) caller_id; | 188 | (void)caller_id; |
189 | GNUNET_break (code == expect); | 189 | GNUNET_break(code == expect); |
190 | switch (code) | 190 | switch (code) |
191 | { | 191 | { |
192 | case GNUNET_CONVERSATION_EC_PHONE_RING: | 192 | case GNUNET_CONVERSATION_EC_PHONE_RING: |
193 | GNUNET_CONVERSATION_caller_hang_up (caller); | 193 | GNUNET_CONVERSATION_caller_hang_up(caller); |
194 | break; | 194 | break; |
195 | default: | 195 | |
196 | fprintf (stderr, "Unexpected phone code: %d\n", code); | 196 | default: |
197 | break; | 197 | fprintf(stderr, "Unexpected phone code: %d\n", code); |
198 | } | 198 | break; |
199 | } | ||
199 | } | 200 | } |
200 | 201 | ||
201 | 202 | ||
202 | static void | 203 | static void |
203 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 204 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
204 | { | 205 | { |
205 | static enum GNUNET_CONVERSATION_CallEventCode expect = | 206 | static enum GNUNET_CONVERSATION_CallEventCode expect = |
206 | GNUNET_CONVERSATION_EC_CALL_RINGING; | 207 | GNUNET_CONVERSATION_EC_CALL_RINGING; |
207 | 208 | ||
208 | (void) cls; | 209 | (void)cls; |
209 | GNUNET_break (code == expect); | 210 | GNUNET_break(code == expect); |
210 | switch (code) | 211 | switch (code) |
211 | { | 212 | { |
212 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 213 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
213 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; | 214 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; |
214 | break; | 215 | break; |
215 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 216 | |
216 | call = NULL; | 217 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
217 | ok = 0; | 218 | call = NULL; |
218 | GNUNET_SCHEDULER_shutdown (); | 219 | ok = 0; |
219 | expect = -1; | 220 | GNUNET_SCHEDULER_shutdown(); |
220 | break; | 221 | expect = -1; |
221 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 222 | break; |
222 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 223 | |
223 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 224 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
224 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 225 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
225 | fprintf (stderr, "Unexpected call code: %d\n", code); | 226 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
226 | break; | 227 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
227 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 228 | fprintf(stderr, "Unexpected call code: %d\n", code); |
228 | fprintf (stderr, "Unexpected call code: %d\n", code); | 229 | break; |
229 | call = NULL; | 230 | |
230 | break; | 231 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
231 | } | 232 | fprintf(stderr, "Unexpected call code: %d\n", code); |
233 | call = NULL; | ||
234 | break; | ||
235 | } | ||
232 | } | 236 | } |
233 | 237 | ||
234 | 238 | ||
235 | static void | 239 | static void |
236 | caller_ego_create_cont (void *cls, | 240 | caller_ego_create_cont(void *cls, |
237 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
238 | const char *emsg) | 242 | const char *emsg) |
239 | { | 243 | { |
240 | (void) cls; | 244 | (void)cls; |
241 | op = NULL; | 245 | op = NULL; |
242 | GNUNET_assert (NULL == emsg); | 246 | GNUNET_assert(NULL == emsg); |
243 | } | 247 | } |
244 | 248 | ||
245 | 249 | ||
246 | static void | 250 | static void |
247 | namestore_put_cont (void *cls, int32_t success, const char *emsg) | 251 | namestore_put_cont(void *cls, int32_t success, const char *emsg) |
248 | { | 252 | { |
249 | (void) cls; | 253 | (void)cls; |
250 | qe = NULL; | 254 | qe = NULL; |
251 | GNUNET_assert (GNUNET_YES == success); | 255 | GNUNET_assert(GNUNET_YES == success); |
252 | GNUNET_assert (NULL == emsg); | 256 | GNUNET_assert(NULL == emsg); |
253 | GNUNET_assert (NULL == op); | 257 | GNUNET_assert(NULL == op); |
254 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 258 | op = GNUNET_IDENTITY_create(id, "caller-ego", &caller_ego_create_cont, NULL); |
255 | } | 259 | } |
256 | 260 | ||
257 | 261 | ||
258 | static void | 262 | static void |
259 | identity_cb (void *cls, | 263 | identity_cb(void *cls, |
260 | struct GNUNET_IDENTITY_Ego *ego, | 264 | struct GNUNET_IDENTITY_Ego *ego, |
261 | void **ctx, | 265 | void **ctx, |
262 | const char *name) | 266 | const char *name) |
263 | { | 267 | { |
264 | struct GNUNET_GNSRECORD_Data rd; | 268 | struct GNUNET_GNSRECORD_Data rd; |
265 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 269 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
266 | 270 | ||
267 | (void) cls; | 271 | (void)cls; |
268 | (void) ctx; | 272 | (void)ctx; |
269 | if (NULL == name) | 273 | if (NULL == name) |
270 | return; | 274 | return; |
271 | if (NULL == ego) | 275 | if (NULL == ego) |
272 | return; | 276 | return; |
273 | if (0 == strcmp (name, "phone-ego")) | 277 | if (0 == strcmp(name, "phone-ego")) |
274 | { | 278 | { |
275 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 279 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
276 | GNUNET_asprintf (&gns_name, | 280 | GNUNET_asprintf(&gns_name, |
277 | "phone.%s", | 281 | "phone.%s", |
278 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 282 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
279 | phone = | 283 | phone = |
280 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); | 284 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); |
281 | GNUNET_assert (NULL != phone); | 285 | GNUNET_assert(NULL != phone); |
282 | memset (&rd, 0, sizeof (rd)); | 286 | memset(&rd, 0, sizeof(rd)); |
283 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | 287 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); |
284 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 288 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
285 | rd.expiration_time = UINT64_MAX; | 289 | rd.expiration_time = UINT64_MAX; |
286 | qe = | 290 | qe = |
287 | GNUNET_NAMESTORE_records_store (ns, | 291 | GNUNET_NAMESTORE_records_store(ns, |
288 | GNUNET_IDENTITY_ego_get_private_key (ego), | 292 | GNUNET_IDENTITY_ego_get_private_key(ego), |
289 | "phone" /* GNS label */, | 293 | "phone" /* GNS label */, |
290 | 1, | 294 | 1, |
291 | &rd, | 295 | &rd, |
292 | &namestore_put_cont, | 296 | &namestore_put_cont, |
293 | NULL); | 297 | NULL); |
294 | return; | 298 | return; |
295 | } | 299 | } |
296 | if (0 == strcmp (name, "caller-ego")) | 300 | if (0 == strcmp(name, "caller-ego")) |
297 | { | 301 | { |
298 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 302 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
299 | GNUNET_asprintf (&gns_caller_id, | 303 | GNUNET_asprintf(&gns_caller_id, |
300 | "%s", | 304 | "%s", |
301 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 305 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
302 | call = GNUNET_CONVERSATION_call_start (cfg, | 306 | call = GNUNET_CONVERSATION_call_start(cfg, |
303 | ego, | 307 | ego, |
304 | gns_name, | 308 | gns_name, |
305 | &call_speaker, | 309 | &call_speaker, |
306 | &call_mic, | 310 | &call_mic, |
307 | &call_event_handler, | 311 | &call_event_handler, |
308 | NULL); | 312 | NULL); |
309 | return; | 313 | return; |
310 | } | 314 | } |
311 | } | 315 | } |
312 | 316 | ||
313 | 317 | ||
314 | static void | 318 | static void |
315 | phone_ego_create_cont (void *cls, | 319 | phone_ego_create_cont(void *cls, |
316 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 320 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
317 | const char *emsg) | 321 | const char *emsg) |
318 | { | 322 | { |
319 | (void) cls; | 323 | (void)cls; |
320 | op = NULL; | 324 | op = NULL; |
321 | GNUNET_assert (NULL == emsg); | 325 | GNUNET_assert(NULL == emsg); |
322 | } | 326 | } |
323 | 327 | ||
324 | 328 | ||
325 | static void | 329 | static void |
326 | run (void *cls, | 330 | run(void *cls, |
327 | const struct GNUNET_CONFIGURATION_Handle *c, | 331 | const struct GNUNET_CONFIGURATION_Handle *c, |
328 | struct GNUNET_TESTING_Peer *peer) | 332 | struct GNUNET_TESTING_Peer *peer) |
329 | { | 333 | { |
330 | (void) cls; | 334 | (void)cls; |
331 | (void) peer; | 335 | (void)peer; |
332 | cfg = c; | 336 | cfg = c; |
333 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 337 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); |
334 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 338 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); |
335 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 339 | op = GNUNET_IDENTITY_create(id, "phone-ego", &phone_ego_create_cont, NULL); |
336 | ns = GNUNET_NAMESTORE_connect (cfg); | 340 | ns = GNUNET_NAMESTORE_connect(cfg); |
337 | } | 341 | } |
338 | 342 | ||
339 | 343 | ||
340 | int | 344 | int |
341 | main (int argc, char *argv[]) | 345 | main(int argc, char *argv[]) |
342 | { | 346 | { |
343 | (void) argc; | 347 | (void)argc; |
344 | (void) argv; | 348 | (void)argv; |
345 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", | 349 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api", |
346 | "test_conversation.conf", | 350 | "test_conversation.conf", |
347 | &run, | 351 | &run, |
348 | NULL)) | 352 | NULL)) |
349 | return 1; | 353 | return 1; |
350 | return ok; | 354 | return ok; |
351 | } | 355 | } |
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c index f3bb87fd2..797563d7a 100644 --- a/src/conversation/test_conversation_api_twocalls.c +++ b/src/conversation/test_conversation_api_twocalls.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file conversation/test_conversation_api_twocalls.c | 21 | * @file conversation/test_conversation_api_twocalls.c |
22 | * @brief testcase for conversation_api.c | 22 | * @brief testcase for conversation_api.c |
@@ -35,13 +35,13 @@ | |||
35 | #include "gnunet_identity_service.h" | 35 | #include "gnunet_identity_service.h" |
36 | #include "gnunet_namestore_service.h" | 36 | #include "gnunet_namestore_service.h" |
37 | 37 | ||
38 | #define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) | 38 | #define FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) |
39 | 39 | ||
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 25) |
41 | 41 | ||
42 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 42 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) |
43 | 43 | ||
44 | #define LOG_DEBUG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 44 | #define LOG_DEBUG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
45 | 45 | ||
46 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 46 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
47 | 47 | ||
@@ -95,7 +95,7 @@ static const char *phone0 = "phone"; | |||
95 | #define CALLER2 &caller2 | 95 | #define CALLER2 &caller2 |
96 | #define PHONE0 &phone0 | 96 | #define PHONE0 &phone0 |
97 | 97 | ||
98 | #define CLS_STR(caller) (*((char **) caller)) | 98 | #define CLS_STR(caller) (*((char **)caller)) |
99 | 99 | ||
100 | 100 | ||
101 | /** | 101 | /** |
@@ -108,8 +108,7 @@ static int call1_finished; | |||
108 | */ | 108 | */ |
109 | static int call2_finished; | 109 | static int call2_finished; |
110 | 110 | ||
111 | struct MicContext | 111 | struct MicContext { |
112 | { | ||
113 | GNUNET_MICROPHONE_RecordedDataCallback rdc; | 112 | GNUNET_MICROPHONE_RecordedDataCallback rdc; |
114 | 113 | ||
115 | void *rdc_cls; | 114 | void *rdc_cls; |
@@ -123,198 +122,198 @@ static struct MicContext call2_mic_ctx; | |||
123 | 122 | ||
124 | 123 | ||
125 | static void | 124 | static void |
126 | phone_send (void *cls) | 125 | phone_send(void *cls) |
127 | { | 126 | { |
128 | char buf[32]; | 127 | char buf[32]; |
129 | 128 | ||
130 | (void) cls; | 129 | (void)cls; |
131 | GNUNET_assert (NULL != phone_rdc); | 130 | GNUNET_assert(NULL != phone_rdc); |
132 | GNUNET_snprintf (buf, sizeof (buf), "phone"); | 131 | GNUNET_snprintf(buf, sizeof(buf), "phone"); |
133 | phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); | 132 | phone_rdc(phone_rdc_cls, strlen(buf) + 1, buf); |
134 | phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL); | 133 | phone_task = GNUNET_SCHEDULER_add_delayed(FREQ, &phone_send, NULL); |
135 | } | 134 | } |
136 | 135 | ||
137 | 136 | ||
138 | static void | 137 | static void |
139 | call_send (void *cls) | 138 | call_send(void *cls) |
140 | { | 139 | { |
141 | struct MicContext *mc = cls; | 140 | struct MicContext *mc = cls; |
142 | char buf[32]; | 141 | char buf[32]; |
143 | 142 | ||
144 | (void) cls; | 143 | (void)cls; |
145 | GNUNET_assert (NULL != mc->rdc); | 144 | GNUNET_assert(NULL != mc->rdc); |
146 | GNUNET_snprintf (buf, sizeof (buf), "call"); | 145 | GNUNET_snprintf(buf, sizeof(buf), "call"); |
147 | mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf); | 146 | mc->rdc(mc->rdc_cls, strlen(buf) + 1, buf); |
148 | mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, mc); | 147 | mc->call_task = GNUNET_SCHEDULER_add_delayed(FREQ, &call_send, mc); |
149 | } | 148 | } |
150 | 149 | ||
151 | 150 | ||
152 | static int | 151 | static int |
153 | enable_speaker (void *cls) | 152 | enable_speaker(void *cls) |
154 | { | 153 | { |
155 | const char *origin = CLS_STR (cls); | 154 | const char *origin = CLS_STR(cls); |
156 | 155 | ||
157 | (void) cls; | 156 | (void)cls; |
158 | LOG_DEBUG ("Speaker %s enabled\n", origin); | 157 | LOG_DEBUG("Speaker %s enabled\n", origin); |
159 | return GNUNET_OK; | 158 | return GNUNET_OK; |
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
163 | static void | 162 | static void |
164 | disable_speaker (void *cls) | 163 | disable_speaker(void *cls) |
165 | { | 164 | { |
166 | const char *origin = CLS_STR (cls); | 165 | const char *origin = CLS_STR(cls); |
167 | 166 | ||
168 | (void) cls; | 167 | (void)cls; |
169 | LOG_DEBUG ("Speaker %s disabled\n", origin); | 168 | LOG_DEBUG("Speaker %s disabled\n", origin); |
170 | } | 169 | } |
171 | 170 | ||
172 | 171 | ||
173 | static void | 172 | static void |
174 | play (void *cls, size_t data_size, const void *data) | 173 | play(void *cls, size_t data_size, const void *data) |
175 | { | 174 | { |
176 | static unsigned int phone_i; | 175 | static unsigned int phone_i; |
177 | static unsigned int call_i; | 176 | static unsigned int call_i; |
178 | 177 | ||
179 | (void) cls; | 178 | (void)cls; |
180 | if (0 == strncmp ("call", data, data_size)) | 179 | if (0 == strncmp("call", data, data_size)) |
181 | call_i++; | 180 | call_i++; |
182 | else if (0 == strncmp ("phone", data, data_size)) | 181 | else if (0 == strncmp("phone", data, data_size)) |
183 | phone_i++; | 182 | phone_i++; |
184 | else | 183 | else |
185 | { | 184 | { |
186 | LOG_DEBUG ("Received %u bytes of unexpected data `%.*s'\n", | 185 | LOG_DEBUG("Received %u bytes of unexpected data `%.*s'\n", |
187 | (unsigned int) data_size, | 186 | (unsigned int)data_size, |
188 | (int) data_size, | 187 | (int)data_size, |
189 | (const char *) data); | 188 | (const char *)data); |
190 | } | 189 | } |
191 | 190 | ||
192 | if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls)) | 191 | if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls)) |
193 | { | 192 | { |
194 | /* time to hang up ... */ | 193 | /* time to hang up ... */ |
195 | GNUNET_CONVERSATION_call_stop (call2); | 194 | GNUNET_CONVERSATION_call_stop(call2); |
196 | call2 = NULL; | 195 | call2 = NULL; |
197 | /* reset counters */ | 196 | /* reset counters */ |
198 | call_i = 0; | 197 | call_i = 0; |
199 | phone_i = 0; | 198 | phone_i = 0; |
200 | call2_finished = GNUNET_YES; | 199 | call2_finished = GNUNET_YES; |
201 | } | 200 | } |
202 | if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls)) | 201 | if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls)) |
203 | { | 202 | { |
204 | /* time to hang up ... */ | 203 | /* time to hang up ... */ |
205 | GNUNET_CONVERSATION_call_stop (call1); | 204 | GNUNET_CONVERSATION_call_stop(call1); |
206 | call1 = NULL; | 205 | call1 = NULL; |
207 | call_i = 0; | 206 | call_i = 0; |
208 | phone_i = 0; | 207 | phone_i = 0; |
209 | call1_finished = GNUNET_YES; | 208 | call1_finished = GNUNET_YES; |
210 | } | 209 | } |
211 | } | 210 | } |
212 | 211 | ||
213 | 212 | ||
214 | static void | 213 | static void |
215 | destroy_speaker (void *cls) | 214 | destroy_speaker(void *cls) |
216 | { | 215 | { |
217 | const char *origin = CLS_STR (cls); | 216 | const char *origin = CLS_STR(cls); |
218 | 217 | ||
219 | LOG_DEBUG ("Speaker %s destroyed\n", origin); | 218 | LOG_DEBUG("Speaker %s destroyed\n", origin); |
220 | } | 219 | } |
221 | 220 | ||
222 | 221 | ||
223 | static struct GNUNET_SPEAKER_Handle call1_speaker = {&enable_speaker, | 222 | static struct GNUNET_SPEAKER_Handle call1_speaker = { &enable_speaker, |
224 | &play, | 223 | &play, |
225 | &disable_speaker, | 224 | &disable_speaker, |
226 | &destroy_speaker, | 225 | &destroy_speaker, |
227 | CALLER1}; | 226 | CALLER1 }; |
228 | 227 | ||
229 | 228 | ||
230 | static struct GNUNET_SPEAKER_Handle call2_speaker = {&enable_speaker, | 229 | static struct GNUNET_SPEAKER_Handle call2_speaker = { &enable_speaker, |
231 | &play, | 230 | &play, |
232 | &disable_speaker, | 231 | &disable_speaker, |
233 | &destroy_speaker, | 232 | &destroy_speaker, |
234 | CALLER2}; | 233 | CALLER2 }; |
235 | 234 | ||
236 | 235 | ||
237 | static struct GNUNET_SPEAKER_Handle phone_speaker = {&enable_speaker, | 236 | static struct GNUNET_SPEAKER_Handle phone_speaker = { &enable_speaker, |
238 | &play, | 237 | &play, |
239 | &disable_speaker, | 238 | &disable_speaker, |
240 | &destroy_speaker, | 239 | &destroy_speaker, |
241 | PHONE0}; | 240 | PHONE0 }; |
242 | 241 | ||
243 | 242 | ||
244 | static int | 243 | static int |
245 | enable_mic (void *cls, | 244 | enable_mic(void *cls, |
246 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 245 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
247 | void *rdc_cls) | 246 | void *rdc_cls) |
248 | { | 247 | { |
249 | const char *origin = CLS_STR (cls); | 248 | const char *origin = CLS_STR(cls); |
250 | struct MicContext *mc; | 249 | struct MicContext *mc; |
251 | 250 | ||
252 | LOG_DEBUG ("Mic %s enabled\n", origin); | 251 | LOG_DEBUG("Mic %s enabled\n", origin); |
253 | if (PHONE0 == cls) | 252 | if (PHONE0 == cls) |
254 | { | 253 | { |
255 | phone_rdc = rdc; | 254 | phone_rdc = rdc; |
256 | phone_rdc_cls = rdc_cls; | 255 | phone_rdc_cls = rdc_cls; |
257 | GNUNET_break (NULL == phone_task); | 256 | GNUNET_break(NULL == phone_task); |
258 | phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL); | 257 | phone_task = GNUNET_SCHEDULER_add_now(&phone_send, NULL); |
259 | return GNUNET_OK; | 258 | return GNUNET_OK; |
260 | } | 259 | } |
261 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; | 260 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; |
262 | mc->rdc = rdc; | 261 | mc->rdc = rdc; |
263 | mc->rdc_cls = rdc_cls; | 262 | mc->rdc_cls = rdc_cls; |
264 | GNUNET_break (NULL == mc->call_task); | 263 | GNUNET_break(NULL == mc->call_task); |
265 | mc->call_task = GNUNET_SCHEDULER_add_now (&call_send, mc); | 264 | mc->call_task = GNUNET_SCHEDULER_add_now(&call_send, mc); |
266 | return GNUNET_OK; | 265 | return GNUNET_OK; |
267 | } | 266 | } |
268 | 267 | ||
269 | 268 | ||
270 | static void | 269 | static void |
271 | disable_mic (void *cls) | 270 | disable_mic(void *cls) |
272 | { | 271 | { |
273 | const char *origin = CLS_STR (cls); | 272 | const char *origin = CLS_STR(cls); |
274 | struct MicContext *mc; | 273 | struct MicContext *mc; |
275 | 274 | ||
276 | LOG_DEBUG ("Mic %s disabled\n", origin); | 275 | LOG_DEBUG("Mic %s disabled\n", origin); |
277 | if (PHONE0 == cls) | 276 | if (PHONE0 == cls) |
278 | { | 277 | { |
279 | phone_rdc = NULL; | 278 | phone_rdc = NULL; |
280 | phone_rdc_cls = NULL; | 279 | phone_rdc_cls = NULL; |
281 | GNUNET_SCHEDULER_cancel (phone_task); | 280 | GNUNET_SCHEDULER_cancel(phone_task); |
282 | phone_task = NULL; | 281 | phone_task = NULL; |
283 | return; | 282 | return; |
284 | } | 283 | } |
285 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; | 284 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; |
286 | mc->rdc = NULL; | 285 | mc->rdc = NULL; |
287 | mc->rdc_cls = NULL; | 286 | mc->rdc_cls = NULL; |
288 | GNUNET_SCHEDULER_cancel (mc->call_task); | 287 | GNUNET_SCHEDULER_cancel(mc->call_task); |
289 | mc->call_task = NULL; | 288 | mc->call_task = NULL; |
290 | } | 289 | } |
291 | 290 | ||
292 | 291 | ||
293 | static void | 292 | static void |
294 | destroy_mic (void *cls) | 293 | destroy_mic(void *cls) |
295 | { | 294 | { |
296 | const char *origin = CLS_STR (cls); | 295 | const char *origin = CLS_STR(cls); |
297 | 296 | ||
298 | LOG_DEBUG ("Mic %s destroyed\n", origin); | 297 | LOG_DEBUG("Mic %s destroyed\n", origin); |
299 | } | 298 | } |
300 | 299 | ||
301 | 300 | ||
302 | static struct GNUNET_MICROPHONE_Handle call1_mic = {&enable_mic, | 301 | static struct GNUNET_MICROPHONE_Handle call1_mic = { &enable_mic, |
303 | &disable_mic, | 302 | &disable_mic, |
304 | &destroy_mic, | 303 | &destroy_mic, |
305 | CALLER1}; | 304 | CALLER1 }; |
306 | 305 | ||
307 | 306 | ||
308 | static struct GNUNET_MICROPHONE_Handle call2_mic = {&enable_mic, | 307 | static struct GNUNET_MICROPHONE_Handle call2_mic = { &enable_mic, |
309 | &disable_mic, | 308 | &disable_mic, |
310 | &destroy_mic, | 309 | &destroy_mic, |
311 | CALLER2}; | 310 | CALLER2 }; |
312 | 311 | ||
313 | 312 | ||
314 | static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic, | 313 | static struct GNUNET_MICROPHONE_Handle phone_mic = { &enable_mic, |
315 | &disable_mic, | 314 | &disable_mic, |
316 | &destroy_mic, | 315 | &destroy_mic, |
317 | PHONE0}; | 316 | PHONE0 }; |
318 | 317 | ||
319 | 318 | ||
320 | /** | 319 | /** |
@@ -323,12 +322,12 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = {&enable_mic, | |||
323 | * @param cls closure | 322 | * @param cls closure |
324 | */ | 323 | */ |
325 | static void | 324 | static void |
326 | end_test (void *cls) | 325 | end_test(void *cls) |
327 | { | 326 | { |
328 | (void) cls; | 327 | (void)cls; |
329 | timeout_task = NULL; | 328 | timeout_task = NULL; |
330 | fprintf (stderr, "Timeout!\n"); | 329 | fprintf(stderr, "Timeout!\n"); |
331 | GNUNET_SCHEDULER_shutdown (); | 330 | GNUNET_SCHEDULER_shutdown(); |
332 | } | 331 | } |
333 | 332 | ||
334 | 333 | ||
@@ -338,286 +337,295 @@ end_test (void *cls) | |||
338 | * @param cls closure | 337 | * @param cls closure |
339 | */ | 338 | */ |
340 | static void | 339 | static void |
341 | do_shutdown (void *cls) | 340 | do_shutdown(void *cls) |
342 | { | 341 | { |
343 | (void) cls; | 342 | (void)cls; |
344 | if (NULL != timeout_task) | 343 | if (NULL != timeout_task) |
345 | { | 344 | { |
346 | GNUNET_SCHEDULER_cancel (timeout_task); | 345 | GNUNET_SCHEDULER_cancel(timeout_task); |
347 | timeout_task = NULL; | 346 | timeout_task = NULL; |
348 | } | 347 | } |
349 | if (NULL != op) | 348 | if (NULL != op) |
350 | { | 349 | { |
351 | GNUNET_IDENTITY_cancel (op); | 350 | GNUNET_IDENTITY_cancel(op); |
352 | op = NULL; | 351 | op = NULL; |
353 | } | 352 | } |
354 | if (NULL != call1) | 353 | if (NULL != call1) |
355 | { | 354 | { |
356 | GNUNET_CONVERSATION_call_stop (call1); | 355 | GNUNET_CONVERSATION_call_stop(call1); |
357 | call1 = NULL; | 356 | call1 = NULL; |
358 | } | 357 | } |
359 | if (NULL != call2) | 358 | if (NULL != call2) |
360 | { | 359 | { |
361 | GNUNET_CONVERSATION_call_stop (call2); | 360 | GNUNET_CONVERSATION_call_stop(call2); |
362 | call2 = NULL; | 361 | call2 = NULL; |
363 | } | 362 | } |
364 | if (NULL != phone) | 363 | if (NULL != phone) |
365 | { | 364 | { |
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | 365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); |
367 | GNUNET_CONVERSATION_phone_destroy (phone); | 366 | GNUNET_CONVERSATION_phone_destroy(phone); |
368 | phone = NULL; | 367 | phone = NULL; |
369 | } | 368 | } |
370 | if (NULL != id) | 369 | if (NULL != id) |
371 | { | 370 | { |
372 | GNUNET_IDENTITY_disconnect (id); | 371 | GNUNET_IDENTITY_disconnect(id); |
373 | id = NULL; | 372 | id = NULL; |
374 | } | 373 | } |
375 | if (NULL != qe) | 374 | if (NULL != qe) |
376 | { | 375 | { |
377 | GNUNET_NAMESTORE_cancel (qe); | 376 | GNUNET_NAMESTORE_cancel(qe); |
378 | qe = NULL; | 377 | qe = NULL; |
379 | } | 378 | } |
380 | if (NULL != ns) | 379 | if (NULL != ns) |
381 | { | 380 | { |
382 | GNUNET_NAMESTORE_disconnect (ns); | 381 | GNUNET_NAMESTORE_disconnect(ns); |
383 | ns = NULL; | 382 | ns = NULL; |
384 | } | 383 | } |
385 | } | 384 | } |
386 | 385 | ||
387 | 386 | ||
388 | static void | 387 | static void |
389 | caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | 388 | caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) |
390 | { | 389 | { |
391 | (void) cls; | 390 | (void)cls; |
392 | switch (code) | 391 | switch (code) |
393 | { | 392 | { |
394 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | 393 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: |
395 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | 394 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: |
396 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code); | 395 | LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code); |
397 | break; | 396 | break; |
398 | } | 397 | } |
399 | } | 398 | } |
400 | 399 | ||
401 | 400 | ||
402 | static void | 401 | static void |
403 | phone_event_handler (void *cls, | 402 | phone_event_handler(void *cls, |
404 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 403 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
405 | struct GNUNET_CONVERSATION_Caller *caller, | 404 | struct GNUNET_CONVERSATION_Caller *caller, |
406 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 405 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
407 | { | 406 | { |
408 | const char *cid; | 407 | const char *cid; |
409 | (void) cls; | 408 | |
410 | (void) caller_id; | 409 | (void)cls; |
410 | (void)caller_id; | ||
411 | 411 | ||
412 | switch (code) | 412 | switch (code) |
413 | { | ||
414 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
415 | if (NULL == active_caller1) | ||
416 | { | 413 | { |
417 | active_caller1 = caller; | 414 | case GNUNET_CONVERSATION_EC_PHONE_RING: |
418 | cid = "caller1"; | 415 | if (NULL == active_caller1) |
419 | GNUNET_CONVERSATION_caller_pick_up (caller, | 416 | { |
420 | &caller_event_handler, | 417 | active_caller1 = caller; |
421 | (void *) cid, | 418 | cid = "caller1"; |
422 | &phone_speaker, | 419 | GNUNET_CONVERSATION_caller_pick_up(caller, |
423 | &phone_mic); | 420 | &caller_event_handler, |
421 | (void *)cid, | ||
422 | &phone_speaker, | ||
423 | &phone_mic); | ||
424 | } | ||
425 | else | ||
426 | { | ||
427 | GNUNET_CONVERSATION_caller_suspend(active_caller1); | ||
428 | active_caller2 = caller; | ||
429 | cid = "caller2"; | ||
430 | GNUNET_CONVERSATION_caller_pick_up(caller, | ||
431 | &caller_event_handler, | ||
432 | (void *)cid, | ||
433 | &phone_speaker, | ||
434 | &phone_mic); | ||
435 | } | ||
436 | break; | ||
437 | |||
438 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
439 | if (caller == active_caller2) | ||
440 | { | ||
441 | active_caller2 = NULL; | ||
442 | GNUNET_CONVERSATION_caller_resume(active_caller1, | ||
443 | &phone_speaker, | ||
444 | &phone_mic); | ||
445 | } | ||
446 | else if (caller == active_caller1) | ||
447 | { | ||
448 | active_caller1 = NULL; | ||
449 | GNUNET_break(NULL == active_caller2); | ||
450 | GNUNET_SCHEDULER_shutdown(); | ||
451 | } | ||
452 | break; | ||
453 | |||
454 | default: | ||
455 | LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code); | ||
456 | break; | ||
424 | } | 457 | } |
425 | else | ||
426 | { | ||
427 | GNUNET_CONVERSATION_caller_suspend (active_caller1); | ||
428 | active_caller2 = caller; | ||
429 | cid = "caller2"; | ||
430 | GNUNET_CONVERSATION_caller_pick_up (caller, | ||
431 | &caller_event_handler, | ||
432 | (void *) cid, | ||
433 | &phone_speaker, | ||
434 | &phone_mic); | ||
435 | } | ||
436 | break; | ||
437 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
438 | if (caller == active_caller2) | ||
439 | { | ||
440 | active_caller2 = NULL; | ||
441 | GNUNET_CONVERSATION_caller_resume (active_caller1, | ||
442 | &phone_speaker, | ||
443 | &phone_mic); | ||
444 | } | ||
445 | else if (caller == active_caller1) | ||
446 | { | ||
447 | active_caller1 = NULL; | ||
448 | GNUNET_break (NULL == active_caller2); | ||
449 | GNUNET_SCHEDULER_shutdown (); | ||
450 | } | ||
451 | break; | ||
452 | default: | ||
453 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code); | ||
454 | break; | ||
455 | } | ||
456 | } | 458 | } |
457 | 459 | ||
458 | 460 | ||
459 | static void | 461 | static void |
460 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 462 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
461 | { | 463 | { |
462 | const char *cid = cls; | 464 | const char *cid = cls; |
463 | 465 | ||
464 | switch (code) | 466 | switch (code) |
465 | { | 467 | { |
466 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 468 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
467 | break; | 469 | break; |
468 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 470 | |
469 | LOG_DEBUG ("Call %s picked\n", cid); | 471 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
470 | break; | 472 | LOG_DEBUG("Call %s picked\n", cid); |
471 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 473 | break; |
472 | LOG_DEBUG ("Call %s GNS lookup failed \n", cid); | 474 | |
473 | break; | 475 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
474 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 476 | LOG_DEBUG("Call %s GNS lookup failed \n", cid); |
475 | LOG_DEBUG ("Call %s hungup\n", cid); | 477 | break; |
476 | if (0 == strcmp (cid, "call1")) | 478 | |
477 | call1 = NULL; | 479 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
478 | else | 480 | LOG_DEBUG("Call %s hungup\n", cid); |
479 | call2 = NULL; | 481 | if (0 == strcmp(cid, "call1")) |
480 | break; | 482 | call1 = NULL; |
481 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 483 | else |
482 | LOG_DEBUG ("Call %s suspended\n", cid); | 484 | call2 = NULL; |
483 | break; | 485 | break; |
484 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 486 | |
485 | LOG_DEBUG ("Call %s resumed\n", cid); | 487 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
486 | break; | 488 | LOG_DEBUG("Call %s suspended\n", cid); |
487 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 489 | break; |
488 | GNUNET_break (0); | 490 | |
489 | if (0 == strcmp (cid, "call1")) | 491 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
490 | call1 = NULL; | 492 | LOG_DEBUG("Call %s resumed\n", cid); |
491 | else | 493 | break; |
492 | call2 = NULL; | 494 | |
493 | GNUNET_SCHEDULER_shutdown (); | 495 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
494 | break; | 496 | GNUNET_break(0); |
495 | } | 497 | if (0 == strcmp(cid, "call1")) |
498 | call1 = NULL; | ||
499 | else | ||
500 | call2 = NULL; | ||
501 | GNUNET_SCHEDULER_shutdown(); | ||
502 | break; | ||
503 | } | ||
496 | } | 504 | } |
497 | 505 | ||
498 | 506 | ||
499 | static void | 507 | static void |
500 | caller_ego_create_cont (void *cls, | 508 | caller_ego_create_cont(void *cls, |
501 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 509 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
502 | const char *emsg) | 510 | const char *emsg) |
503 | { | 511 | { |
504 | (void) cls; | 512 | (void)cls; |
505 | op = NULL; | 513 | op = NULL; |
506 | GNUNET_assert (NULL == emsg); | 514 | GNUNET_assert(NULL == emsg); |
507 | } | 515 | } |
508 | 516 | ||
509 | 517 | ||
510 | static void | 518 | static void |
511 | namestore_put_cont (void *cls, int32_t success, const char *emsg) | 519 | namestore_put_cont(void *cls, int32_t success, const char *emsg) |
512 | { | 520 | { |
513 | (void) cls; | 521 | (void)cls; |
514 | qe = NULL; | 522 | qe = NULL; |
515 | GNUNET_assert (GNUNET_YES == success); | 523 | GNUNET_assert(GNUNET_YES == success); |
516 | GNUNET_assert (NULL == emsg); | 524 | GNUNET_assert(NULL == emsg); |
517 | GNUNET_assert (NULL == op); | 525 | GNUNET_assert(NULL == op); |
518 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | 526 | op = GNUNET_IDENTITY_create(id, "caller-ego", &caller_ego_create_cont, NULL); |
519 | } | 527 | } |
520 | 528 | ||
521 | 529 | ||
522 | static void | 530 | static void |
523 | identity_cb (void *cls, | 531 | identity_cb(void *cls, |
524 | struct GNUNET_IDENTITY_Ego *ego, | 532 | struct GNUNET_IDENTITY_Ego *ego, |
525 | void **ctx, | 533 | void **ctx, |
526 | const char *name) | 534 | const char *name) |
527 | { | 535 | { |
528 | struct GNUNET_GNSRECORD_Data rd; | 536 | struct GNUNET_GNSRECORD_Data rd; |
529 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 537 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
530 | 538 | ||
531 | (void) cls; | 539 | (void)cls; |
532 | (void) ctx; | 540 | (void)ctx; |
533 | if (NULL == name) | 541 | if (NULL == name) |
534 | return; | 542 | return; |
535 | if (NULL == ego) | 543 | if (NULL == ego) |
536 | return; | 544 | return; |
537 | if (0 == strcmp (name, "phone-ego")) | 545 | if (0 == strcmp(name, "phone-ego")) |
538 | { | 546 | { |
539 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 547 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
540 | GNUNET_asprintf (&gns_name, | 548 | GNUNET_asprintf(&gns_name, |
541 | "phone.%s", | 549 | "phone.%s", |
542 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 550 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
543 | phone = | 551 | phone = |
544 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); | 552 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); |
545 | GNUNET_assert (NULL != phone); | 553 | GNUNET_assert(NULL != phone); |
546 | memset (&rd, 0, sizeof (rd)); | 554 | memset(&rd, 0, sizeof(rd)); |
547 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); | 555 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); |
548 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 556 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
549 | rd.expiration_time = UINT64_MAX; | 557 | rd.expiration_time = UINT64_MAX; |
550 | qe = | 558 | qe = |
551 | GNUNET_NAMESTORE_records_store (ns, | 559 | GNUNET_NAMESTORE_records_store(ns, |
552 | GNUNET_IDENTITY_ego_get_private_key (ego), | 560 | GNUNET_IDENTITY_ego_get_private_key(ego), |
553 | "phone" /* GNS label */, | 561 | "phone" /* GNS label */, |
554 | 1, | 562 | 1, |
555 | &rd, | 563 | &rd, |
556 | &namestore_put_cont, | 564 | &namestore_put_cont, |
557 | NULL); | 565 | NULL); |
558 | return; | 566 | return; |
559 | } | 567 | } |
560 | if (0 == strcmp (name, "caller-ego")) | 568 | if (0 == strcmp(name, "caller-ego")) |
561 | { | 569 | { |
562 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | 570 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); |
563 | GNUNET_asprintf (&gns_caller_id, | 571 | GNUNET_asprintf(&gns_caller_id, |
564 | "%s", | 572 | "%s", |
565 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | 573 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); |
566 | call1 = GNUNET_CONVERSATION_call_start (cfg, | 574 | call1 = GNUNET_CONVERSATION_call_start(cfg, |
567 | ego, | 575 | ego, |
568 | gns_name, | 576 | gns_name, |
569 | &call1_speaker, | 577 | &call1_speaker, |
570 | &call1_mic, | 578 | &call1_mic, |
571 | &call_event_handler, | 579 | &call_event_handler, |
572 | (void *) "call1"); | 580 | (void *)"call1"); |
573 | call2 = GNUNET_CONVERSATION_call_start (cfg, | 581 | call2 = GNUNET_CONVERSATION_call_start(cfg, |
574 | ego, | 582 | ego, |
575 | gns_name, | 583 | gns_name, |
576 | &call2_speaker, | 584 | &call2_speaker, |
577 | &call2_mic, | 585 | &call2_mic, |
578 | &call_event_handler, | 586 | &call_event_handler, |
579 | (void *) "call2"); | 587 | (void *)"call2"); |
580 | return; | 588 | return; |
581 | } | 589 | } |
582 | } | 590 | } |
583 | 591 | ||
584 | 592 | ||
585 | static void | 593 | static void |
586 | phone_ego_create_cont (void *cls, | 594 | phone_ego_create_cont(void *cls, |
587 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 595 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
588 | const char *emsg) | 596 | const char *emsg) |
589 | { | 597 | { |
590 | (void) cls; | 598 | (void)cls; |
591 | op = NULL; | 599 | op = NULL; |
592 | GNUNET_assert (NULL == emsg); | 600 | GNUNET_assert(NULL == emsg); |
593 | } | 601 | } |
594 | 602 | ||
595 | 603 | ||
596 | static void | 604 | static void |
597 | run (void *cls, | 605 | run(void *cls, |
598 | const struct GNUNET_CONFIGURATION_Handle *c, | 606 | const struct GNUNET_CONFIGURATION_Handle *c, |
599 | struct GNUNET_TESTING_Peer *peer) | 607 | struct GNUNET_TESTING_Peer *peer) |
600 | { | 608 | { |
601 | (void) cls; | 609 | (void)cls; |
602 | (void) peer; | 610 | (void)peer; |
603 | cfg = c; | 611 | cfg = c; |
604 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); | 612 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); |
605 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 613 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
606 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); | 614 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); |
607 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | 615 | op = GNUNET_IDENTITY_create(id, "phone-ego", &phone_ego_create_cont, NULL); |
608 | ns = GNUNET_NAMESTORE_connect (cfg); | 616 | ns = GNUNET_NAMESTORE_connect(cfg); |
609 | } | 617 | } |
610 | 618 | ||
611 | 619 | ||
612 | int | 620 | int |
613 | main (int argc, char *argv[]) | 621 | main(int argc, char *argv[]) |
614 | { | 622 | { |
615 | (void) argc; | 623 | (void)argc; |
616 | (void) argv; | 624 | (void)argv; |
617 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls", | 625 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api_twocalls", |
618 | "test_conversation.conf", | 626 | "test_conversation.conf", |
619 | &run, | 627 | &run, |
620 | NULL)) | 628 | NULL)) |
621 | return 1; | 629 | return 1; |
622 | if (call1_finished && call2_finished) | 630 | if (call1_finished && call2_finished) |
623 | return 0; | 631 | return 0; |