diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/conversation | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/conversation')
20 files changed, 4857 insertions, 4748 deletions
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h index 0a9e2b5fb..ed614ab1b 100644 --- a/src/conversation/conversation.h +++ b/src/conversation/conversation.h | |||
@@ -36,7 +36,8 @@ extern "C" | |||
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 ( \ |
40 | GNUNET_TIME_UNIT_SECONDS, 60) | ||
40 | 41 | ||
41 | 42 | ||
42 | /** | 43 | /** |
@@ -44,7 +45,7 @@ extern "C" | |||
44 | * bit set if we are making an outgoing call, | 45 | * bit set if we are making an outgoing call, |
45 | * bit unset for local lines. | 46 | * bit unset for local lines. |
46 | */ | 47 | */ |
47 | #define HIGH_BIT ((uint32_t)(1LL << 31)) | 48 | #define HIGH_BIT ((uint32_t) (1LL << 31)) |
48 | 49 | ||
49 | GNUNET_NETWORK_STRUCT_BEGIN | 50 | GNUNET_NETWORK_STRUCT_BEGIN |
50 | 51 | ||
@@ -52,7 +53,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
52 | /** | 53 | /** |
53 | * Message to transmit the audio (between client and helpers). | 54 | * Message to transmit the audio (between client and helpers). |
54 | */ | 55 | */ |
55 | struct AudioMessage { | 56 | struct AudioMessage |
57 | { | ||
56 | /** | 58 | /** |
57 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO | 59 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO |
58 | */ | 60 | */ |
@@ -65,7 +67,8 @@ struct AudioMessage { | |||
65 | /** | 67 | /** |
66 | * Client -> Service message to register a phone. | 68 | * Client -> Service message to register a phone. |
67 | */ | 69 | */ |
68 | struct ClientPhoneRegisterMessage { | 70 | struct ClientPhoneRegisterMessage |
71 | { | ||
69 | /** | 72 | /** |
70 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER | 73 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER |
71 | */ | 74 | */ |
@@ -86,7 +89,8 @@ struct ClientPhoneRegisterMessage { | |||
86 | /** | 89 | /** |
87 | * Service -> Client message for phone is ringing. | 90 | * Service -> Client message for phone is ringing. |
88 | */ | 91 | */ |
89 | struct ClientPhoneRingMessage { | 92 | struct ClientPhoneRingMessage |
93 | { | ||
90 | /** | 94 | /** |
91 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING | 95 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING |
92 | */ | 96 | */ |
@@ -108,7 +112,8 @@ struct ClientPhoneRingMessage { | |||
108 | /** | 112 | /** |
109 | * Service <-> Client message for phone was suspended. | 113 | * Service <-> Client message for phone was suspended. |
110 | */ | 114 | */ |
111 | struct ClientPhoneSuspendMessage { | 115 | struct ClientPhoneSuspendMessage |
116 | { | ||
112 | /** | 117 | /** |
113 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND | 118 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND |
114 | */ | 119 | */ |
@@ -125,7 +130,8 @@ struct ClientPhoneSuspendMessage { | |||
125 | /** | 130 | /** |
126 | * Service <-> Client message for phone was resumed. | 131 | * Service <-> Client message for phone was resumed. |
127 | */ | 132 | */ |
128 | struct ClientPhoneResumeMessage { | 133 | struct ClientPhoneResumeMessage |
134 | { | ||
129 | /** | 135 | /** |
130 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME | 136 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME |
131 | */ | 137 | */ |
@@ -142,7 +148,8 @@ struct ClientPhoneResumeMessage { | |||
142 | /** | 148 | /** |
143 | * Client -> Service pick up phone that is ringing. | 149 | * Client -> Service pick up phone that is ringing. |
144 | */ | 150 | */ |
145 | struct ClientPhonePickupMessage { | 151 | struct ClientPhonePickupMessage |
152 | { | ||
146 | /** | 153 | /** |
147 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP | 154 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP |
148 | */ | 155 | */ |
@@ -160,7 +167,8 @@ struct ClientPhonePickupMessage { | |||
160 | * Client <-> Service hang up phone that may or may not be ringing. | 167 | * Client <-> Service hang up phone that may or may not be ringing. |
161 | * Also sent in response to a (failed) `struct ClientCallMessage`. | 168 | * Also sent in response to a (failed) `struct ClientCallMessage`. |
162 | */ | 169 | */ |
163 | struct ClientPhoneHangupMessage { | 170 | struct ClientPhoneHangupMessage |
171 | { | ||
164 | /** | 172 | /** |
165 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP | 173 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP |
166 | */ | 174 | */ |
@@ -177,7 +185,8 @@ struct ClientPhoneHangupMessage { | |||
177 | /** | 185 | /** |
178 | * Message Client <-> Service to transmit the audio. | 186 | * Message Client <-> Service to transmit the audio. |
179 | */ | 187 | */ |
180 | struct ClientAudioMessage { | 188 | struct ClientAudioMessage |
189 | { | ||
181 | /** | 190 | /** |
182 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO | 191 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO |
183 | */ | 192 | */ |
@@ -196,7 +205,8 @@ struct ClientAudioMessage { | |||
196 | /** | 205 | /** |
197 | * Client -> Service message to call a phone. | 206 | * Client -> Service message to call a phone. |
198 | */ | 207 | */ |
199 | struct ClientCallMessage { | 208 | struct ClientCallMessage |
209 | { | ||
200 | /** | 210 | /** |
201 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL | 211 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL |
202 | */ | 212 | */ |
@@ -228,7 +238,8 @@ struct ClientCallMessage { | |||
228 | * Service -> Client: other peer has picked up the phone, we are | 238 | * Service -> Client: other peer has picked up the phone, we are |
229 | * now talking. | 239 | * now talking. |
230 | */ | 240 | */ |
231 | struct ClientPhonePickedupMessage { | 241 | struct ClientPhonePickedupMessage |
242 | { | ||
232 | /** | 243 | /** |
233 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP | 244 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP |
234 | */ | 245 | */ |
@@ -246,7 +257,8 @@ struct ClientPhonePickedupMessage { | |||
246 | * Information signed in a `struct CadetPhoneRingMessage` | 257 | * Information signed in a `struct CadetPhoneRingMessage` |
247 | * whereby the caller self-identifies to the receiver. | 258 | * whereby the caller self-identifies to the receiver. |
248 | */ | 259 | */ |
249 | struct CadetPhoneRingInfoPS { | 260 | struct CadetPhoneRingInfoPS |
261 | { | ||
250 | /** | 262 | /** |
251 | * Purpose for the signature, must be | 263 | * Purpose for the signature, must be |
252 | * #GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING. | 264 | * #GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING. |
@@ -274,7 +286,8 @@ struct CadetPhoneRingInfoPS { | |||
274 | * Cadet message to make a phone ring. Sent to the port | 286 | * Cadet message to make a phone ring. Sent to the port |
275 | * of the respective phone. | 287 | * of the respective phone. |
276 | */ | 288 | */ |
277 | struct CadetPhoneRingMessage { | 289 | struct CadetPhoneRingMessage |
290 | { | ||
278 | /** | 291 | /** |
279 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING | 292 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING |
280 | */ | 293 | */ |
@@ -305,7 +318,8 @@ struct CadetPhoneRingMessage { | |||
305 | /** | 318 | /** |
306 | * Cadet message for hanging up. | 319 | * Cadet message for hanging up. |
307 | */ | 320 | */ |
308 | struct CadetPhoneHangupMessage { | 321 | struct CadetPhoneHangupMessage |
322 | { | ||
309 | /** | 323 | /** |
310 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP | 324 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP |
311 | */ | 325 | */ |
@@ -316,7 +330,8 @@ struct CadetPhoneHangupMessage { | |||
316 | /** | 330 | /** |
317 | * Cadet message for picking up. | 331 | * Cadet message for picking up. |
318 | */ | 332 | */ |
319 | struct CadetPhonePickupMessage { | 333 | struct CadetPhonePickupMessage |
334 | { | ||
320 | /** | 335 | /** |
321 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP | 336 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP |
322 | */ | 337 | */ |
@@ -327,7 +342,8 @@ struct CadetPhonePickupMessage { | |||
327 | /** | 342 | /** |
328 | * Cadet message for phone suspended. | 343 | * Cadet message for phone suspended. |
329 | */ | 344 | */ |
330 | struct CadetPhoneSuspendMessage { | 345 | struct CadetPhoneSuspendMessage |
346 | { | ||
331 | /** | 347 | /** |
332 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND | 348 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND |
333 | */ | 349 | */ |
@@ -338,7 +354,8 @@ struct CadetPhoneSuspendMessage { | |||
338 | /** | 354 | /** |
339 | * Cadet message for phone resumed. | 355 | * Cadet message for phone resumed. |
340 | */ | 356 | */ |
341 | struct CadetPhoneResumeMessage { | 357 | struct CadetPhoneResumeMessage |
358 | { | ||
342 | /** | 359 | /** |
343 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME | 360 | * Type is: #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME |
344 | */ | 361 | */ |
@@ -349,7 +366,8 @@ struct CadetPhoneResumeMessage { | |||
349 | /** | 366 | /** |
350 | * Cadet message to transmit the audio. | 367 | * Cadet message to transmit the audio. |
351 | */ | 368 | */ |
352 | struct CadetAudioMessage { | 369 | struct CadetAudioMessage |
370 | { | ||
353 | /** | 371 | /** |
354 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO | 372 | * Type is #GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO |
355 | */ | 373 | */ |
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index 4c19a7d2d..eb070e56e 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Possible states of a caller. | 34 | * Possible states of a caller. |
35 | */ | 35 | */ |
36 | enum CallerState { | 36 | enum CallerState |
37 | { | ||
37 | /** | 38 | /** |
38 | * The phone is ringing (user knows about incoming call). | 39 | * The phone is ringing (user knows about incoming call). |
39 | */ | 40 | */ |
@@ -65,7 +66,8 @@ enum CallerState { | |||
65 | /** | 66 | /** |
66 | * A caller is the handle we have for an incoming call. | 67 | * A caller is the handle we have for an incoming call. |
67 | */ | 68 | */ |
68 | struct GNUNET_CONVERSATION_Caller { | 69 | struct GNUNET_CONVERSATION_Caller |
70 | { | ||
69 | /** | 71 | /** |
70 | * We keep all callers in a DLL. | 72 | * We keep all callers in a DLL. |
71 | */ | 73 | */ |
@@ -121,7 +123,8 @@ struct GNUNET_CONVERSATION_Caller { | |||
121 | /** | 123 | /** |
122 | * Possible states of a phone. | 124 | * Possible states of a phone. |
123 | */ | 125 | */ |
124 | enum PhoneState { | 126 | enum PhoneState |
127 | { | ||
125 | /** | 128 | /** |
126 | * We still need to register the phone. | 129 | * We still need to register the phone. |
127 | */ | 130 | */ |
@@ -145,7 +148,8 @@ enum PhoneState { | |||
145 | * something rather internal to a phone and not obvious from it). | 148 | * something rather internal to a phone and not obvious from it). |
146 | * You can only have one conversation per phone at any time. | 149 | * You can only have one conversation per phone at any time. |
147 | */ | 150 | */ |
148 | struct GNUNET_CONVERSATION_Phone { | 151 | struct GNUNET_CONVERSATION_Phone |
152 | { | ||
149 | /** | 153 | /** |
150 | * Our configuration. | 154 | * Our configuration. |
151 | */ | 155 | */ |
@@ -204,7 +208,7 @@ struct GNUNET_CONVERSATION_Phone { | |||
204 | * @param phone phone to reconnect | 208 | * @param phone phone to reconnect |
205 | */ | 209 | */ |
206 | static void | 210 | static void |
207 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone); | 211 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone); |
208 | 212 | ||
209 | 213 | ||
210 | /** | 214 | /** |
@@ -215,24 +219,24 @@ reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone); | |||
215 | * @param data audio data to play | 219 | * @param data audio data to play |
216 | */ | 220 | */ |
217 | static void | 221 | static void |
218 | transmit_phone_audio(void *cls, | 222 | transmit_phone_audio (void *cls, |
219 | size_t data_size, | 223 | size_t data_size, |
220 | const void *data) | 224 | const void *data) |
221 | { | 225 | { |
222 | struct GNUNET_CONVERSATION_Caller *caller = cls; | 226 | struct GNUNET_CONVERSATION_Caller *caller = cls; |
223 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 227 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
224 | struct GNUNET_MQ_Envelope *e; | 228 | struct GNUNET_MQ_Envelope *e; |
225 | struct ClientAudioMessage *am; | 229 | struct ClientAudioMessage *am; |
226 | 230 | ||
227 | e = GNUNET_MQ_msg_extra(am, | 231 | e = GNUNET_MQ_msg_extra (am, |
228 | data_size, | 232 | data_size, |
229 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 233 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
230 | am->cid = caller->cid; | 234 | am->cid = caller->cid; |
231 | GNUNET_memcpy(&am[1], | 235 | GNUNET_memcpy (&am[1], |
232 | data, | 236 | data, |
233 | data_size); | 237 | data_size); |
234 | GNUNET_MQ_send(phone->mq, | 238 | GNUNET_MQ_send (phone->mq, |
235 | e); | 239 | e); |
236 | } | 240 | } |
237 | 241 | ||
238 | 242 | ||
@@ -243,33 +247,33 @@ transmit_phone_audio(void *cls, | |||
243 | * @param ring the message | 247 | * @param ring the message |
244 | */ | 248 | */ |
245 | static void | 249 | static void |
246 | handle_phone_ring(void *cls, | 250 | handle_phone_ring (void *cls, |
247 | const struct ClientPhoneRingMessage *ring) | 251 | const struct ClientPhoneRingMessage *ring) |
248 | { | 252 | { |
249 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 253 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
250 | struct GNUNET_CONVERSATION_Caller *caller; | 254 | struct GNUNET_CONVERSATION_Caller *caller; |
251 | 255 | ||
252 | switch (phone->state) | 256 | switch (phone->state) |
253 | { | 257 | { |
254 | case PS_REGISTER: | 258 | case PS_REGISTER: |
255 | GNUNET_assert(0); | 259 | GNUNET_assert (0); |
256 | break; | 260 | break; |
257 | 261 | ||
258 | case PS_READY: | 262 | case PS_READY: |
259 | caller = GNUNET_new(struct GNUNET_CONVERSATION_Caller); | 263 | caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller); |
260 | caller->phone = phone; | 264 | caller->phone = phone; |
261 | GNUNET_CONTAINER_DLL_insert(phone->caller_head, | 265 | GNUNET_CONTAINER_DLL_insert (phone->caller_head, |
262 | phone->caller_tail, | 266 | phone->caller_tail, |
263 | caller); | 267 | caller); |
264 | caller->caller_id = ring->caller_id; | 268 | caller->caller_id = ring->caller_id; |
265 | caller->cid = ring->cid; | 269 | caller->cid = ring->cid; |
266 | caller->state = CS_RINGING; | 270 | caller->state = CS_RINGING; |
267 | phone->event_handler(phone->event_handler_cls, | 271 | phone->event_handler (phone->event_handler_cls, |
268 | GNUNET_CONVERSATION_EC_PHONE_RING, | 272 | GNUNET_CONVERSATION_EC_PHONE_RING, |
269 | caller, | 273 | caller, |
270 | &caller->caller_id); | 274 | &caller->caller_id); |
271 | break; | 275 | break; |
272 | } | 276 | } |
273 | } | 277 | } |
274 | 278 | ||
275 | 279 | ||
@@ -281,8 +285,8 @@ handle_phone_ring(void *cls, | |||
281 | * @return NULL if @a cid was not found | 285 | * @return NULL if @a cid was not found |
282 | */ | 286 | */ |
283 | static struct GNUNET_CONVERSATION_Caller * | 287 | static struct GNUNET_CONVERSATION_Caller * |
284 | find_caller(struct GNUNET_CONVERSATION_Phone *phone, | 288 | find_caller (struct GNUNET_CONVERSATION_Phone *phone, |
285 | uint32_t cid) | 289 | uint32_t cid) |
286 | { | 290 | { |
287 | struct GNUNET_CONVERSATION_Caller *caller; | 291 | struct GNUNET_CONVERSATION_Caller *caller; |
288 | 292 | ||
@@ -300,56 +304,56 @@ find_caller(struct GNUNET_CONVERSATION_Phone *phone, | |||
300 | * @param msg the message | 304 | * @param msg the message |
301 | */ | 305 | */ |
302 | static void | 306 | static void |
303 | handle_phone_hangup(void *cls, | 307 | handle_phone_hangup (void *cls, |
304 | const struct ClientPhoneHangupMessage *hang) | 308 | const struct ClientPhoneHangupMessage *hang) |
305 | { | 309 | { |
306 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 310 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
307 | struct GNUNET_CONVERSATION_Caller *caller; | 311 | struct GNUNET_CONVERSATION_Caller *caller; |
308 | 312 | ||
309 | caller = find_caller(phone, | 313 | caller = find_caller (phone, |
310 | hang->cid); | 314 | hang->cid); |
311 | if (NULL == caller) | 315 | if (NULL == caller) |
312 | { | 316 | { |
313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
314 | "Received HANG_UP message for unknown caller ID %u\n", | 318 | "Received HANG_UP message for unknown caller ID %u\n", |
315 | (unsigned int)hang->cid); | 319 | (unsigned int) hang->cid); |
316 | return; | 320 | return; |
317 | } | 321 | } |
318 | 322 | ||
319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
320 | "Received HANG_UP message, terminating call with `%s'\n", | 324 | "Received HANG_UP message, terminating call with `%s'\n", |
321 | GNUNET_GNSRECORD_pkey_to_zkey(&caller->caller_id)); | 325 | GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id)); |
322 | switch (caller->state) | 326 | switch (caller->state) |
323 | { | 327 | { |
324 | case CS_RINGING: | 328 | case CS_RINGING: |
325 | phone->event_handler(phone->event_handler_cls, | 329 | phone->event_handler (phone->event_handler_cls, |
326 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 330 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
327 | caller, | 331 | caller, |
328 | &caller->caller_id); | 332 | &caller->caller_id); |
329 | break; | 333 | break; |
330 | 334 | ||
331 | case CS_ACTIVE: | 335 | case CS_ACTIVE: |
332 | caller->speaker->disable_speaker(caller->speaker->cls); | 336 | caller->speaker->disable_speaker (caller->speaker->cls); |
333 | caller->mic->disable_microphone(caller->mic->cls); | 337 | caller->mic->disable_microphone (caller->mic->cls); |
334 | phone->event_handler(phone->event_handler_cls, | 338 | phone->event_handler (phone->event_handler_cls, |
335 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 339 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
336 | caller, | 340 | caller, |
337 | &caller->caller_id); | 341 | &caller->caller_id); |
338 | break; | 342 | break; |
339 | 343 | ||
340 | case CS_CALLEE_SUSPENDED: | 344 | case CS_CALLEE_SUSPENDED: |
341 | case CS_CALLER_SUSPENDED: | 345 | case CS_CALLER_SUSPENDED: |
342 | case CS_BOTH_SUSPENDED: | 346 | case CS_BOTH_SUSPENDED: |
343 | phone->event_handler(phone->event_handler_cls, | 347 | phone->event_handler (phone->event_handler_cls, |
344 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 348 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
345 | caller, | 349 | caller, |
346 | &caller->caller_id); | 350 | &caller->caller_id); |
347 | break; | 351 | break; |
348 | } | 352 | } |
349 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, | 353 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, |
350 | phone->caller_tail, | 354 | phone->caller_tail, |
351 | caller); | 355 | caller); |
352 | GNUNET_free(caller); | 356 | GNUNET_free (caller); |
353 | } | 357 | } |
354 | 358 | ||
355 | 359 | ||
@@ -360,41 +364,41 @@ handle_phone_hangup(void *cls, | |||
360 | * @param suspend the message | 364 | * @param suspend the message |
361 | */ | 365 | */ |
362 | static void | 366 | static void |
363 | handle_phone_suspend(void *cls, | 367 | handle_phone_suspend (void *cls, |
364 | const struct ClientPhoneSuspendMessage *suspend) | 368 | const struct ClientPhoneSuspendMessage *suspend) |
365 | { | 369 | { |
366 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 370 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
367 | struct GNUNET_CONVERSATION_Caller *caller; | 371 | struct GNUNET_CONVERSATION_Caller *caller; |
368 | 372 | ||
369 | caller = find_caller(phone, | 373 | caller = find_caller (phone, |
370 | suspend->cid); | 374 | suspend->cid); |
371 | if (NULL == caller) | 375 | if (NULL == caller) |
372 | return; | 376 | return; |
373 | switch (caller->state) | 377 | switch (caller->state) |
374 | { | 378 | { |
375 | case CS_RINGING: | 379 | case CS_RINGING: |
376 | GNUNET_break_op(0); | 380 | GNUNET_break_op (0); |
377 | break; | 381 | break; |
378 | 382 | ||
379 | case CS_ACTIVE: | 383 | case CS_ACTIVE: |
380 | caller->state = CS_CALLER_SUSPENDED; | 384 | caller->state = CS_CALLER_SUSPENDED; |
381 | caller->speaker->disable_speaker(caller->speaker->cls); | 385 | caller->speaker->disable_speaker (caller->speaker->cls); |
382 | caller->mic->disable_microphone(caller->mic->cls); | 386 | caller->mic->disable_microphone (caller->mic->cls); |
383 | caller->event_handler(caller->event_handler_cls, | 387 | caller->event_handler (caller->event_handler_cls, |
384 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 388 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
385 | break; | 389 | break; |
386 | 390 | ||
387 | case CS_CALLEE_SUSPENDED: | 391 | case CS_CALLEE_SUSPENDED: |
388 | caller->state = CS_BOTH_SUSPENDED; | 392 | caller->state = CS_BOTH_SUSPENDED; |
389 | caller->event_handler(caller->event_handler_cls, | 393 | caller->event_handler (caller->event_handler_cls, |
390 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 394 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
391 | break; | 395 | break; |
392 | 396 | ||
393 | case CS_CALLER_SUSPENDED: | 397 | case CS_CALLER_SUSPENDED: |
394 | case CS_BOTH_SUSPENDED: | 398 | case CS_BOTH_SUSPENDED: |
395 | GNUNET_break_op(0); | 399 | GNUNET_break_op (0); |
396 | break; | 400 | break; |
397 | } | 401 | } |
398 | } | 402 | } |
399 | 403 | ||
400 | 404 | ||
@@ -405,43 +409,43 @@ handle_phone_suspend(void *cls, | |||
405 | * @param resume the message | 409 | * @param resume the message |
406 | */ | 410 | */ |
407 | static void | 411 | static void |
408 | handle_phone_resume(void *cls, | 412 | handle_phone_resume (void *cls, |
409 | const struct ClientPhoneResumeMessage *resume) | 413 | const struct ClientPhoneResumeMessage *resume) |
410 | { | 414 | { |
411 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 415 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
412 | struct GNUNET_CONVERSATION_Caller *caller; | 416 | struct GNUNET_CONVERSATION_Caller *caller; |
413 | 417 | ||
414 | caller = find_caller(phone, | 418 | caller = find_caller (phone, |
415 | resume->cid); | 419 | resume->cid); |
416 | if (NULL == caller) | 420 | if (NULL == caller) |
417 | return; | 421 | return; |
418 | switch (caller->state) | 422 | switch (caller->state) |
419 | { | 423 | { |
420 | case CS_RINGING: | 424 | case CS_RINGING: |
421 | GNUNET_break_op(0); | 425 | GNUNET_break_op (0); |
422 | break; | 426 | break; |
423 | 427 | ||
424 | case CS_ACTIVE: | 428 | case CS_ACTIVE: |
425 | case CS_CALLEE_SUSPENDED: | 429 | case CS_CALLEE_SUSPENDED: |
426 | GNUNET_break_op(0); | 430 | GNUNET_break_op (0); |
427 | break; | 431 | break; |
428 | 432 | ||
429 | case CS_CALLER_SUSPENDED: | 433 | case CS_CALLER_SUSPENDED: |
430 | caller->state = CS_ACTIVE; | 434 | caller->state = CS_ACTIVE; |
431 | caller->speaker->enable_speaker(caller->speaker->cls); | 435 | caller->speaker->enable_speaker (caller->speaker->cls); |
432 | caller->mic->enable_microphone(caller->mic->cls, | 436 | caller->mic->enable_microphone (caller->mic->cls, |
433 | &transmit_phone_audio, | 437 | &transmit_phone_audio, |
434 | caller); | 438 | caller); |
435 | caller->event_handler(caller->event_handler_cls, | 439 | caller->event_handler (caller->event_handler_cls, |
436 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 440 | GNUNET_CONVERSATION_EC_CALLER_RESUME); |
437 | break; | 441 | break; |
438 | 442 | ||
439 | case CS_BOTH_SUSPENDED: | 443 | case CS_BOTH_SUSPENDED: |
440 | caller->state = CS_CALLEE_SUSPENDED; | 444 | caller->state = CS_CALLEE_SUSPENDED; |
441 | caller->event_handler(caller->event_handler_cls, | 445 | caller->event_handler (caller->event_handler_cls, |
442 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 446 | GNUNET_CONVERSATION_EC_CALLER_RESUME); |
443 | break; | 447 | break; |
444 | } | 448 | } |
445 | } | 449 | } |
446 | 450 | ||
447 | 451 | ||
@@ -453,11 +457,11 @@ handle_phone_resume(void *cls, | |||
453 | * @return #GNUNET_OK if @a am is well-formed | 457 | * @return #GNUNET_OK if @a am is well-formed |
454 | */ | 458 | */ |
455 | static int | 459 | static int |
456 | check_phone_audio(void *cls, | 460 | check_phone_audio (void *cls, |
457 | const struct ClientAudioMessage *am) | 461 | const struct ClientAudioMessage *am) |
458 | { | 462 | { |
459 | (void)cls; | 463 | (void) cls; |
460 | (void)am; | 464 | (void) am; |
461 | 465 | ||
462 | /* any variable-size payload is OK */ | 466 | /* any variable-size payload is OK */ |
463 | return GNUNET_OK; | 467 | return GNUNET_OK; |
@@ -471,33 +475,34 @@ check_phone_audio(void *cls, | |||
471 | * @param am the message | 475 | * @param am the message |
472 | */ | 476 | */ |
473 | static void | 477 | static void |
474 | handle_phone_audio(void *cls, | 478 | handle_phone_audio (void *cls, |
475 | const struct ClientAudioMessage *am) | 479 | const struct ClientAudioMessage *am) |
476 | { | 480 | { |
477 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 481 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
478 | struct GNUNET_CONVERSATION_Caller *caller; | 482 | struct GNUNET_CONVERSATION_Caller *caller; |
479 | 483 | ||
480 | caller = find_caller(phone, | 484 | caller = find_caller (phone, |
481 | am->cid); | 485 | am->cid); |
482 | if (NULL == caller) | 486 | if (NULL == caller) |
483 | return; | 487 | return; |
484 | switch (caller->state) | 488 | switch (caller->state) |
485 | { | 489 | { |
486 | case CS_RINGING: | 490 | case CS_RINGING: |
487 | GNUNET_break_op(0); | 491 | GNUNET_break_op (0); |
488 | break; | 492 | break; |
489 | 493 | ||
490 | case CS_ACTIVE: | 494 | case CS_ACTIVE: |
491 | caller->speaker->play(caller->speaker->cls, | 495 | caller->speaker->play (caller->speaker->cls, |
492 | ntohs(am->header.size) - sizeof(struct ClientAudioMessage), | 496 | ntohs (am->header.size) - sizeof(struct |
493 | &am[1]); | 497 | ClientAudioMessage), |
494 | break; | 498 | &am[1]); |
495 | 499 | break; | |
496 | case CS_CALLEE_SUSPENDED: | 500 | |
497 | case CS_CALLER_SUSPENDED: | 501 | case CS_CALLEE_SUSPENDED: |
498 | case CS_BOTH_SUSPENDED: | 502 | case CS_CALLER_SUSPENDED: |
499 | break; | 503 | case CS_BOTH_SUSPENDED: |
500 | } | 504 | break; |
505 | } | ||
501 | } | 506 | } |
502 | 507 | ||
503 | 508 | ||
@@ -508,15 +513,16 @@ handle_phone_audio(void *cls, | |||
508 | * @param error details about the error | 513 | * @param error details about the error |
509 | */ | 514 | */ |
510 | static void | 515 | static void |
511 | phone_error_handler(void *cls, | 516 | phone_error_handler (void *cls, |
512 | enum GNUNET_MQ_Error error) | 517 | enum GNUNET_MQ_Error error) |
513 | { | 518 | { |
514 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 519 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
515 | 520 | ||
516 | (void)error; | 521 | (void) error; |
517 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
518 | _("Connection to conversation service lost, trying to reconnect\n")); | 523 | _ ( |
519 | reconnect_phone(phone); | 524 | "Connection to conversation service lost, trying to reconnect\n")); |
525 | reconnect_phone (phone); | ||
520 | } | 526 | } |
521 | 527 | ||
522 | 528 | ||
@@ -526,25 +532,25 @@ phone_error_handler(void *cls, | |||
526 | * @param phone phone to clean up callers for | 532 | * @param phone phone to clean up callers for |
527 | */ | 533 | */ |
528 | static void | 534 | static void |
529 | clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone) | 535 | clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone) |
530 | { | 536 | { |
531 | struct GNUNET_CONVERSATION_Caller *caller; | 537 | struct GNUNET_CONVERSATION_Caller *caller; |
532 | 538 | ||
533 | while (NULL != (caller = phone->caller_head)) | 539 | while (NULL != (caller = phone->caller_head)) |
540 | { | ||
541 | /* make sure mic/speaker are disabled *before* callback */ | ||
542 | if (CS_ACTIVE == caller->state) | ||
534 | { | 543 | { |
535 | /* make sure mic/speaker are disabled *before* callback */ | 544 | caller->speaker->disable_speaker (caller->speaker->cls); |
536 | if (CS_ACTIVE == caller->state) | 545 | caller->mic->disable_microphone (caller->mic->cls); |
537 | { | 546 | caller->state = CS_CALLER_SUSPENDED; |
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); | ||
547 | } | 547 | } |
548 | phone->event_handler (phone->event_handler_cls, | ||
549 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | ||
550 | caller, | ||
551 | &caller->caller_id); | ||
552 | GNUNET_CONVERSATION_caller_hang_up (caller); | ||
553 | } | ||
548 | } | 554 | } |
549 | 555 | ||
550 | 556 | ||
@@ -554,53 +560,53 @@ clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone) | |||
554 | * @param phone phone to reconnect | 560 | * @param phone phone to reconnect |
555 | */ | 561 | */ |
556 | static void | 562 | static void |
557 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone) | 563 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) |
558 | { | 564 | { |
559 | struct GNUNET_MQ_MessageHandler handlers[] = { | 565 | struct GNUNET_MQ_MessageHandler handlers[] = { |
560 | GNUNET_MQ_hd_fixed_size(phone_ring, | 566 | GNUNET_MQ_hd_fixed_size (phone_ring, |
561 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, | 567 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, |
562 | struct ClientPhoneRingMessage, | 568 | struct ClientPhoneRingMessage, |
563 | phone), | 569 | phone), |
564 | GNUNET_MQ_hd_fixed_size(phone_hangup, | 570 | GNUNET_MQ_hd_fixed_size (phone_hangup, |
565 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 571 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
566 | struct ClientPhoneHangupMessage, | 572 | struct ClientPhoneHangupMessage, |
567 | phone), | 573 | phone), |
568 | GNUNET_MQ_hd_fixed_size(phone_suspend, | 574 | GNUNET_MQ_hd_fixed_size (phone_suspend, |
569 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 575 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
570 | struct ClientPhoneSuspendMessage, | 576 | struct ClientPhoneSuspendMessage, |
571 | phone), | 577 | phone), |
572 | GNUNET_MQ_hd_fixed_size(phone_resume, | 578 | GNUNET_MQ_hd_fixed_size (phone_resume, |
573 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 579 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
574 | struct ClientPhoneResumeMessage, | 580 | struct ClientPhoneResumeMessage, |
575 | phone), | 581 | phone), |
576 | GNUNET_MQ_hd_var_size(phone_audio, | 582 | GNUNET_MQ_hd_var_size (phone_audio, |
577 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 583 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
578 | struct ClientAudioMessage, | 584 | struct ClientAudioMessage, |
579 | phone), | 585 | phone), |
580 | GNUNET_MQ_handler_end() | 586 | GNUNET_MQ_handler_end () |
581 | }; | 587 | }; |
582 | struct GNUNET_MQ_Envelope *e; | 588 | struct GNUNET_MQ_Envelope *e; |
583 | struct ClientPhoneRegisterMessage *reg; | 589 | struct ClientPhoneRegisterMessage *reg; |
584 | 590 | ||
585 | clean_up_callers(phone); | 591 | clean_up_callers (phone); |
586 | if (NULL != phone->mq) | 592 | if (NULL != phone->mq) |
587 | { | 593 | { |
588 | GNUNET_MQ_destroy(phone->mq); | 594 | GNUNET_MQ_destroy (phone->mq); |
589 | phone->mq = NULL; | 595 | phone->mq = NULL; |
590 | } | 596 | } |
591 | phone->state = PS_REGISTER; | 597 | phone->state = PS_REGISTER; |
592 | phone->mq = GNUNET_CLIENT_connect(phone->cfg, | 598 | phone->mq = GNUNET_CLIENT_connect (phone->cfg, |
593 | "conversation", | 599 | "conversation", |
594 | handlers, | 600 | handlers, |
595 | &phone_error_handler, | 601 | &phone_error_handler, |
596 | phone); | 602 | phone); |
597 | if (NULL == phone->mq) | 603 | if (NULL == phone->mq) |
598 | return; | 604 | return; |
599 | e = GNUNET_MQ_msg(reg, | 605 | e = GNUNET_MQ_msg (reg, |
600 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); | 606 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); |
601 | reg->line_port = phone->my_record.line_port; | 607 | reg->line_port = phone->my_record.line_port; |
602 | GNUNET_MQ_send(phone->mq, | 608 | GNUNET_MQ_send (phone->mq, |
603 | e); | 609 | e); |
604 | phone->state = PS_READY; | 610 | phone->state = PS_READY; |
605 | } | 611 | } |
606 | 612 | ||
@@ -616,54 +622,55 @@ reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone) | |||
616 | * @return NULL on error (no valid line configured) | 622 | * @return NULL on error (no valid line configured) |
617 | */ | 623 | */ |
618 | struct GNUNET_CONVERSATION_Phone * | 624 | struct GNUNET_CONVERSATION_Phone * |
619 | GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | 625 | GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, |
620 | const struct GNUNET_IDENTITY_Ego *ego, | 626 | const struct GNUNET_IDENTITY_Ego *ego, |
621 | GNUNET_CONVERSATION_PhoneEventHandler event_handler, | 627 | GNUNET_CONVERSATION_PhoneEventHandler |
622 | void *event_handler_cls) | 628 | event_handler, |
629 | void *event_handler_cls) | ||
623 | { | 630 | { |
624 | struct GNUNET_CONVERSATION_Phone *phone; | 631 | struct GNUNET_CONVERSATION_Phone *phone; |
625 | char *line; | 632 | char *line; |
626 | struct GNUNET_HashCode line_port; | 633 | struct GNUNET_HashCode line_port; |
627 | 634 | ||
628 | if (GNUNET_OK != | 635 | if (GNUNET_OK != |
629 | GNUNET_CONFIGURATION_get_value_string(cfg, | 636 | GNUNET_CONFIGURATION_get_value_string (cfg, |
630 | "CONVERSATION", | 637 | "CONVERSATION", |
631 | "LINE", | 638 | "LINE", |
632 | &line)) | 639 | &line)) |
633 | { | 640 | { |
634 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 641 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
635 | "CONVERSATION", | 642 | "CONVERSATION", |
636 | "LINE"); | 643 | "LINE"); |
637 | return NULL; | 644 | return NULL; |
638 | } | 645 | } |
639 | GNUNET_CRYPTO_hash(line, | 646 | GNUNET_CRYPTO_hash (line, |
640 | strlen(line), | 647 | strlen (line), |
641 | &line_port); | 648 | &line_port); |
642 | phone = GNUNET_new(struct GNUNET_CONVERSATION_Phone); | 649 | phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone); |
643 | if (GNUNET_OK != | 650 | if (GNUNET_OK != |
644 | GNUNET_CRYPTO_get_peer_identity(cfg, | 651 | GNUNET_CRYPTO_get_peer_identity (cfg, |
645 | &phone->my_record.peer)) | 652 | &phone->my_record.peer)) |
646 | { | 653 | { |
647 | GNUNET_break(0); | 654 | GNUNET_break (0); |
648 | GNUNET_free(phone); | 655 | GNUNET_free (phone); |
649 | return NULL; | 656 | return NULL; |
650 | } | 657 | } |
651 | phone->cfg = cfg; | 658 | phone->cfg = cfg; |
652 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key(ego); | 659 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key (ego); |
653 | phone->event_handler = event_handler; | 660 | phone->event_handler = event_handler; |
654 | phone->event_handler_cls = event_handler_cls; | 661 | phone->event_handler_cls = event_handler_cls; |
655 | phone->ns = GNUNET_NAMESTORE_connect(cfg); | 662 | phone->ns = GNUNET_NAMESTORE_connect (cfg); |
656 | phone->my_record.version = htonl(1); | 663 | phone->my_record.version = htonl (1); |
657 | phone->my_record.reserved = htonl(0); | 664 | phone->my_record.reserved = htonl (0); |
658 | phone->my_record.line_port = line_port; | 665 | phone->my_record.line_port = line_port; |
659 | reconnect_phone(phone); | 666 | reconnect_phone (phone); |
660 | if ((NULL == phone->mq) || | 667 | if ((NULL == phone->mq) || |
661 | (NULL == phone->ns)) | 668 | (NULL == phone->ns)) |
662 | { | 669 | { |
663 | GNUNET_break(0); | 670 | GNUNET_break (0); |
664 | GNUNET_CONVERSATION_phone_destroy(phone); | 671 | GNUNET_CONVERSATION_phone_destroy (phone); |
665 | return NULL; | 672 | return NULL; |
666 | } | 673 | } |
667 | return phone; | 674 | return phone; |
668 | } | 675 | } |
669 | 676 | ||
@@ -677,8 +684,8 @@ GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
677 | * @param rd namestore record to fill in | 684 | * @param rd namestore record to fill in |
678 | */ | 685 | */ |
679 | void | 686 | void |
680 | GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, | 687 | GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, |
681 | struct GNUNET_GNSRECORD_Data *rd) | 688 | struct GNUNET_GNSRECORD_Data *rd) |
682 | { | 689 | { |
683 | rd->data = &phone->my_record; | 690 | rd->data = &phone->my_record; |
684 | rd->expiration_time = 0; | 691 | rd->expiration_time = 0; |
@@ -699,31 +706,32 @@ GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, | |||
699 | * @param mic microphone to use | 706 | * @param mic microphone to use |
700 | */ | 707 | */ |
701 | void | 708 | void |
702 | GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, | 709 | GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, |
703 | GNUNET_CONVERSATION_CallerEventHandler event_handler, | 710 | GNUNET_CONVERSATION_CallerEventHandler |
704 | void *event_handler_cls, | 711 | event_handler, |
705 | struct GNUNET_SPEAKER_Handle *speaker, | 712 | void *event_handler_cls, |
706 | struct GNUNET_MICROPHONE_Handle *mic) | 713 | struct GNUNET_SPEAKER_Handle *speaker, |
714 | struct GNUNET_MICROPHONE_Handle *mic) | ||
707 | { | 715 | { |
708 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 716 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
709 | struct GNUNET_MQ_Envelope *e; | 717 | struct GNUNET_MQ_Envelope *e; |
710 | struct ClientPhonePickupMessage *pick; | 718 | struct ClientPhonePickupMessage *pick; |
711 | 719 | ||
712 | GNUNET_assert(CS_RINGING == caller->state); | 720 | GNUNET_assert (CS_RINGING == caller->state); |
713 | caller->speaker = speaker; | 721 | caller->speaker = speaker; |
714 | caller->mic = mic; | 722 | caller->mic = mic; |
715 | e = GNUNET_MQ_msg(pick, | 723 | e = GNUNET_MQ_msg (pick, |
716 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); | 724 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); |
717 | pick->cid = caller->cid; | 725 | pick->cid = caller->cid; |
718 | GNUNET_MQ_send(phone->mq, | 726 | GNUNET_MQ_send (phone->mq, |
719 | e); | 727 | e); |
720 | caller->state = CS_ACTIVE; | 728 | caller->state = CS_ACTIVE; |
721 | caller->event_handler = event_handler; | 729 | caller->event_handler = event_handler; |
722 | caller->event_handler_cls = event_handler_cls; | 730 | caller->event_handler_cls = event_handler_cls; |
723 | caller->speaker->enable_speaker(caller->speaker->cls); | 731 | caller->speaker->enable_speaker (caller->speaker->cls); |
724 | caller->mic->enable_microphone(caller->mic->cls, | 732 | caller->mic->enable_microphone (caller->mic->cls, |
725 | &transmit_phone_audio, | 733 | &transmit_phone_audio, |
726 | caller); | 734 | caller); |
727 | } | 735 | } |
728 | 736 | ||
729 | 737 | ||
@@ -734,31 +742,31 @@ GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, | |||
734 | * @param caller conversation to hang up on | 742 | * @param caller conversation to hang up on |
735 | */ | 743 | */ |
736 | void | 744 | void |
737 | GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller) | 745 | GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) |
738 | { | 746 | { |
739 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 747 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
740 | struct GNUNET_MQ_Envelope *e; | 748 | struct GNUNET_MQ_Envelope *e; |
741 | struct ClientPhoneHangupMessage *hang; | 749 | struct ClientPhoneHangupMessage *hang; |
742 | 750 | ||
743 | switch (caller->state) | 751 | switch (caller->state) |
744 | { | 752 | { |
745 | case CS_ACTIVE: | 753 | case CS_ACTIVE: |
746 | caller->speaker->disable_speaker(caller->speaker->cls); | 754 | caller->speaker->disable_speaker (caller->speaker->cls); |
747 | caller->mic->disable_microphone(caller->mic->cls); | 755 | caller->mic->disable_microphone (caller->mic->cls); |
748 | break; | 756 | break; |
749 | 757 | ||
750 | default: | 758 | default: |
751 | break; | 759 | break; |
752 | } | 760 | } |
753 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, | 761 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, |
754 | phone->caller_tail, | 762 | phone->caller_tail, |
755 | caller); | 763 | caller); |
756 | e = GNUNET_MQ_msg(hang, | 764 | e = GNUNET_MQ_msg (hang, |
757 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 765 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); |
758 | hang->cid = caller->cid; | 766 | hang->cid = caller->cid; |
759 | GNUNET_MQ_send(phone->mq, | 767 | GNUNET_MQ_send (phone->mq, |
760 | e); | 768 | e); |
761 | GNUNET_free(caller); | 769 | GNUNET_free (caller); |
762 | } | 770 | } |
763 | 771 | ||
764 | 772 | ||
@@ -768,20 +776,20 @@ GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller) | |||
768 | * @param phone phone to destroy | 776 | * @param phone phone to destroy |
769 | */ | 777 | */ |
770 | void | 778 | void |
771 | GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone) | 779 | GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) |
772 | { | 780 | { |
773 | clean_up_callers(phone); | 781 | clean_up_callers (phone); |
774 | if (NULL != phone->ns) | 782 | if (NULL != phone->ns) |
775 | { | 783 | { |
776 | GNUNET_NAMESTORE_disconnect(phone->ns); | 784 | GNUNET_NAMESTORE_disconnect (phone->ns); |
777 | phone->ns = NULL; | 785 | phone->ns = NULL; |
778 | } | 786 | } |
779 | if (NULL != phone->mq) | 787 | if (NULL != phone->mq) |
780 | { | 788 | { |
781 | GNUNET_MQ_destroy(phone->mq); | 789 | GNUNET_MQ_destroy (phone->mq); |
782 | phone->mq = NULL; | 790 | phone->mq = NULL; |
783 | } | 791 | } |
784 | GNUNET_free(phone); | 792 | GNUNET_free (phone); |
785 | } | 793 | } |
786 | 794 | ||
787 | 795 | ||
@@ -793,26 +801,26 @@ GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone) | |||
793 | * @param caller call to suspend | 801 | * @param caller call to suspend |
794 | */ | 802 | */ |
795 | void | 803 | void |
796 | GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller) | 804 | GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller) |
797 | { | 805 | { |
798 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 806 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
799 | struct GNUNET_MQ_Envelope *e; | 807 | struct GNUNET_MQ_Envelope *e; |
800 | struct ClientPhoneSuspendMessage *suspend; | 808 | struct ClientPhoneSuspendMessage *suspend; |
801 | 809 | ||
802 | GNUNET_assert((CS_ACTIVE == caller->state) || | 810 | GNUNET_assert ((CS_ACTIVE == caller->state) || |
803 | (CS_CALLER_SUSPENDED == caller->state)); | 811 | (CS_CALLER_SUSPENDED == caller->state)); |
804 | if (CS_ACTIVE == caller->state) | 812 | if (CS_ACTIVE == caller->state) |
805 | { | 813 | { |
806 | caller->speaker->disable_speaker(caller->speaker->cls); | 814 | caller->speaker->disable_speaker (caller->speaker->cls); |
807 | caller->mic->disable_microphone(caller->mic->cls); | 815 | caller->mic->disable_microphone (caller->mic->cls); |
808 | } | 816 | } |
809 | caller->speaker = NULL; | 817 | caller->speaker = NULL; |
810 | caller->mic = NULL; | 818 | caller->mic = NULL; |
811 | e = GNUNET_MQ_msg(suspend, | 819 | e = GNUNET_MQ_msg (suspend, |
812 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 820 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
813 | suspend->cid = caller->cid; | 821 | suspend->cid = caller->cid; |
814 | GNUNET_MQ_send(phone->mq, | 822 | GNUNET_MQ_send (phone->mq, |
815 | e); | 823 | e); |
816 | if (CS_ACTIVE == caller->state) | 824 | if (CS_ACTIVE == caller->state) |
817 | caller->state = CS_CALLEE_SUSPENDED; | 825 | caller->state = CS_CALLEE_SUSPENDED; |
818 | else | 826 | else |
@@ -828,35 +836,35 @@ GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller) | |||
828 | * @param mic microphone to use | 836 | * @param mic microphone to use |
829 | */ | 837 | */ |
830 | void | 838 | void |
831 | GNUNET_CONVERSATION_caller_resume(struct GNUNET_CONVERSATION_Caller *caller, | 839 | GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller, |
832 | struct GNUNET_SPEAKER_Handle *speaker, | 840 | struct GNUNET_SPEAKER_Handle *speaker, |
833 | struct GNUNET_MICROPHONE_Handle *mic) | 841 | struct GNUNET_MICROPHONE_Handle *mic) |
834 | { | 842 | { |
835 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 843 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
836 | struct GNUNET_MQ_Envelope *e; | 844 | struct GNUNET_MQ_Envelope *e; |
837 | struct ClientPhoneResumeMessage *resume; | 845 | struct ClientPhoneResumeMessage *resume; |
838 | 846 | ||
839 | GNUNET_assert((CS_CALLEE_SUSPENDED == caller->state) || | 847 | GNUNET_assert ((CS_CALLEE_SUSPENDED == caller->state) || |
840 | (CS_BOTH_SUSPENDED == caller->state)); | 848 | (CS_BOTH_SUSPENDED == caller->state)); |
841 | caller->speaker = speaker; | 849 | caller->speaker = speaker; |
842 | caller->mic = mic; | 850 | caller->mic = mic; |
843 | e = GNUNET_MQ_msg(resume, | 851 | e = GNUNET_MQ_msg (resume, |
844 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 852 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
845 | resume->cid = caller->cid; | 853 | resume->cid = caller->cid; |
846 | GNUNET_MQ_send(phone->mq, | 854 | GNUNET_MQ_send (phone->mq, |
847 | e); | 855 | e); |
848 | if (CS_CALLEE_SUSPENDED == caller->state) | 856 | if (CS_CALLEE_SUSPENDED == caller->state) |
849 | { | 857 | { |
850 | caller->state = CS_ACTIVE; | 858 | caller->state = CS_ACTIVE; |
851 | caller->speaker->enable_speaker(caller->speaker->cls); | 859 | caller->speaker->enable_speaker (caller->speaker->cls); |
852 | caller->mic->enable_microphone(caller->mic->cls, | 860 | caller->mic->enable_microphone (caller->mic->cls, |
853 | &transmit_phone_audio, | 861 | &transmit_phone_audio, |
854 | caller); | 862 | caller); |
855 | } | 863 | } |
856 | else | 864 | else |
857 | { | 865 | { |
858 | caller->state = CS_CALLER_SUSPENDED; | 866 | caller->state = CS_CALLER_SUSPENDED; |
859 | } | 867 | } |
860 | } | 868 | } |
861 | 869 | ||
862 | /* end of conversation_api.c */ | 870 | /* end of conversation_api.c */ |
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c index 08fab57b4..2be7886fa 100644 --- a/src/conversation/conversation_api_call.c +++ b/src/conversation/conversation_api_call.c | |||
@@ -35,7 +35,8 @@ | |||
35 | /** | 35 | /** |
36 | * Possible states of the phone. | 36 | * Possible states of the phone. |
37 | */ | 37 | */ |
38 | enum CallState { | 38 | enum CallState |
39 | { | ||
39 | /** | 40 | /** |
40 | * We still need to lookup the callee. | 41 | * We still need to lookup the callee. |
41 | */ | 42 | */ |
@@ -76,7 +77,8 @@ enum CallState { | |||
76 | /** | 77 | /** |
77 | * Handle for an outgoing call. | 78 | * Handle for an outgoing call. |
78 | */ | 79 | */ |
79 | struct GNUNET_CONVERSATION_Call { | 80 | struct GNUNET_CONVERSATION_Call |
81 | { | ||
80 | /** | 82 | /** |
81 | * Our configuration. | 83 | * Our configuration. |
82 | */ | 84 | */ |
@@ -145,7 +147,7 @@ struct GNUNET_CONVERSATION_Call { | |||
145 | * @param call call to reconnect | 147 | * @param call call to reconnect |
146 | */ | 148 | */ |
147 | static void | 149 | static void |
148 | fail_call(struct GNUNET_CONVERSATION_Call *call); | 150 | fail_call (struct GNUNET_CONVERSATION_Call *call); |
149 | 151 | ||
150 | 152 | ||
151 | /** | 153 | /** |
@@ -156,23 +158,23 @@ fail_call(struct GNUNET_CONVERSATION_Call *call); | |||
156 | * @param data audio data to play | 158 | * @param data audio data to play |
157 | */ | 159 | */ |
158 | static void | 160 | static void |
159 | transmit_call_audio(void *cls, | 161 | transmit_call_audio (void *cls, |
160 | size_t data_size, | 162 | size_t data_size, |
161 | const void *data) | 163 | const void *data) |
162 | { | 164 | { |
163 | struct GNUNET_CONVERSATION_Call *call = cls; | 165 | struct GNUNET_CONVERSATION_Call *call = cls; |
164 | struct GNUNET_MQ_Envelope *e; | 166 | struct GNUNET_MQ_Envelope *e; |
165 | struct ClientAudioMessage *am; | 167 | struct ClientAudioMessage *am; |
166 | 168 | ||
167 | GNUNET_assert(CS_ACTIVE == call->state); | 169 | GNUNET_assert (CS_ACTIVE == call->state); |
168 | e = GNUNET_MQ_msg_extra(am, | 170 | e = GNUNET_MQ_msg_extra (am, |
169 | data_size, | 171 | data_size, |
170 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 172 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
171 | GNUNET_memcpy(&am[1], | 173 | GNUNET_memcpy (&am[1], |
172 | data, | 174 | data, |
173 | data_size); | 175 | data_size); |
174 | GNUNET_MQ_send(call->mq, | 176 | GNUNET_MQ_send (call->mq, |
175 | e); | 177 | e); |
176 | } | 178 | } |
177 | 179 | ||
178 | 180 | ||
@@ -183,47 +185,47 @@ transmit_call_audio(void *cls, | |||
183 | * @param msg the message | 185 | * @param msg the message |
184 | */ | 186 | */ |
185 | static void | 187 | static void |
186 | handle_call_suspend(void *cls, | 188 | handle_call_suspend (void *cls, |
187 | const struct ClientPhoneSuspendMessage *msg) | 189 | const struct ClientPhoneSuspendMessage *msg) |
188 | { | 190 | { |
189 | struct GNUNET_CONVERSATION_Call *call = cls; | 191 | struct GNUNET_CONVERSATION_Call *call = cls; |
190 | 192 | ||
191 | (void)msg; | 193 | (void) msg; |
192 | switch (call->state) | 194 | switch (call->state) |
193 | { | 195 | { |
194 | case CS_LOOKUP: | 196 | case CS_LOOKUP: |
195 | GNUNET_break(0); | 197 | GNUNET_break (0); |
196 | fail_call(call); | 198 | fail_call (call); |
197 | break; | 199 | break; |
198 | 200 | ||
199 | case CS_RINGING: | 201 | case CS_RINGING: |
200 | GNUNET_break_op(0); | 202 | GNUNET_break_op (0); |
201 | fail_call(call); | 203 | fail_call (call); |
202 | break; | 204 | break; |
203 | 205 | ||
204 | case CS_SUSPENDED_CALLER: | 206 | case CS_SUSPENDED_CALLER: |
205 | call->state = CS_SUSPENDED_BOTH; | 207 | call->state = CS_SUSPENDED_BOTH; |
206 | call->event_handler(call->event_handler_cls, | 208 | call->event_handler (call->event_handler_cls, |
207 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); | 209 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); |
208 | break; | 210 | break; |
209 | 211 | ||
210 | case CS_SUSPENDED_CALLEE: | 212 | case CS_SUSPENDED_CALLEE: |
211 | case CS_SUSPENDED_BOTH: | 213 | case CS_SUSPENDED_BOTH: |
212 | GNUNET_break_op(0); | 214 | GNUNET_break_op (0); |
213 | break; | 215 | break; |
214 | 216 | ||
215 | case CS_ACTIVE: | 217 | case CS_ACTIVE: |
216 | call->state = CS_SUSPENDED_CALLEE; | 218 | call->state = CS_SUSPENDED_CALLEE; |
217 | call->speaker->disable_speaker(call->speaker->cls); | 219 | call->speaker->disable_speaker (call->speaker->cls); |
218 | call->mic->disable_microphone(call->mic->cls); | 220 | call->mic->disable_microphone (call->mic->cls); |
219 | call->event_handler(call->event_handler_cls, | 221 | call->event_handler (call->event_handler_cls, |
220 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); | 222 | GNUNET_CONVERSATION_EC_CALL_SUSPENDED); |
221 | break; | 223 | break; |
222 | 224 | ||
223 | case CS_SHUTDOWN: | 225 | case CS_SHUTDOWN: |
224 | GNUNET_CONVERSATION_call_stop(call); | 226 | GNUNET_CONVERSATION_call_stop (call); |
225 | break; | 227 | break; |
226 | } | 228 | } |
227 | } | 229 | } |
228 | 230 | ||
229 | 231 | ||
@@ -234,52 +236,52 @@ handle_call_suspend(void *cls, | |||
234 | * @param msg the message | 236 | * @param msg the message |
235 | */ | 237 | */ |
236 | static void | 238 | static void |
237 | handle_call_resume(void *cls, | 239 | handle_call_resume (void *cls, |
238 | const struct ClientPhoneResumeMessage *msg) | 240 | const struct ClientPhoneResumeMessage *msg) |
239 | { | 241 | { |
240 | struct GNUNET_CONVERSATION_Call *call = cls; | 242 | struct GNUNET_CONVERSATION_Call *call = cls; |
241 | 243 | ||
242 | (void)msg; | 244 | (void) msg; |
243 | switch (call->state) | 245 | switch (call->state) |
244 | { | 246 | { |
245 | case CS_LOOKUP: | 247 | case CS_LOOKUP: |
246 | GNUNET_break(0); | 248 | GNUNET_break (0); |
247 | fail_call(call); | 249 | fail_call (call); |
248 | break; | 250 | break; |
249 | 251 | ||
250 | case CS_RINGING: | 252 | case CS_RINGING: |
251 | GNUNET_break_op(0); | 253 | GNUNET_break_op (0); |
252 | fail_call(call); | 254 | fail_call (call); |
253 | break; | 255 | break; |
254 | 256 | ||
255 | case CS_SUSPENDED_CALLER: | 257 | case CS_SUSPENDED_CALLER: |
256 | GNUNET_break_op(0); | 258 | GNUNET_break_op (0); |
257 | break; | 259 | break; |
258 | 260 | ||
259 | case CS_SUSPENDED_CALLEE: | 261 | case CS_SUSPENDED_CALLEE: |
260 | call->state = CS_ACTIVE; | 262 | call->state = CS_ACTIVE; |
261 | call->speaker->enable_speaker(call->speaker->cls); | 263 | call->speaker->enable_speaker (call->speaker->cls); |
262 | call->mic->enable_microphone(call->mic->cls, | 264 | call->mic->enable_microphone (call->mic->cls, |
263 | &transmit_call_audio, | 265 | &transmit_call_audio, |
264 | call); | 266 | call); |
265 | call->event_handler(call->event_handler_cls, | 267 | call->event_handler (call->event_handler_cls, |
266 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | 268 | GNUNET_CONVERSATION_EC_CALL_RESUMED); |
267 | break; | 269 | break; |
268 | 270 | ||
269 | case CS_SUSPENDED_BOTH: | 271 | case CS_SUSPENDED_BOTH: |
270 | call->state = CS_SUSPENDED_CALLER; | 272 | call->state = CS_SUSPENDED_CALLER; |
271 | call->event_handler(call->event_handler_cls, | 273 | call->event_handler (call->event_handler_cls, |
272 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | 274 | GNUNET_CONVERSATION_EC_CALL_RESUMED); |
273 | break; | 275 | break; |
274 | 276 | ||
275 | case CS_ACTIVE: | 277 | case CS_ACTIVE: |
276 | GNUNET_break_op(0); | 278 | GNUNET_break_op (0); |
277 | break; | 279 | break; |
278 | 280 | ||
279 | case CS_SHUTDOWN: | 281 | case CS_SHUTDOWN: |
280 | GNUNET_CONVERSATION_call_stop(call); | 282 | GNUNET_CONVERSATION_call_stop (call); |
281 | break; | 283 | break; |
282 | } | 284 | } |
283 | } | 285 | } |
284 | 286 | ||
285 | 287 | ||
@@ -290,41 +292,41 @@ handle_call_resume(void *cls, | |||
290 | * @param msg the message | 292 | * @param msg the message |
291 | */ | 293 | */ |
292 | static void | 294 | static void |
293 | handle_call_picked_up(void *cls, | 295 | handle_call_picked_up (void *cls, |
294 | const struct ClientPhonePickedupMessage *msg) | 296 | const struct ClientPhonePickedupMessage *msg) |
295 | { | 297 | { |
296 | struct GNUNET_CONVERSATION_Call *call = cls; | 298 | struct GNUNET_CONVERSATION_Call *call = cls; |
297 | 299 | ||
298 | (void)msg; | 300 | (void) msg; |
299 | switch (call->state) | 301 | switch (call->state) |
300 | { | 302 | { |
301 | case CS_LOOKUP: | 303 | case CS_LOOKUP: |
302 | GNUNET_break(0); | 304 | GNUNET_break (0); |
303 | fail_call(call); | 305 | fail_call (call); |
304 | break; | 306 | break; |
305 | 307 | ||
306 | case CS_RINGING: | 308 | case CS_RINGING: |
307 | call->state = CS_ACTIVE; | 309 | call->state = CS_ACTIVE; |
308 | call->speaker->enable_speaker(call->speaker->cls); | 310 | call->speaker->enable_speaker (call->speaker->cls); |
309 | call->mic->enable_microphone(call->mic->cls, | 311 | call->mic->enable_microphone (call->mic->cls, |
310 | &transmit_call_audio, | 312 | &transmit_call_audio, |
311 | call); | 313 | call); |
312 | call->event_handler(call->event_handler_cls, | 314 | call->event_handler (call->event_handler_cls, |
313 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); | 315 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); |
314 | break; | 316 | break; |
315 | 317 | ||
316 | case CS_SUSPENDED_CALLER: | 318 | case CS_SUSPENDED_CALLER: |
317 | case CS_SUSPENDED_CALLEE: | 319 | case CS_SUSPENDED_CALLEE: |
318 | case CS_SUSPENDED_BOTH: | 320 | case CS_SUSPENDED_BOTH: |
319 | case CS_ACTIVE: | 321 | case CS_ACTIVE: |
320 | GNUNET_break(0); | 322 | GNUNET_break (0); |
321 | fail_call(call); | 323 | fail_call (call); |
322 | break; | 324 | break; |
323 | 325 | ||
324 | case CS_SHUTDOWN: | 326 | case CS_SHUTDOWN: |
325 | GNUNET_CONVERSATION_call_stop(call); | 327 | GNUNET_CONVERSATION_call_stop (call); |
326 | break; | 328 | break; |
327 | } | 329 | } |
328 | } | 330 | } |
329 | 331 | ||
330 | 332 | ||
@@ -335,37 +337,37 @@ handle_call_picked_up(void *cls, | |||
335 | * @param msg the message | 337 | * @param msg the message |
336 | */ | 338 | */ |
337 | static void | 339 | static void |
338 | handle_call_hangup(void *cls, | 340 | handle_call_hangup (void *cls, |
339 | const struct ClientPhoneHangupMessage *msg) | 341 | const struct ClientPhoneHangupMessage *msg) |
340 | { | 342 | { |
341 | struct GNUNET_CONVERSATION_Call *call = cls; | 343 | struct GNUNET_CONVERSATION_Call *call = cls; |
342 | GNUNET_CONVERSATION_CallEventHandler eh; | 344 | GNUNET_CONVERSATION_CallEventHandler eh; |
343 | void *eh_cls; | 345 | void *eh_cls; |
344 | 346 | ||
345 | (void)msg; | 347 | (void) msg; |
346 | switch (call->state) | 348 | switch (call->state) |
347 | { | 349 | { |
348 | case CS_LOOKUP: | 350 | case CS_LOOKUP: |
349 | GNUNET_break(0); | 351 | GNUNET_break (0); |
350 | fail_call(call); | 352 | fail_call (call); |
351 | break; | 353 | break; |
352 | 354 | ||
353 | case CS_RINGING: | 355 | case CS_RINGING: |
354 | case CS_SUSPENDED_CALLER: | 356 | case CS_SUSPENDED_CALLER: |
355 | case CS_SUSPENDED_CALLEE: | 357 | case CS_SUSPENDED_CALLEE: |
356 | case CS_SUSPENDED_BOTH: | 358 | case CS_SUSPENDED_BOTH: |
357 | case CS_ACTIVE: | 359 | case CS_ACTIVE: |
358 | eh = call->event_handler; | 360 | eh = call->event_handler; |
359 | eh_cls = call->event_handler_cls; | 361 | eh_cls = call->event_handler_cls; |
360 | GNUNET_CONVERSATION_call_stop(call); | 362 | GNUNET_CONVERSATION_call_stop (call); |
361 | eh(eh_cls, | 363 | eh (eh_cls, |
362 | GNUNET_CONVERSATION_EC_CALL_HUNG_UP); | 364 | GNUNET_CONVERSATION_EC_CALL_HUNG_UP); |
363 | return; | 365 | return; |
364 | 366 | ||
365 | case CS_SHUTDOWN: | 367 | case CS_SHUTDOWN: |
366 | GNUNET_CONVERSATION_call_stop(call); | 368 | GNUNET_CONVERSATION_call_stop (call); |
367 | break; | 369 | break; |
368 | } | 370 | } |
369 | } | 371 | } |
370 | 372 | ||
371 | 373 | ||
@@ -377,11 +379,11 @@ handle_call_hangup(void *cls, | |||
377 | * @return #GNUNET_OK (always well-formed) | 379 | * @return #GNUNET_OK (always well-formed) |
378 | */ | 380 | */ |
379 | static int | 381 | static int |
380 | check_call_audio(void *cls, | 382 | check_call_audio (void *cls, |
381 | const struct ClientAudioMessage *am) | 383 | const struct ClientAudioMessage *am) |
382 | { | 384 | { |
383 | (void)cls; | 385 | (void) cls; |
384 | (void)am; | 386 | (void) am; |
385 | /* any payload is OK */ | 387 | /* any payload is OK */ |
386 | return GNUNET_OK; | 388 | return GNUNET_OK; |
387 | } | 389 | } |
@@ -394,44 +396,45 @@ check_call_audio(void *cls, | |||
394 | * @param msg the message | 396 | * @param msg the message |
395 | */ | 397 | */ |
396 | static void | 398 | static void |
397 | handle_call_audio(void *cls, | 399 | handle_call_audio (void *cls, |
398 | const struct ClientAudioMessage *am) | 400 | const struct ClientAudioMessage *am) |
399 | { | 401 | { |
400 | struct GNUNET_CONVERSATION_Call *call = cls; | 402 | struct GNUNET_CONVERSATION_Call *call = cls; |
401 | 403 | ||
402 | switch (call->state) | 404 | switch (call->state) |
403 | { | 405 | { |
404 | case CS_LOOKUP: | 406 | case CS_LOOKUP: |
405 | GNUNET_break(0); | 407 | GNUNET_break (0); |
406 | fail_call(call); | 408 | fail_call (call); |
407 | break; | 409 | break; |
408 | 410 | ||
409 | case CS_RINGING: | 411 | case CS_RINGING: |
410 | GNUNET_break(0); | 412 | GNUNET_break (0); |
411 | fail_call(call); | 413 | fail_call (call); |
412 | break; | 414 | break; |
413 | 415 | ||
414 | case CS_SUSPENDED_CALLER: | 416 | case CS_SUSPENDED_CALLER: |
415 | /* can happen: we suspended, other peer did not yet | 417 | /* can happen: we suspended, other peer did not yet |
416 | learn about this. */ | 418 | learn about this. */ |
417 | break; | 419 | break; |
418 | 420 | ||
419 | case CS_SUSPENDED_CALLEE: | 421 | case CS_SUSPENDED_CALLEE: |
420 | case CS_SUSPENDED_BOTH: | 422 | case CS_SUSPENDED_BOTH: |
421 | /* can (rarely) also happen: other peer suspended, but cadet might | 423 | /* can (rarely) also happen: other peer suspended, but cadet might |
422 | have had delayed data on the unreliable channel */ | 424 | have had delayed data on the unreliable channel */ |
423 | break; | 425 | break; |
424 | 426 | ||
425 | case CS_ACTIVE: | 427 | case CS_ACTIVE: |
426 | call->speaker->play(call->speaker->cls, | 428 | call->speaker->play (call->speaker->cls, |
427 | ntohs(am->header.size) - sizeof(struct ClientAudioMessage), | 429 | ntohs (am->header.size) - sizeof(struct |
428 | &am[1]); | 430 | ClientAudioMessage), |
429 | break; | 431 | &am[1]); |
430 | 432 | break; | |
431 | case CS_SHUTDOWN: | 433 | |
432 | GNUNET_CONVERSATION_call_stop(call); | 434 | case CS_SHUTDOWN: |
433 | break; | 435 | GNUNET_CONVERSATION_call_stop (call); |
434 | } | 436 | break; |
437 | } | ||
435 | } | 438 | } |
436 | 439 | ||
437 | 440 | ||
@@ -444,48 +447,48 @@ handle_call_audio(void *cls, | |||
444 | * @param rd the records in reply | 447 | * @param rd the records in reply |
445 | */ | 448 | */ |
446 | static void | 449 | static void |
447 | handle_gns_response(void *cls, | 450 | handle_gns_response (void *cls, |
448 | int was_gns, | 451 | int was_gns, |
449 | uint32_t rd_count, | 452 | uint32_t rd_count, |
450 | const struct GNUNET_GNSRECORD_Data *rd) | 453 | const struct GNUNET_GNSRECORD_Data *rd) |
451 | { | 454 | { |
452 | struct GNUNET_CONVERSATION_Call *call = cls; | 455 | struct GNUNET_CONVERSATION_Call *call = cls; |
453 | struct GNUNET_MQ_Envelope *e; | 456 | struct GNUNET_MQ_Envelope *e; |
454 | struct ClientCallMessage *ccm; | 457 | struct ClientCallMessage *ccm; |
455 | 458 | ||
456 | (void)was_gns; | 459 | (void) was_gns; |
457 | GNUNET_break(NULL != call->gns_lookup); | 460 | GNUNET_break (NULL != call->gns_lookup); |
458 | GNUNET_break(CS_LOOKUP == call->state); | 461 | GNUNET_break (CS_LOOKUP == call->state); |
459 | call->gns_lookup = NULL; | 462 | call->gns_lookup = NULL; |
460 | for (uint32_t i = 0; i < rd_count; i++) | 463 | for (uint32_t i = 0; i < rd_count; i++) |
464 | { | ||
465 | if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type) | ||
461 | { | 466 | { |
462 | if (GNUNET_GNSRECORD_TYPE_PHONE == rd[i].record_type) | 467 | if (rd[i].data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord)) |
463 | { | 468 | { |
464 | if (rd[i].data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord)) | 469 | GNUNET_break_op (0); |
465 | { | 470 | continue; |
466 | GNUNET_break_op(0); | 471 | } |
467 | continue; | 472 | GNUNET_memcpy (&call->phone_record, |
468 | } | 473 | rd[i].data, |
469 | GNUNET_memcpy(&call->phone_record, | 474 | rd[i].data_size); |
470 | rd[i].data, | 475 | e = GNUNET_MQ_msg (ccm, |
471 | rd[i].data_size); | 476 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); |
472 | e = GNUNET_MQ_msg(ccm, | 477 | ccm->line_port = call->phone_record.line_port; |
473 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL); | 478 | ccm->target = call->phone_record.peer; |
474 | ccm->line_port = call->phone_record.line_port; | 479 | ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key (call->caller_id); |
475 | ccm->target = call->phone_record.peer; | 480 | GNUNET_MQ_send (call->mq, |
476 | ccm->caller_id = *GNUNET_IDENTITY_ego_get_private_key(call->caller_id); | 481 | e); |
477 | GNUNET_MQ_send(call->mq, | 482 | call->state = CS_RINGING; |
478 | e); | 483 | call->event_handler (call->event_handler_cls, |
479 | call->state = CS_RINGING; | 484 | GNUNET_CONVERSATION_EC_CALL_RINGING); |
480 | call->event_handler(call->event_handler_cls, | 485 | return; |
481 | GNUNET_CONVERSATION_EC_CALL_RINGING); | ||
482 | return; | ||
483 | } | ||
484 | } | 486 | } |
487 | } | ||
485 | /* not found */ | 488 | /* not found */ |
486 | call->event_handler(call->event_handler_cls, | 489 | call->event_handler (call->event_handler_cls, |
487 | GNUNET_CONVERSATION_EC_CALL_GNS_FAIL); | 490 | GNUNET_CONVERSATION_EC_CALL_GNS_FAIL); |
488 | GNUNET_CONVERSATION_call_stop(call); | 491 | GNUNET_CONVERSATION_call_stop (call); |
489 | } | 492 | } |
490 | 493 | ||
491 | 494 | ||
@@ -496,20 +499,21 @@ handle_gns_response(void *cls, | |||
496 | * @param error details about the error | 499 | * @param error details about the error |
497 | */ | 500 | */ |
498 | static void | 501 | static void |
499 | call_error_handler(void *cls, | 502 | call_error_handler (void *cls, |
500 | enum GNUNET_MQ_Error error) | 503 | enum GNUNET_MQ_Error error) |
501 | { | 504 | { |
502 | struct GNUNET_CONVERSATION_Call *call = cls; | 505 | struct GNUNET_CONVERSATION_Call *call = cls; |
503 | 506 | ||
504 | (void)error; | 507 | (void) error; |
505 | if (CS_SHUTDOWN == call->state) | 508 | if (CS_SHUTDOWN == call->state) |
506 | { | 509 | { |
507 | GNUNET_CONVERSATION_call_stop(call); | 510 | GNUNET_CONVERSATION_call_stop (call); |
508 | return; | 511 | return; |
509 | } | 512 | } |
510 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 513 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
511 | _("Connection to conversation service lost, trying to reconnect\n")); | 514 | _ ( |
512 | fail_call(call); | 515 | "Connection to conversation service lost, trying to reconnect\n")); |
516 | fail_call (call); | ||
513 | } | 517 | } |
514 | 518 | ||
515 | 519 | ||
@@ -519,22 +523,22 @@ call_error_handler(void *cls, | |||
519 | * @param call call to reconnect | 523 | * @param call call to reconnect |
520 | */ | 524 | */ |
521 | static void | 525 | static void |
522 | fail_call(struct GNUNET_CONVERSATION_Call *call) | 526 | fail_call (struct GNUNET_CONVERSATION_Call *call) |
523 | { | 527 | { |
524 | if (CS_ACTIVE == call->state) | 528 | if (CS_ACTIVE == call->state) |
525 | { | 529 | { |
526 | call->speaker->disable_speaker(call->speaker->cls); | 530 | call->speaker->disable_speaker (call->speaker->cls); |
527 | call->mic->disable_microphone(call->mic->cls); | 531 | call->mic->disable_microphone (call->mic->cls); |
528 | } | 532 | } |
529 | if (NULL != call->mq) | 533 | if (NULL != call->mq) |
530 | { | 534 | { |
531 | GNUNET_MQ_destroy(call->mq); | 535 | GNUNET_MQ_destroy (call->mq); |
532 | call->mq = NULL; | 536 | call->mq = NULL; |
533 | } | 537 | } |
534 | call->state = CS_SHUTDOWN; | 538 | call->state = CS_SHUTDOWN; |
535 | call->event_handler(call->event_handler_cls, | 539 | call->event_handler (call->event_handler_cls, |
536 | GNUNET_CONVERSATION_EC_CALL_ERROR); | 540 | GNUNET_CONVERSATION_EC_CALL_ERROR); |
537 | GNUNET_CONVERSATION_call_stop(call); | 541 | GNUNET_CONVERSATION_call_stop (call); |
538 | } | 542 | } |
539 | 543 | ||
540 | 544 | ||
@@ -554,76 +558,77 @@ fail_call(struct GNUNET_CONVERSATION_Call *call) | |||
554 | * @return handle for the call, NULL on hard errors | 558 | * @return handle for the call, NULL on hard errors |
555 | */ | 559 | */ |
556 | struct GNUNET_CONVERSATION_Call * | 560 | struct GNUNET_CONVERSATION_Call * |
557 | GNUNET_CONVERSATION_call_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | 561 | GNUNET_CONVERSATION_call_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
558 | struct GNUNET_IDENTITY_Ego *caller_id, | 562 | struct GNUNET_IDENTITY_Ego *caller_id, |
559 | const char *callee, | 563 | const char *callee, |
560 | struct GNUNET_SPEAKER_Handle *speaker, | 564 | struct GNUNET_SPEAKER_Handle *speaker, |
561 | struct GNUNET_MICROPHONE_Handle *mic, | 565 | struct GNUNET_MICROPHONE_Handle *mic, |
562 | GNUNET_CONVERSATION_CallEventHandler event_handler, | 566 | GNUNET_CONVERSATION_CallEventHandler |
563 | void *event_handler_cls) | 567 | event_handler, |
568 | void *event_handler_cls) | ||
564 | { | 569 | { |
565 | struct GNUNET_CONVERSATION_Call *call | 570 | struct GNUNET_CONVERSATION_Call *call |
566 | = GNUNET_new(struct GNUNET_CONVERSATION_Call); | 571 | = GNUNET_new (struct GNUNET_CONVERSATION_Call); |
567 | struct GNUNET_MQ_MessageHandler handlers[] = { | 572 | struct GNUNET_MQ_MessageHandler handlers[] = { |
568 | GNUNET_MQ_hd_fixed_size(call_suspend, | 573 | GNUNET_MQ_hd_fixed_size (call_suspend, |
569 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 574 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
570 | struct ClientPhoneSuspendMessage, | 575 | struct ClientPhoneSuspendMessage, |
571 | call), | 576 | call), |
572 | GNUNET_MQ_hd_fixed_size(call_resume, | 577 | GNUNET_MQ_hd_fixed_size (call_resume, |
573 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 578 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
574 | struct ClientPhoneResumeMessage, | 579 | struct ClientPhoneResumeMessage, |
575 | call), | 580 | call), |
576 | GNUNET_MQ_hd_fixed_size(call_picked_up, | 581 | GNUNET_MQ_hd_fixed_size (call_picked_up, |
577 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, | 582 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP, |
578 | struct ClientPhonePickedupMessage, | 583 | struct ClientPhonePickedupMessage, |
579 | call), | 584 | call), |
580 | GNUNET_MQ_hd_fixed_size(call_hangup, | 585 | GNUNET_MQ_hd_fixed_size (call_hangup, |
581 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 586 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
582 | struct ClientPhoneHangupMessage, | 587 | struct ClientPhoneHangupMessage, |
583 | call), | 588 | call), |
584 | GNUNET_MQ_hd_var_size(call_audio, | 589 | GNUNET_MQ_hd_var_size (call_audio, |
585 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 590 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
586 | struct ClientAudioMessage, | 591 | struct ClientAudioMessage, |
587 | call), | 592 | call), |
588 | GNUNET_MQ_handler_end() | 593 | GNUNET_MQ_handler_end () |
589 | }; | 594 | }; |
590 | 595 | ||
591 | call->mq = GNUNET_CLIENT_connect(cfg, | 596 | call->mq = GNUNET_CLIENT_connect (cfg, |
592 | "conversation", | 597 | "conversation", |
593 | handlers, | 598 | handlers, |
594 | &call_error_handler, | 599 | &call_error_handler, |
595 | call); | 600 | call); |
596 | if (NULL == call->mq) | 601 | if (NULL == call->mq) |
597 | { | 602 | { |
598 | GNUNET_break(0); | 603 | GNUNET_break (0); |
599 | GNUNET_free(call); | 604 | GNUNET_free (call); |
600 | return NULL; | 605 | return NULL; |
601 | } | 606 | } |
602 | call->cfg = cfg; | 607 | call->cfg = cfg; |
603 | call->caller_id = caller_id; | 608 | call->caller_id = caller_id; |
604 | call->callee = GNUNET_strdup(callee); | 609 | call->callee = GNUNET_strdup (callee); |
605 | call->speaker = speaker; | 610 | call->speaker = speaker; |
606 | call->mic = mic; | 611 | call->mic = mic; |
607 | call->event_handler = event_handler; | 612 | call->event_handler = event_handler; |
608 | call->event_handler_cls = event_handler_cls; | 613 | call->event_handler_cls = event_handler_cls; |
609 | call->gns = GNUNET_GNS_connect(cfg); | 614 | call->gns = GNUNET_GNS_connect (cfg); |
610 | if (NULL == call->gns) | 615 | if (NULL == call->gns) |
611 | { | 616 | { |
612 | GNUNET_CONVERSATION_call_stop(call); | 617 | GNUNET_CONVERSATION_call_stop (call); |
613 | return NULL; | 618 | return NULL; |
614 | } | 619 | } |
615 | call->state = CS_LOOKUP; | 620 | call->state = CS_LOOKUP; |
616 | call->gns_lookup = GNUNET_GNS_lookup_with_tld(call->gns, | 621 | call->gns_lookup = GNUNET_GNS_lookup_with_tld (call->gns, |
617 | call->callee, | 622 | call->callee, |
618 | GNUNET_GNSRECORD_TYPE_PHONE, | 623 | GNUNET_GNSRECORD_TYPE_PHONE, |
619 | GNUNET_NO, | 624 | GNUNET_NO, |
620 | &handle_gns_response, | 625 | &handle_gns_response, |
621 | call); | 626 | call); |
622 | if (NULL == call->gns_lookup) | 627 | if (NULL == call->gns_lookup) |
623 | { | 628 | { |
624 | GNUNET_CONVERSATION_call_stop(call); | 629 | GNUNET_CONVERSATION_call_stop (call); |
625 | return NULL; | 630 | return NULL; |
626 | } | 631 | } |
627 | return call; | 632 | return call; |
628 | } | 633 | } |
629 | 634 | ||
@@ -634,35 +639,35 @@ GNUNET_CONVERSATION_call_start(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
634 | * @param call call to terminate | 639 | * @param call call to terminate |
635 | */ | 640 | */ |
636 | void | 641 | void |
637 | GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call) | 642 | GNUNET_CONVERSATION_call_stop (struct GNUNET_CONVERSATION_Call *call) |
638 | { | 643 | { |
639 | if ((NULL != call->speaker) && | 644 | if ((NULL != call->speaker) && |
640 | (CS_ACTIVE == call->state)) | 645 | (CS_ACTIVE == call->state)) |
641 | call->speaker->disable_speaker(call->speaker->cls); | 646 | call->speaker->disable_speaker (call->speaker->cls); |
642 | if ((NULL != call->mic) && | 647 | if ((NULL != call->mic) && |
643 | (CS_ACTIVE == call->state)) | 648 | (CS_ACTIVE == call->state)) |
644 | call->mic->disable_microphone(call->mic->cls); | 649 | call->mic->disable_microphone (call->mic->cls); |
645 | if (CS_SHUTDOWN != call->state) | 650 | if (CS_SHUTDOWN != call->state) |
646 | { | 651 | { |
647 | call->state = CS_SHUTDOWN; | 652 | call->state = CS_SHUTDOWN; |
648 | } | 653 | } |
649 | if (NULL != call->mq) | 654 | if (NULL != call->mq) |
650 | { | 655 | { |
651 | GNUNET_MQ_destroy(call->mq); | 656 | GNUNET_MQ_destroy (call->mq); |
652 | call->mq = NULL; | 657 | call->mq = NULL; |
653 | } | 658 | } |
654 | if (NULL != call->gns_lookup) | 659 | if (NULL != call->gns_lookup) |
655 | { | 660 | { |
656 | GNUNET_GNS_lookup_with_tld_cancel(call->gns_lookup); | 661 | GNUNET_GNS_lookup_with_tld_cancel (call->gns_lookup); |
657 | call->gns_lookup = NULL; | 662 | call->gns_lookup = NULL; |
658 | } | 663 | } |
659 | if (NULL != call->gns) | 664 | if (NULL != call->gns) |
660 | { | 665 | { |
661 | GNUNET_GNS_disconnect(call->gns); | 666 | GNUNET_GNS_disconnect (call->gns); |
662 | call->gns = NULL; | 667 | call->gns = NULL; |
663 | } | 668 | } |
664 | GNUNET_free(call->callee); | 669 | GNUNET_free (call->callee); |
665 | GNUNET_free(call); | 670 | GNUNET_free (call); |
666 | } | 671 | } |
667 | 672 | ||
668 | 673 | ||
@@ -673,24 +678,24 @@ GNUNET_CONVERSATION_call_stop(struct GNUNET_CONVERSATION_Call *call) | |||
673 | * @param call call to pause | 678 | * @param call call to pause |
674 | */ | 679 | */ |
675 | void | 680 | void |
676 | GNUNET_CONVERSATION_call_suspend(struct GNUNET_CONVERSATION_Call *call) | 681 | GNUNET_CONVERSATION_call_suspend (struct GNUNET_CONVERSATION_Call *call) |
677 | { | 682 | { |
678 | struct GNUNET_MQ_Envelope *e; | 683 | struct GNUNET_MQ_Envelope *e; |
679 | struct ClientPhoneSuspendMessage *suspend; | 684 | struct ClientPhoneSuspendMessage *suspend; |
680 | 685 | ||
681 | GNUNET_assert((CS_SUSPENDED_CALLEE == call->state) || | 686 | GNUNET_assert ((CS_SUSPENDED_CALLEE == call->state) || |
682 | (CS_ACTIVE == call->state)); | 687 | (CS_ACTIVE == call->state)); |
683 | if (CS_ACTIVE == call->state) | 688 | if (CS_ACTIVE == call->state) |
684 | { | 689 | { |
685 | call->speaker->disable_speaker(call->speaker->cls); | 690 | call->speaker->disable_speaker (call->speaker->cls); |
686 | call->mic->disable_microphone(call->mic->cls); | 691 | call->mic->disable_microphone (call->mic->cls); |
687 | } | 692 | } |
688 | call->speaker = NULL; | 693 | call->speaker = NULL; |
689 | call->mic = NULL; | 694 | call->mic = NULL; |
690 | e = GNUNET_MQ_msg(suspend, | 695 | e = GNUNET_MQ_msg (suspend, |
691 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 696 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
692 | GNUNET_MQ_send(call->mq, | 697 | GNUNET_MQ_send (call->mq, |
693 | e); | 698 | e); |
694 | if (CS_SUSPENDED_CALLER == call->state) | 699 | if (CS_SUSPENDED_CALLER == call->state) |
695 | call->state = CS_SUSPENDED_BOTH; | 700 | call->state = CS_SUSPENDED_BOTH; |
696 | else | 701 | else |
@@ -707,31 +712,31 @@ GNUNET_CONVERSATION_call_suspend(struct GNUNET_CONVERSATION_Call *call) | |||
707 | * @param mic microphone to use | 712 | * @param mic microphone to use |
708 | */ | 713 | */ |
709 | void | 714 | void |
710 | GNUNET_CONVERSATION_call_resume(struct GNUNET_CONVERSATION_Call *call, | 715 | GNUNET_CONVERSATION_call_resume (struct GNUNET_CONVERSATION_Call *call, |
711 | struct GNUNET_SPEAKER_Handle *speaker, | 716 | struct GNUNET_SPEAKER_Handle *speaker, |
712 | struct GNUNET_MICROPHONE_Handle *mic) | 717 | struct GNUNET_MICROPHONE_Handle *mic) |
713 | { | 718 | { |
714 | struct GNUNET_MQ_Envelope *e; | 719 | struct GNUNET_MQ_Envelope *e; |
715 | struct ClientPhoneResumeMessage *resume; | 720 | struct ClientPhoneResumeMessage *resume; |
716 | 721 | ||
717 | GNUNET_assert((CS_SUSPENDED_CALLER == call->state) || | 722 | GNUNET_assert ((CS_SUSPENDED_CALLER == call->state) || |
718 | (CS_SUSPENDED_BOTH == call->state)); | 723 | (CS_SUSPENDED_BOTH == call->state)); |
719 | e = GNUNET_MQ_msg(resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 724 | e = GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
720 | GNUNET_MQ_send(call->mq, e); | 725 | GNUNET_MQ_send (call->mq, e); |
721 | call->speaker = speaker; | 726 | call->speaker = speaker; |
722 | call->mic = mic; | 727 | call->mic = mic; |
723 | if (CS_SUSPENDED_CALLER == call->state) | 728 | if (CS_SUSPENDED_CALLER == call->state) |
724 | { | 729 | { |
725 | call->state = CS_ACTIVE; | 730 | call->state = CS_ACTIVE; |
726 | call->speaker->enable_speaker(call->speaker->cls); | 731 | call->speaker->enable_speaker (call->speaker->cls); |
727 | call->mic->enable_microphone(call->mic->cls, | 732 | call->mic->enable_microphone (call->mic->cls, |
728 | &transmit_call_audio, | 733 | &transmit_call_audio, |
729 | call); | 734 | call); |
730 | } | 735 | } |
731 | else | 736 | else |
732 | { | 737 | { |
733 | call->state = CS_SUSPENDED_CALLEE; | 738 | call->state = CS_SUSPENDED_CALLEE; |
734 | } | 739 | } |
735 | } | 740 | } |
736 | 741 | ||
737 | 742 | ||
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c index 871058233..c03723fc3 100644 --- a/src/conversation/gnunet-conversation-test.c +++ b/src/conversation/gnunet-conversation-test.c | |||
@@ -31,13 +31,14 @@ | |||
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 | { | ||
41 | /** | 42 | /** |
42 | * Kept in a DLL. | 43 | * Kept in a DLL. |
43 | */ | 44 | */ |
@@ -73,12 +74,12 @@ static struct GNUNET_SPEAKER_Handle *speaker; | |||
73 | /** | 74 | /** |
74 | * Task scheduled to switch from recording to playback. | 75 | * Task scheduled to switch from recording to playback. |
75 | */ | 76 | */ |
76 | static struct GNUNET_SCHEDULER_Task * switch_task; | 77 | static struct GNUNET_SCHEDULER_Task *switch_task; |
77 | 78 | ||
78 | /** | 79 | /** |
79 | * The shutdown task. | 80 | * The shutdown task. |
80 | */ | 81 | */ |
81 | static struct GNUNET_SCHEDULER_Task * st; | 82 | static struct GNUNET_SCHEDULER_Task *st; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Head of DLL with recorded frames. | 85 | * Head of DLL with recorded frames. |
@@ -97,26 +98,26 @@ static struct Recording *rec_tail; | |||
97 | * @param cls NULL | 98 | * @param cls NULL |
98 | */ | 99 | */ |
99 | static void | 100 | static void |
100 | do_shutdown(void *cls) | 101 | do_shutdown (void *cls) |
101 | { | 102 | { |
102 | struct Recording *rec; | 103 | struct Recording *rec; |
103 | 104 | ||
104 | (void)cls; | 105 | (void) cls; |
105 | if (NULL != switch_task) | 106 | if (NULL != switch_task) |
106 | GNUNET_SCHEDULER_cancel(switch_task); | 107 | GNUNET_SCHEDULER_cancel (switch_task); |
107 | if (NULL != microphone) | 108 | if (NULL != microphone) |
108 | GNUNET_MICROPHONE_destroy(microphone); | 109 | GNUNET_MICROPHONE_destroy (microphone); |
109 | if (NULL != speaker) | 110 | if (NULL != speaker) |
110 | GNUNET_SPEAKER_destroy(speaker); | 111 | GNUNET_SPEAKER_destroy (speaker); |
111 | while (NULL != (rec = rec_head)) | 112 | while (NULL != (rec = rec_head)) |
112 | { | 113 | { |
113 | GNUNET_CONTAINER_DLL_remove(rec_head, | 114 | GNUNET_CONTAINER_DLL_remove (rec_head, |
114 | rec_tail, | 115 | rec_tail, |
115 | rec); | 116 | rec); |
116 | GNUNET_free(rec); | 117 | GNUNET_free (rec); |
117 | } | 118 | } |
118 | fprintf(stderr, | 119 | fprintf (stderr, |
119 | _("\nEnd of transmission. Have a GNU day.\n")); | 120 | _ ("\nEnd of transmission. Have a GNU day.\n")); |
120 | } | 121 | } |
121 | 122 | ||
122 | 123 | ||
@@ -126,35 +127,36 @@ do_shutdown(void *cls) | |||
126 | * @param cls NULL | 127 | * @param cls NULL |
127 | */ | 128 | */ |
128 | static void | 129 | static void |
129 | switch_to_speaker(void *cls) | 130 | switch_to_speaker (void *cls) |
130 | { | 131 | { |
131 | (void)cls; | 132 | (void) cls; |
132 | switch_task = NULL; | 133 | switch_task = NULL; |
133 | microphone->disable_microphone(microphone->cls); | 134 | microphone->disable_microphone (microphone->cls); |
134 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
135 | speaker->enable_speaker(speaker->cls)) | 136 | speaker->enable_speaker (speaker->cls)) |
136 | { | 137 | { |
137 | fprintf(stderr, | 138 | fprintf (stderr, |
138 | "Failed to enable microphone\n"); | 139 | "Failed to enable microphone\n"); |
139 | ret = 1; | 140 | ret = 1; |
140 | GNUNET_SCHEDULER_shutdown(); | 141 | GNUNET_SCHEDULER_shutdown (); |
141 | return; | 142 | return; |
142 | } | 143 | } |
143 | fprintf(stderr, | 144 | fprintf (stderr, |
144 | _("\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); | 145 | _ ( |
146 | "\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); | ||
145 | for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next) | 147 | for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next) |
146 | { | 148 | { |
147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
148 | "Replaying %u bytes\n", | 150 | "Replaying %u bytes\n", |
149 | (unsigned int)rec->size); | 151 | (unsigned int) rec->size); |
150 | speaker->play(speaker->cls, | 152 | speaker->play (speaker->cls, |
151 | rec->size, | 153 | rec->size, |
152 | &rec[1]); | 154 | &rec[1]); |
153 | } | 155 | } |
154 | GNUNET_SCHEDULER_cancel(st); | 156 | GNUNET_SCHEDULER_cancel (st); |
155 | st = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 157 | st = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
156 | &do_shutdown, | 158 | &do_shutdown, |
157 | NULL); | 159 | NULL); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
@@ -166,22 +168,22 @@ switch_to_speaker(void *cls) | |||
166 | * @param data audio data to play | 168 | * @param data audio data to play |
167 | */ | 169 | */ |
168 | static void | 170 | static void |
169 | record(void *cls, | 171 | record (void *cls, |
170 | size_t data_size, | 172 | size_t data_size, |
171 | const void *data) | 173 | const void *data) |
172 | { | 174 | { |
173 | struct Recording *rec; | 175 | struct Recording *rec; |
174 | 176 | ||
175 | (void)cls; | 177 | (void) cls; |
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Recorded %u bytes\n", | 179 | "Recorded %u bytes\n", |
178 | (unsigned int)data_size); | 180 | (unsigned int) data_size); |
179 | rec = GNUNET_malloc(sizeof(struct Recording) + data_size); | 181 | rec = GNUNET_malloc (sizeof(struct Recording) + data_size); |
180 | rec->size = data_size; | 182 | rec->size = data_size; |
181 | GNUNET_memcpy(&rec[1], data, data_size); | 183 | GNUNET_memcpy (&rec[1], data, data_size); |
182 | GNUNET_CONTAINER_DLL_insert_tail(rec_head, | 184 | GNUNET_CONTAINER_DLL_insert_tail (rec_head, |
183 | rec_tail, | 185 | rec_tail, |
184 | rec); | 186 | rec); |
185 | } | 187 | } |
186 | 188 | ||
187 | 189 | ||
@@ -194,36 +196,37 @@ record(void *cls, | |||
194 | * @param cfg configuration | 196 | * @param cfg configuration |
195 | */ | 197 | */ |
196 | static void | 198 | static void |
197 | run(void *cls, | 199 | run (void *cls, |
198 | char *const *args, | 200 | char *const *args, |
199 | const char *cfgfile, | 201 | const char *cfgfile, |
200 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 202 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
201 | { | 203 | { |
202 | (void)cls; | 204 | (void) cls; |
203 | (void)args; | 205 | (void) args; |
204 | (void)cfgfile; | 206 | (void) cfgfile; |
205 | microphone = GNUNET_MICROPHONE_create_from_hardware(cfg); | 207 | microphone = GNUNET_MICROPHONE_create_from_hardware (cfg); |
206 | GNUNET_assert(NULL != microphone); | 208 | GNUNET_assert (NULL != microphone); |
207 | speaker = GNUNET_SPEAKER_create_from_hardware(cfg); | 209 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); |
208 | GNUNET_assert(NULL != speaker); | 210 | GNUNET_assert (NULL != speaker); |
209 | switch_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 211 | switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
210 | &switch_to_speaker, | 212 | &switch_to_speaker, |
211 | NULL); | 213 | NULL); |
212 | st = GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 214 | st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
213 | NULL); | 215 | NULL); |
214 | fprintf(stderr, | 216 | fprintf (stderr, |
215 | _("We will now be recording you for %s. After that time, the recording will be played back to you..."), | 217 | _ ( |
216 | GNUNET_STRINGS_relative_time_to_string(TIMEOUT, GNUNET_YES)); | 218 | "We will now be recording you for %s. After that time, the recording will be played back to you..."), |
219 | GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES)); | ||
217 | if (GNUNET_OK != | 220 | if (GNUNET_OK != |
218 | microphone->enable_microphone(microphone->cls, | 221 | microphone->enable_microphone (microphone->cls, |
219 | &record, NULL)) | 222 | &record, NULL)) |
220 | { | 223 | { |
221 | fprintf(stderr, | 224 | fprintf (stderr, |
222 | "Failed to enable microphone\n"); | 225 | "Failed to enable microphone\n"); |
223 | ret = 1; | 226 | ret = 1; |
224 | GNUNET_SCHEDULER_shutdown(); | 227 | GNUNET_SCHEDULER_shutdown (); |
225 | return; | 228 | return; |
226 | } | 229 | } |
227 | } | 230 | } |
228 | 231 | ||
229 | 232 | ||
@@ -235,26 +238,26 @@ run(void *cls, | |||
235 | * @return 0 ok, 1 on error | 238 | * @return 0 ok, 1 on error |
236 | */ | 239 | */ |
237 | int | 240 | int |
238 | main(int argc, | 241 | main (int argc, |
239 | char *const *argv) | 242 | char *const *argv) |
240 | { | 243 | { |
241 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 244 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | GNUNET_GETOPT_OPTION_END | 245 | GNUNET_GETOPT_OPTION_END |
243 | }; | 246 | }; |
244 | 247 | ||
245 | if (GNUNET_OK != | 248 | if (GNUNET_OK != |
246 | GNUNET_STRINGS_get_utf8_args(argc, argv, | 249 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
247 | &argc, &argv)) | 250 | &argc, &argv)) |
248 | return 2; | 251 | return 2; |
249 | 252 | ||
250 | ret = (GNUNET_OK == | 253 | ret = (GNUNET_OK == |
251 | GNUNET_PROGRAM_run(argc, argv, | 254 | GNUNET_PROGRAM_run (argc, argv, |
252 | "gnunet-conversation-test", | 255 | "gnunet-conversation-test", |
253 | gettext_noop("help text"), | 256 | gettext_noop ("help text"), |
254 | options, | 257 | options, |
255 | &run, | 258 | &run, |
256 | NULL)) ? ret : 1; | 259 | NULL)) ? ret : 1; |
257 | GNUNET_free((void*)argv); | 260 | GNUNET_free ((void*) argv); |
258 | return ret; | 261 | return ret; |
259 | } | 262 | } |
260 | 263 | ||
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index bf044a4f8..0b04ba38e 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c | |||
@@ -35,14 +35,15 @@ | |||
35 | */ | 35 | */ |
36 | #define MAX_MESSAGE_LENGTH 1024 | 36 | #define MAX_MESSAGE_LENGTH 1024 |
37 | 37 | ||
38 | #define XSTRINGIFY(x) STRINGIFY(x) | 38 | #define XSTRINGIFY(x) STRINGIFY (x) |
39 | 39 | ||
40 | #define STRINGIFY(x) (#x) | 40 | #define STRINGIFY(x) (#x) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Possible states of the phone. | 43 | * Possible states of the phone. |
44 | */ | 44 | */ |
45 | enum PhoneState { | 45 | enum PhoneState |
46 | { | ||
46 | /** | 47 | /** |
47 | * We're waiting for our own idenitty. | 48 | * We're waiting for our own idenitty. |
48 | */ | 49 | */ |
@@ -68,7 +69,8 @@ enum PhoneState { | |||
68 | /** | 69 | /** |
69 | * States for current outgoing call. | 70 | * States for current outgoing call. |
70 | */ | 71 | */ |
71 | enum CallState { | 72 | enum CallState |
73 | { | ||
72 | /** | 74 | /** |
73 | * We are looking up some other participant. | 75 | * We are looking up some other participant. |
74 | */ | 76 | */ |
@@ -94,7 +96,8 @@ enum CallState { | |||
94 | /** | 96 | /** |
95 | * List of incoming calls | 97 | * List of incoming calls |
96 | */ | 98 | */ |
97 | struct CallList { | 99 | struct CallList |
100 | { | ||
98 | /** | 101 | /** |
99 | * A DLL. | 102 | * A DLL. |
100 | */ | 103 | */ |
@@ -238,64 +241,64 @@ static int verbose; | |||
238 | * @param caller_id public key of the caller (in GNS) | 241 | * @param caller_id public key of the caller (in GNS) |
239 | */ | 242 | */ |
240 | static void | 243 | static void |
241 | phone_event_handler(void *cls, | 244 | phone_event_handler (void *cls, |
242 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 245 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
243 | struct GNUNET_CONVERSATION_Caller *caller, | 246 | struct GNUNET_CONVERSATION_Caller *caller, |
244 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 247 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
245 | { | 248 | { |
246 | struct CallList *cl; | 249 | struct CallList *cl; |
247 | 250 | ||
248 | (void)cls; | 251 | (void) cls; |
249 | switch (code) | 252 | switch (code) |
253 | { | ||
254 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
255 | /* | ||
256 | * FIXME: we should be playing our ringtones from contrib/sounds now! | ||
257 | * | ||
258 | ring_my_bell(); | ||
259 | * | ||
260 | * 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 | ||
261 | */ | ||
262 | fprintf ( | ||
263 | stdout, | ||
264 | _ ( | ||
265 | "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), | ||
266 | GNUNET_GNSRECORD_pkey_to_zkey (caller_id), | ||
267 | caller_num_gen, | ||
268 | caller_num_gen); | ||
269 | cl = GNUNET_new (struct CallList); | ||
270 | cl->caller = caller; | ||
271 | cl->caller_id = *caller_id; | ||
272 | cl->caller_num = caller_num_gen++; | ||
273 | GNUNET_CONTAINER_DLL_insert (cl_head, cl_tail, cl); | ||
274 | break; | ||
275 | |||
276 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
277 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
278 | if (caller == cl->caller) | ||
279 | break; | ||
280 | if ((NULL == cl) && (caller == cl_active->caller)) | ||
281 | cl = cl_active; | ||
282 | if (NULL == cl) | ||
250 | { | 283 | { |
251 | case GNUNET_CONVERSATION_EC_PHONE_RING: | 284 | GNUNET_break (0); |
252 | /* | 285 | return; |
253 | * FIXME: we should be playing our ringtones from contrib/sounds now! | ||
254 | * | ||
255 | ring_my_bell(); | ||
256 | * | ||
257 | * 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 | ||
258 | */ | ||
259 | fprintf( | ||
260 | stdout, | ||
261 | _( | ||
262 | "Incoming call from `%s'. Please /accept %u or /cancel %u the call.\n"), | ||
263 | GNUNET_GNSRECORD_pkey_to_zkey(caller_id), | ||
264 | caller_num_gen, | ||
265 | caller_num_gen); | ||
266 | cl = GNUNET_new(struct CallList); | ||
267 | cl->caller = caller; | ||
268 | cl->caller_id = *caller_id; | ||
269 | cl->caller_num = caller_num_gen++; | ||
270 | GNUNET_CONTAINER_DLL_insert(cl_head, cl_tail, cl); | ||
271 | break; | ||
272 | |||
273 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
274 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
275 | if (caller == cl->caller) | ||
276 | break; | ||
277 | if ((NULL == cl) && (caller == cl_active->caller)) | ||
278 | cl = cl_active; | ||
279 | if (NULL == cl) | ||
280 | { | ||
281 | GNUNET_break(0); | ||
282 | return; | ||
283 | } | ||
284 | fprintf(stdout, | ||
285 | _("Call from `%s' terminated\n"), | ||
286 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | ||
287 | if (cl == cl_active) | ||
288 | { | ||
289 | cl_active = NULL; | ||
290 | phone_state = PS_LISTEN; | ||
291 | } | ||
292 | else | ||
293 | { | ||
294 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); | ||
295 | } | ||
296 | GNUNET_free(cl); | ||
297 | break; | ||
298 | } | 286 | } |
287 | fprintf (stdout, | ||
288 | _ ("Call from `%s' terminated\n"), | ||
289 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); | ||
290 | if (cl == cl_active) | ||
291 | { | ||
292 | cl_active = NULL; | ||
293 | phone_state = PS_LISTEN; | ||
294 | } | ||
295 | else | ||
296 | { | ||
297 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); | ||
298 | } | ||
299 | GNUNET_free (cl); | ||
300 | break; | ||
301 | } | ||
299 | } | 302 | } |
300 | 303 | ||
301 | 304 | ||
@@ -306,24 +309,24 @@ phone_event_handler(void *cls, | |||
306 | * @param code type of the event issued by the caller | 309 | * @param code type of the event issued by the caller |
307 | */ | 310 | */ |
308 | static void | 311 | static void |
309 | caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | 312 | caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) |
310 | { | 313 | { |
311 | struct CallList *cl = cls; | 314 | struct CallList *cl = cls; |
312 | 315 | ||
313 | switch (code) | 316 | switch (code) |
314 | { | 317 | { |
315 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | 318 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: |
316 | fprintf(stdout, | 319 | fprintf (stdout, |
317 | _("Call from `%s' suspended by other user\n"), | 320 | _ ("Call from `%s' suspended by other user\n"), |
318 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | 321 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); |
319 | break; | 322 | break; |
320 | 323 | ||
321 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | 324 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: |
322 | fprintf(stdout, | 325 | fprintf (stdout, |
323 | _("Call from `%s' resumed by other user\n"), | 326 | _ ("Call from `%s' resumed by other user\n"), |
324 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | 327 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); |
325 | break; | 328 | break; |
326 | } | 329 | } |
327 | } | 330 | } |
328 | 331 | ||
329 | 332 | ||
@@ -331,42 +334,42 @@ caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | |||
331 | * Start our phone. | 334 | * Start our phone. |
332 | */ | 335 | */ |
333 | static void | 336 | static void |
334 | start_phone() | 337 | start_phone () |
335 | { | 338 | { |
336 | struct GNUNET_GNSRECORD_Data rd; | 339 | struct GNUNET_GNSRECORD_Data rd; |
337 | 340 | ||
338 | if (NULL == my_caller_id) | 341 | if (NULL == my_caller_id) |
339 | { | 342 | { |
340 | fprintf(stderr, | 343 | fprintf (stderr, |
341 | _("Ego `%s' no longer available, phone is now down.\n"), | 344 | _ ("Ego `%s' no longer available, phone is now down.\n"), |
342 | ego_name); | 345 | ego_name); |
343 | phone_state = PS_LOOKUP_EGO; | 346 | phone_state = PS_LOOKUP_EGO; |
344 | return; | 347 | return; |
345 | } | 348 | } |
346 | GNUNET_assert(NULL == phone); | 349 | GNUNET_assert (NULL == phone); |
347 | phone = GNUNET_CONVERSATION_phone_create(cfg, | 350 | phone = GNUNET_CONVERSATION_phone_create (cfg, |
348 | my_caller_id, | 351 | my_caller_id, |
349 | &phone_event_handler, | 352 | &phone_event_handler, |
350 | NULL); | 353 | NULL); |
351 | /* FIXME: get record and print full GNS record info later here... */ | 354 | /* FIXME: get record and print full GNS record info later here... */ |
352 | if (NULL == phone) | 355 | if (NULL == phone) |
353 | { | 356 | { |
354 | fprintf(stderr, "%s", _("Failed to setup phone (internal error)\n")); | 357 | fprintf (stderr, "%s", _ ("Failed to setup phone (internal error)\n")); |
355 | phone_state = PS_ERROR; | 358 | phone_state = PS_ERROR; |
356 | } | 359 | } |
357 | else | 360 | else |
358 | { | 361 | { |
359 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); | 362 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); |
360 | GNUNET_free_non_null(address); | 363 | GNUNET_free_non_null (address); |
361 | address = | 364 | address = |
362 | GNUNET_GNSRECORD_value_to_string(rd.record_type, rd.data, rd.data_size); | 365 | GNUNET_GNSRECORD_value_to_string (rd.record_type, rd.data, rd.data_size); |
363 | fprintf( | 366 | fprintf ( |
364 | stdout, | 367 | stdout, |
365 | _( | 368 | _ ( |
366 | "Phone active at `%s'. Type `/help' for a list of available commands\n"), | 369 | "Phone active at `%s'. Type `/help' for a list of available commands\n"), |
367 | address); | 370 | address); |
368 | phone_state = PS_LISTEN; | 371 | phone_state = PS_LISTEN; |
369 | } | 372 | } |
370 | } | 373 | } |
371 | 374 | ||
372 | 375 | ||
@@ -377,62 +380,62 @@ start_phone() | |||
377 | * @param code type of the event on the call | 380 | * @param code type of the event on the call |
378 | */ | 381 | */ |
379 | static void | 382 | static void |
380 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 383 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
381 | { | 384 | { |
382 | (void)cls; | 385 | (void) cls; |
383 | 386 | ||
384 | switch (code) | 387 | switch (code) |
385 | { | 388 | { |
386 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 389 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
387 | GNUNET_break(CS_RESOLVING == call_state); | 390 | GNUNET_break (CS_RESOLVING == call_state); |
388 | fprintf(stdout, | 391 | fprintf (stdout, |
389 | _("Resolved address of `%s'. Now ringing other party.\n"), | 392 | _ ("Resolved address of `%s'. Now ringing other party.\n"), |
390 | peer_name); | 393 | peer_name); |
391 | call_state = CS_RINGING; | 394 | call_state = CS_RINGING; |
392 | break; | 395 | break; |
393 | 396 | ||
394 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 397 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
395 | GNUNET_break(CS_RINGING == call_state); | 398 | GNUNET_break (CS_RINGING == call_state); |
396 | fprintf(stdout, _("Connection established to `%s'\n"), peer_name); | 399 | fprintf (stdout, _ ("Connection established to `%s'\n"), peer_name); |
397 | call_state = CS_CONNECTED; | 400 | call_state = CS_CONNECTED; |
398 | break; | 401 | break; |
399 | 402 | ||
400 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 403 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
401 | GNUNET_break(CS_RESOLVING == call_state); | 404 | GNUNET_break (CS_RESOLVING == call_state); |
402 | fprintf(stdout, _("Failed to resolve `%s'\n"), peer_name); | 405 | fprintf (stdout, _ ("Failed to resolve `%s'\n"), peer_name); |
403 | GNUNET_free(peer_name); | 406 | GNUNET_free (peer_name); |
404 | peer_name = NULL; | 407 | peer_name = NULL; |
405 | call = NULL; | 408 | call = NULL; |
406 | break; | 409 | break; |
407 | 410 | ||
408 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 411 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
409 | fprintf(stdout, _("Call to `%s' terminated\n"), peer_name); | 412 | fprintf (stdout, _ ("Call to `%s' terminated\n"), peer_name); |
410 | GNUNET_free(peer_name); | 413 | GNUNET_free (peer_name); |
411 | peer_name = NULL; | 414 | peer_name = NULL; |
412 | call = NULL; | 415 | call = NULL; |
413 | break; | 416 | break; |
414 | 417 | ||
415 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 418 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
416 | GNUNET_break(CS_CONNECTED == call_state); | 419 | GNUNET_break (CS_CONNECTED == call_state); |
417 | fprintf(stdout, | 420 | fprintf (stdout, |
418 | _("Connection to `%s' suspended (by other user)\n"), | 421 | _ ("Connection to `%s' suspended (by other user)\n"), |
419 | peer_name); | 422 | peer_name); |
420 | break; | 423 | break; |
421 | 424 | ||
422 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 425 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
423 | GNUNET_break(CS_CONNECTED == call_state); | 426 | GNUNET_break (CS_CONNECTED == call_state); |
424 | fprintf(stdout, | 427 | fprintf (stdout, |
425 | _("Connection to `%s' resumed (by other user)\n"), | 428 | _ ("Connection to `%s' resumed (by other user)\n"), |
426 | peer_name); | 429 | peer_name); |
427 | break; | 430 | break; |
428 | 431 | ||
429 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 432 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
430 | fprintf(stdout, _("Error with the call, restarting it\n")); | 433 | fprintf (stdout, _ ("Error with the call, restarting it\n")); |
431 | GNUNET_free(peer_name); | 434 | GNUNET_free (peer_name); |
432 | peer_name = NULL; | 435 | peer_name = NULL; |
433 | call = NULL; | 436 | call = NULL; |
434 | break; | 437 | break; |
435 | } | 438 | } |
436 | } | 439 | } |
437 | 440 | ||
438 | 441 | ||
@@ -447,7 +450,8 @@ typedef void (*ActionFunction) (const char *arguments); | |||
447 | /** | 450 | /** |
448 | * Structure which defines a command | 451 | * Structure which defines a command |
449 | */ | 452 | */ |
450 | struct VoipCommand { | 453 | struct VoipCommand |
454 | { | ||
451 | /** | 455 | /** |
452 | * Command the user needs to enter. | 456 | * Command the user needs to enter. |
453 | */ | 457 | */ |
@@ -471,7 +475,7 @@ struct VoipCommand { | |||
471 | * @param args arguments given to the command | 475 | * @param args arguments given to the command |
472 | */ | 476 | */ |
473 | static void | 477 | static void |
474 | do_help(const char *args); | 478 | do_help (const char *args); |
475 | 479 | ||
476 | 480 | ||
477 | /** | 481 | /** |
@@ -480,10 +484,10 @@ do_help(const char *args); | |||
480 | * @param args arguments given to the command | 484 | * @param args arguments given to the command |
481 | */ | 485 | */ |
482 | static void | 486 | static void |
483 | do_quit(const char *args) | 487 | do_quit (const char *args) |
484 | { | 488 | { |
485 | (void)args; | 489 | (void) args; |
486 | GNUNET_SCHEDULER_shutdown(); | 490 | GNUNET_SCHEDULER_shutdown (); |
487 | } | 491 | } |
488 | 492 | ||
489 | 493 | ||
@@ -493,9 +497,9 @@ do_quit(const char *args) | |||
493 | * @param msg arguments given to the command | 497 | * @param msg arguments given to the command |
494 | */ | 498 | */ |
495 | static void | 499 | static void |
496 | do_unknown(const char *msg) | 500 | do_unknown (const char *msg) |
497 | { | 501 | { |
498 | fprintf(stderr, _("Unknown command `%s'\n"), msg); | 502 | fprintf (stderr, _ ("Unknown command `%s'\n"), msg); |
499 | } | 503 | } |
500 | 504 | ||
501 | 505 | ||
@@ -505,57 +509,57 @@ do_unknown(const char *msg) | |||
505 | * @param arg arguments given to the command | 509 | * @param arg arguments given to the command |
506 | */ | 510 | */ |
507 | static void | 511 | static void |
508 | do_call(const char *arg) | 512 | do_call (const char *arg) |
509 | { | 513 | { |
510 | if (NULL == my_caller_id) | 514 | if (NULL == my_caller_id) |
511 | { | 515 | { |
512 | fprintf(stderr, _("Ego `%s' not available\n"), ego_name); | 516 | fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name); |
513 | return; | 517 | return; |
514 | } | 518 | } |
515 | if (NULL != call) | 519 | if (NULL != call) |
516 | { | 520 | { |
517 | fprintf(stderr, | 521 | fprintf (stderr, |
518 | _("You are calling someone else already, hang up first!\n")); | 522 | _ ("You are calling someone else already, hang up first!\n")); |
519 | return; | 523 | return; |
520 | } | 524 | } |
521 | switch (phone_state) | 525 | switch (phone_state) |
522 | { | 526 | { |
523 | case PS_LOOKUP_EGO: | 527 | case PS_LOOKUP_EGO: |
524 | fprintf(stderr, _("Ego `%s' not available\n"), ego_name); | 528 | fprintf (stderr, _ ("Ego `%s' not available\n"), ego_name); |
525 | return; | 529 | return; |
526 | 530 | ||
527 | case PS_LISTEN: | 531 | case PS_LISTEN: |
528 | /* ok to call! */ | 532 | /* ok to call! */ |
529 | break; | 533 | break; |
530 | 534 | ||
531 | case PS_ACCEPTED: | 535 | case PS_ACCEPTED: |
532 | fprintf( | 536 | fprintf ( |
533 | stderr, | 537 | stderr, |
534 | _( | 538 | _ ( |
535 | "You are answering call from `%s', hang up or suspend that call first!\n"), | 539 | "You are answering call from `%s', hang up or suspend that call first!\n"), |
536 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | 540 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); |
537 | return; | 541 | return; |
538 | 542 | ||
539 | case PS_ERROR: | 543 | case PS_ERROR: |
540 | /* ok to call */ | 544 | /* ok to call */ |
541 | break; | 545 | break; |
542 | } | 546 | } |
543 | if (NULL == arg) | 547 | if (NULL == arg) |
544 | { | 548 | { |
545 | fprintf(stderr, _("Call recipient missing.\n")); | 549 | fprintf (stderr, _ ("Call recipient missing.\n")); |
546 | do_help("/call"); | 550 | do_help ("/call"); |
547 | return; | 551 | return; |
548 | } | 552 | } |
549 | peer_name = GNUNET_strdup(arg); | 553 | peer_name = GNUNET_strdup (arg); |
550 | call_state = CS_RESOLVING; | 554 | call_state = CS_RESOLVING; |
551 | GNUNET_assert(NULL == call); | 555 | GNUNET_assert (NULL == call); |
552 | call = GNUNET_CONVERSATION_call_start(cfg, | 556 | call = GNUNET_CONVERSATION_call_start (cfg, |
553 | my_caller_id, | 557 | my_caller_id, |
554 | arg, | 558 | arg, |
555 | speaker, | 559 | speaker, |
556 | mic, | 560 | mic, |
557 | &call_event_handler, | 561 | &call_event_handler, |
558 | NULL); | 562 | NULL); |
559 | } | 563 | } |
560 | 564 | ||
561 | 565 | ||
@@ -565,70 +569,70 @@ do_call(const char *arg) | |||
565 | * @param args arguments given to the command | 569 | * @param args arguments given to the command |
566 | */ | 570 | */ |
567 | static void | 571 | static void |
568 | do_accept(const char *args) | 572 | do_accept (const char *args) |
569 | { | 573 | { |
570 | struct CallList *cl; | 574 | struct CallList *cl; |
571 | char buf[32]; | 575 | char buf[32]; |
572 | 576 | ||
573 | if ((NULL != call) && (CS_SUSPENDED != call_state)) | 577 | if ((NULL != call) && (CS_SUSPENDED != call_state)) |
574 | { | 578 | { |
575 | fprintf(stderr, | 579 | fprintf (stderr, |
576 | _("You are calling someone else already, hang up first!\n")); | 580 | _ ("You are calling someone else already, hang up first!\n")); |
577 | return; | 581 | return; |
578 | } | 582 | } |
579 | switch (phone_state) | 583 | switch (phone_state) |
580 | { | 584 | { |
581 | case PS_LOOKUP_EGO: | 585 | case PS_LOOKUP_EGO: |
582 | GNUNET_break(0); | 586 | GNUNET_break (0); |
583 | break; | 587 | break; |
584 | 588 | ||
585 | case PS_LISTEN: | 589 | case PS_LISTEN: |
586 | /* this is the expected state */ | 590 | /* this is the expected state */ |
587 | break; | 591 | break; |
588 | 592 | ||
589 | case PS_ACCEPTED: | 593 | case PS_ACCEPTED: |
590 | fprintf( | 594 | fprintf ( |
591 | stderr, | 595 | stderr, |
592 | _( | 596 | _ ( |
593 | "You are answering call from `%s', hang up or suspend that call first!\n"), | 597 | "You are answering call from `%s', hang up or suspend that call first!\n"), |
594 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | 598 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); |
595 | return; | 599 | return; |
596 | 600 | ||
597 | case PS_ERROR: | 601 | case PS_ERROR: |
598 | GNUNET_break(0); | 602 | GNUNET_break (0); |
599 | break; | 603 | break; |
600 | } | 604 | } |
601 | cl = cl_head; | 605 | cl = cl_head; |
602 | if (NULL == cl) | 606 | if (NULL == cl) |
603 | { | 607 | { |
604 | fprintf(stderr, _("There is no incoming call to accept here!\n")); | 608 | fprintf (stderr, _ ("There is no incoming call to accept here!\n")); |
605 | return; | 609 | return; |
606 | } | 610 | } |
607 | if ((NULL != cl->next) || (NULL != args)) | 611 | if ((NULL != cl->next) || (NULL != args)) |
612 | { | ||
613 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
608 | { | 614 | { |
609 | for (cl = cl_head; NULL != cl; cl = cl->next) | 615 | GNUNET_snprintf (buf, sizeof(buf), "%u", cl->caller_num); |
610 | { | 616 | if (0 == strcmp (buf, args)) |
611 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); | 617 | break; |
612 | if (0 == strcmp(buf, args)) | ||
613 | break; | ||
614 | } | ||
615 | } | 618 | } |
619 | } | ||
616 | if (NULL == cl) | 620 | if (NULL == cl) |
617 | { | 621 | { |
618 | fprintf(stderr, | 622 | fprintf (stderr, |
619 | _("There is no incoming call `%s' to accept right now!\n"), | 623 | _ ("There is no incoming call `%s' to accept right now!\n"), |
620 | args); | 624 | args); |
621 | return; | 625 | return; |
622 | } | 626 | } |
623 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); | 627 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); |
624 | cl_active = cl; | 628 | cl_active = cl; |
625 | peer_key = cl->caller_id; | 629 | peer_key = cl->caller_id; |
626 | phone_state = PS_ACCEPTED; | 630 | phone_state = PS_ACCEPTED; |
627 | GNUNET_CONVERSATION_caller_pick_up(cl->caller, | 631 | GNUNET_CONVERSATION_caller_pick_up (cl->caller, |
628 | &caller_event_handler, | 632 | &caller_event_handler, |
629 | cl, | 633 | cl, |
630 | speaker, | 634 | speaker, |
631 | mic); | 635 | mic); |
632 | } | 636 | } |
633 | 637 | ||
634 | 638 | ||
@@ -638,15 +642,15 @@ do_accept(const char *args) | |||
638 | * @param args arguments given to the command | 642 | * @param args arguments given to the command |
639 | */ | 643 | */ |
640 | static void | 644 | static void |
641 | do_address(const char *args) | 645 | do_address (const char *args) |
642 | { | 646 | { |
643 | (void)args; | 647 | (void) args; |
644 | if (NULL == address) | 648 | if (NULL == address) |
645 | { | 649 | { |
646 | fprintf(stdout, "%s", _("We currently do not have an address.\n")); | 650 | fprintf (stdout, "%s", _ ("We currently do not have an address.\n")); |
647 | return; | 651 | return; |
648 | } | 652 | } |
649 | fprintf(stdout, "%s\n", address); | 653 | fprintf (stdout, "%s\n", address); |
650 | } | 654 | } |
651 | 655 | ||
652 | 656 | ||
@@ -656,84 +660,84 @@ do_address(const char *args) | |||
656 | * @param args arguments given to the command | 660 | * @param args arguments given to the command |
657 | */ | 661 | */ |
658 | static void | 662 | static void |
659 | do_status(const char *args) | 663 | do_status (const char *args) |
660 | { | 664 | { |
661 | struct CallList *cl; | 665 | struct CallList *cl; |
662 | 666 | ||
663 | (void)args; | 667 | (void) args; |
664 | switch (phone_state) | 668 | switch (phone_state) |
669 | { | ||
670 | case PS_LOOKUP_EGO: | ||
671 | fprintf ( | ||
672 | stdout, | ||
673 | _ ( | ||
674 | "We are currently trying to locate the private key for the ego `%s'.\n"), | ||
675 | ego_name); | ||
676 | break; | ||
677 | |||
678 | case PS_LISTEN: | ||
679 | fprintf (stdout, | ||
680 | _ ( | ||
681 | "We are listening for incoming calls for ego `%s' on line `%s'.\n"), | ||
682 | ego_name, | ||
683 | line); | ||
684 | break; | ||
685 | |||
686 | case PS_ACCEPTED: | ||
687 | fprintf (stdout, | ||
688 | _ ("You are having a conversation with `%s'.\n"), | ||
689 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | ||
690 | ; | ||
691 | break; | ||
692 | |||
693 | case PS_ERROR: | ||
694 | fprintf ( | ||
695 | stdout, | ||
696 | _ ( | ||
697 | "We had an internal error setting up our phone line. You can still make calls.\n")); | ||
698 | break; | ||
699 | } | ||
700 | if (NULL != call) | ||
701 | { | ||
702 | switch (call_state) | ||
665 | { | 703 | { |
666 | case PS_LOOKUP_EGO: | 704 | case CS_RESOLVING: |
667 | fprintf( | 705 | fprintf (stdout, |
668 | stdout, | 706 | _ ("We are trying to find the network address to call `%s'.\n"), |
669 | _( | 707 | peer_name); |
670 | "We are currently trying to locate the private key for the ego `%s'.\n"), | ||
671 | ego_name); | ||
672 | break; | 708 | break; |
673 | 709 | ||
674 | case PS_LISTEN: | 710 | case CS_RINGING: |
675 | fprintf(stdout, | 711 | fprintf (stdout, |
676 | _( | 712 | _ ("We are calling `%s', their phone should be ringing.\n"), |
677 | "We are listening for incoming calls for ego `%s' on line `%s'.\n"), | 713 | peer_name); |
678 | ego_name, | ||
679 | line); | ||
680 | break; | 714 | break; |
681 | 715 | ||
682 | case PS_ACCEPTED: | 716 | case CS_CONNECTED: |
683 | fprintf(stdout, | 717 | fprintf (stdout, |
684 | _("You are having a conversation with `%s'.\n"), | 718 | _ ("You are having a conversation with `%s'.\n"), |
685 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | 719 | peer_name); |
686 | ; | ||
687 | break; | 720 | break; |
688 | 721 | ||
689 | case PS_ERROR: | 722 | case CS_SUSPENDED: |
690 | fprintf( | 723 | /* ok to accept incoming call right now */ |
691 | stdout, | ||
692 | _( | ||
693 | "We had an internal error setting up our phone line. You can still make calls.\n")); | ||
694 | break; | 724 | break; |
695 | } | 725 | } |
696 | if (NULL != call) | 726 | } |
697 | { | ||
698 | switch (call_state) | ||
699 | { | ||
700 | case CS_RESOLVING: | ||
701 | fprintf(stdout, | ||
702 | _("We are trying to find the network address to call `%s'.\n"), | ||
703 | peer_name); | ||
704 | break; | ||
705 | |||
706 | case CS_RINGING: | ||
707 | fprintf(stdout, | ||
708 | _("We are calling `%s', their phone should be ringing.\n"), | ||
709 | peer_name); | ||
710 | break; | ||
711 | |||
712 | case CS_CONNECTED: | ||
713 | fprintf(stdout, | ||
714 | _("You are having a conversation with `%s'.\n"), | ||
715 | peer_name); | ||
716 | break; | ||
717 | |||
718 | case CS_SUSPENDED: | ||
719 | /* ok to accept incoming call right now */ | ||
720 | break; | ||
721 | } | ||
722 | } | ||
723 | if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail))) | 727 | if ((NULL != cl_head) && ((cl_head != cl_active) || (cl_head != cl_tail))) |
728 | { | ||
729 | fprintf (stdout, "%s", _ ("Calls waiting:\n")); | ||
730 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
724 | { | 731 | { |
725 | fprintf(stdout, "%s", _("Calls waiting:\n")); | 732 | if (cl == cl_active) |
726 | for (cl = cl_head; NULL != cl; cl = cl->next) | 733 | continue; |
727 | { | 734 | fprintf (stdout, |
728 | if (cl == cl_active) | 735 | _ ("#%u: `%s'\n"), |
729 | continue; | 736 | cl->caller_num, |
730 | fprintf(stdout, | 737 | GNUNET_GNSRECORD_pkey_to_zkey (&cl->caller_id)); |
731 | _("#%u: `%s'\n"), | ||
732 | cl->caller_num, | ||
733 | GNUNET_GNSRECORD_pkey_to_zkey(&cl->caller_id)); | ||
734 | } | ||
735 | fprintf(stdout, "%s", "\n"); | ||
736 | } | 738 | } |
739 | fprintf (stdout, "%s", "\n"); | ||
740 | } | ||
737 | } | 741 | } |
738 | 742 | ||
739 | 743 | ||
@@ -743,43 +747,43 @@ do_status(const char *args) | |||
743 | * @param args arguments given to the command | 747 | * @param args arguments given to the command |
744 | */ | 748 | */ |
745 | static void | 749 | static void |
746 | do_suspend(const char *args) | 750 | do_suspend (const char *args) |
747 | { | 751 | { |
748 | (void)args; | 752 | (void) args; |
749 | if (NULL != call) | 753 | if (NULL != call) |
754 | { | ||
755 | switch (call_state) | ||
750 | { | 756 | { |
751 | switch (call_state) | 757 | case CS_RESOLVING: |
752 | { | 758 | case CS_RINGING: |
753 | case CS_RESOLVING: | 759 | case CS_SUSPENDED: |
754 | case CS_RINGING: | 760 | fprintf (stderr, |
755 | case CS_SUSPENDED: | 761 | "%s", |
756 | fprintf(stderr, | 762 | _ ("There is no call that could be suspended right now.\n")); |
757 | "%s", | ||
758 | _("There is no call that could be suspended right now.\n")); | ||
759 | return; | ||
760 | |||
761 | case CS_CONNECTED: | ||
762 | call_state = CS_SUSPENDED; | ||
763 | GNUNET_CONVERSATION_call_suspend(call); | ||
764 | return; | ||
765 | } | ||
766 | } | ||
767 | switch (phone_state) | ||
768 | { | ||
769 | case PS_LOOKUP_EGO: | ||
770 | case PS_LISTEN: | ||
771 | case PS_ERROR: | ||
772 | fprintf(stderr, | ||
773 | "%s", | ||
774 | _("There is no call that could be suspended right now.\n")); | ||
775 | return; | 763 | return; |
776 | 764 | ||
777 | case PS_ACCEPTED: | 765 | case CS_CONNECTED: |
778 | /* expected state, do rejection logic */ | 766 | call_state = CS_SUSPENDED; |
779 | break; | 767 | GNUNET_CONVERSATION_call_suspend (call); |
768 | return; | ||
780 | } | 769 | } |
781 | GNUNET_assert(NULL != cl_active); | 770 | } |
782 | GNUNET_CONVERSATION_caller_suspend(cl_active->caller); | 771 | switch (phone_state) |
772 | { | ||
773 | case PS_LOOKUP_EGO: | ||
774 | case PS_LISTEN: | ||
775 | case PS_ERROR: | ||
776 | fprintf (stderr, | ||
777 | "%s", | ||
778 | _ ("There is no call that could be suspended right now.\n")); | ||
779 | return; | ||
780 | |||
781 | case PS_ACCEPTED: | ||
782 | /* expected state, do rejection logic */ | ||
783 | break; | ||
784 | } | ||
785 | GNUNET_assert (NULL != cl_active); | ||
786 | GNUNET_CONVERSATION_caller_suspend (cl_active->caller); | ||
783 | cl_active = NULL; | 787 | cl_active = NULL; |
784 | phone_state = PS_LISTEN; | 788 | phone_state = PS_LISTEN; |
785 | } | 789 | } |
@@ -791,73 +795,73 @@ do_suspend(const char *args) | |||
791 | * @param args arguments given to the command | 795 | * @param args arguments given to the command |
792 | */ | 796 | */ |
793 | static void | 797 | static void |
794 | do_resume(const char *args) | 798 | do_resume (const char *args) |
795 | { | 799 | { |
796 | struct CallList *cl; | 800 | struct CallList *cl; |
797 | char buf[32]; | 801 | char buf[32]; |
798 | 802 | ||
799 | if (NULL != call) | 803 | if (NULL != call) |
804 | { | ||
805 | switch (call_state) | ||
800 | { | 806 | { |
801 | switch (call_state) | 807 | case CS_RESOLVING: |
802 | { | 808 | case CS_RINGING: |
803 | case CS_RESOLVING: | 809 | case CS_CONNECTED: |
804 | case CS_RINGING: | 810 | fprintf (stderr, |
805 | case CS_CONNECTED: | 811 | "%s", |
806 | fprintf(stderr, | 812 | _ ("There is no call that could be resumed right now.\n")); |
807 | "%s", | ||
808 | _("There is no call that could be resumed right now.\n")); | ||
809 | return; | ||
810 | |||
811 | case CS_SUSPENDED: | ||
812 | call_state = CS_CONNECTED; | ||
813 | GNUNET_CONVERSATION_call_resume(call, speaker, mic); | ||
814 | return; | ||
815 | } | ||
816 | } | ||
817 | switch (phone_state) | ||
818 | { | ||
819 | case PS_LOOKUP_EGO: | ||
820 | case PS_ERROR: | ||
821 | fprintf(stderr, | ||
822 | "%s", | ||
823 | _("There is no call that could be resumed right now.\n")); | ||
824 | return; | 813 | return; |
825 | 814 | ||
826 | case PS_LISTEN: | 815 | case CS_SUSPENDED: |
827 | /* expected state, do resume logic */ | 816 | call_state = CS_CONNECTED; |
828 | break; | 817 | GNUNET_CONVERSATION_call_resume (call, speaker, mic); |
829 | |||
830 | case PS_ACCEPTED: | ||
831 | fprintf(stderr, | ||
832 | _("Already talking with `%s', cannot resume a call right now.\n"), | ||
833 | GNUNET_GNSRECORD_pkey_to_zkey(&peer_key)); | ||
834 | return; | 818 | return; |
835 | } | 819 | } |
836 | GNUNET_assert(NULL == cl_active); | 820 | } |
821 | switch (phone_state) | ||
822 | { | ||
823 | case PS_LOOKUP_EGO: | ||
824 | case PS_ERROR: | ||
825 | fprintf (stderr, | ||
826 | "%s", | ||
827 | _ ("There is no call that could be resumed right now.\n")); | ||
828 | return; | ||
829 | |||
830 | case PS_LISTEN: | ||
831 | /* expected state, do resume logic */ | ||
832 | break; | ||
833 | |||
834 | case PS_ACCEPTED: | ||
835 | fprintf (stderr, | ||
836 | _ ("Already talking with `%s', cannot resume a call right now.\n"), | ||
837 | GNUNET_GNSRECORD_pkey_to_zkey (&peer_key)); | ||
838 | return; | ||
839 | } | ||
840 | GNUNET_assert (NULL == cl_active); | ||
837 | cl = cl_head; | 841 | cl = cl_head; |
838 | if (NULL == cl) | 842 | if (NULL == cl) |
839 | { | 843 | { |
840 | fprintf(stderr, _("There is no incoming call to resume here!\n")); | 844 | fprintf (stderr, _ ("There is no incoming call to resume here!\n")); |
841 | return; | 845 | return; |
842 | } | 846 | } |
843 | if ((NULL != cl->next) || (NULL != args)) | 847 | if ((NULL != cl->next) || (NULL != args)) |
848 | { | ||
849 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
844 | { | 850 | { |
845 | for (cl = cl_head; NULL != cl; cl = cl->next) | 851 | GNUNET_snprintf (buf, sizeof(buf), "%u", cl->caller_num); |
846 | { | 852 | if (0 == strcmp (buf, args)) |
847 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); | 853 | break; |
848 | if (0 == strcmp(buf, args)) | ||
849 | break; | ||
850 | } | ||
851 | } | 854 | } |
855 | } | ||
852 | if (NULL == cl) | 856 | if (NULL == cl) |
853 | { | 857 | { |
854 | fprintf(stderr, | 858 | fprintf (stderr, |
855 | _("There is no incoming call `%s' to resume right now!\n"), | 859 | _ ("There is no incoming call `%s' to resume right now!\n"), |
856 | args); | 860 | args); |
857 | return; | 861 | return; |
858 | } | 862 | } |
859 | cl_active = cl; | 863 | cl_active = cl; |
860 | GNUNET_CONVERSATION_caller_resume(cl_active->caller, speaker, mic); | 864 | GNUNET_CONVERSATION_caller_resume (cl_active->caller, speaker, mic); |
861 | phone_state = PS_ACCEPTED; | 865 | phone_state = PS_ACCEPTED; |
862 | } | 866 | } |
863 | 867 | ||
@@ -868,63 +872,63 @@ do_resume(const char *args) | |||
868 | * @param args arguments given to the command | 872 | * @param args arguments given to the command |
869 | */ | 873 | */ |
870 | static void | 874 | static void |
871 | do_reject(const char *args) | 875 | do_reject (const char *args) |
872 | { | 876 | { |
873 | struct CallList *cl; | 877 | struct CallList *cl; |
874 | char buf[32]; | 878 | char buf[32]; |
875 | 879 | ||
876 | if (NULL != call) | 880 | if (NULL != call) |
881 | { | ||
882 | GNUNET_CONVERSATION_call_stop (call); | ||
883 | call = NULL; | ||
884 | return; | ||
885 | } | ||
886 | switch (phone_state) | ||
887 | { | ||
888 | case PS_LOOKUP_EGO: | ||
889 | case PS_ERROR: | ||
890 | fprintf (stderr, | ||
891 | "%s", | ||
892 | _ ("There is no call that could be cancelled right now.\n")); | ||
893 | return; | ||
894 | |||
895 | case PS_LISTEN: | ||
896 | /* look for active incoming calls to refuse */ | ||
897 | cl = cl_head; | ||
898 | if (NULL == cl) | ||
877 | { | 899 | { |
878 | GNUNET_CONVERSATION_call_stop(call); | 900 | fprintf (stderr, _ ("There is no incoming call to refuse here!\n")); |
879 | call = NULL; | ||
880 | return; | 901 | return; |
881 | } | 902 | } |
882 | switch (phone_state) | 903 | if ((NULL != cl->next) || (NULL != args)) |
883 | { | 904 | { |
884 | case PS_LOOKUP_EGO: | 905 | for (cl = cl_head; NULL != cl; cl = cl->next) |
885 | case PS_ERROR: | 906 | { |
886 | fprintf(stderr, | 907 | GNUNET_snprintf (buf, sizeof(buf), "%u", cl->caller_num); |
887 | "%s", | 908 | if (0 == strcmp (buf, args)) |
888 | _("There is no call that could be cancelled right now.\n")); | 909 | break; |
910 | } | ||
911 | } | ||
912 | if (NULL == cl) | ||
913 | { | ||
914 | fprintf (stderr, | ||
915 | _ ("There is no incoming call `%s' to refuse right now!\n"), | ||
916 | args); | ||
889 | return; | 917 | return; |
890 | |||
891 | case PS_LISTEN: | ||
892 | /* look for active incoming calls to refuse */ | ||
893 | cl = cl_head; | ||
894 | if (NULL == cl) | ||
895 | { | ||
896 | fprintf(stderr, _("There is no incoming call to refuse here!\n")); | ||
897 | return; | ||
898 | } | ||
899 | if ((NULL != cl->next) || (NULL != args)) | ||
900 | { | ||
901 | for (cl = cl_head; NULL != cl; cl = cl->next) | ||
902 | { | ||
903 | GNUNET_snprintf(buf, sizeof(buf), "%u", cl->caller_num); | ||
904 | if (0 == strcmp(buf, args)) | ||
905 | break; | ||
906 | } | ||
907 | } | ||
908 | if (NULL == cl) | ||
909 | { | ||
910 | fprintf(stderr, | ||
911 | _("There is no incoming call `%s' to refuse right now!\n"), | ||
912 | args); | ||
913 | return; | ||
914 | } | ||
915 | GNUNET_CONVERSATION_caller_hang_up(cl->caller); | ||
916 | GNUNET_CONTAINER_DLL_remove(cl_head, cl_tail, cl); | ||
917 | GNUNET_free(cl); | ||
918 | break; | ||
919 | |||
920 | case PS_ACCEPTED: | ||
921 | /* expected state, do rejection logic */ | ||
922 | GNUNET_assert(NULL != cl_active); | ||
923 | GNUNET_CONVERSATION_caller_hang_up(cl_active->caller); | ||
924 | cl_active = NULL; | ||
925 | phone_state = PS_LISTEN; | ||
926 | break; | ||
927 | } | 918 | } |
919 | GNUNET_CONVERSATION_caller_hang_up (cl->caller); | ||
920 | GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl); | ||
921 | GNUNET_free (cl); | ||
922 | break; | ||
923 | |||
924 | case PS_ACCEPTED: | ||
925 | /* expected state, do rejection logic */ | ||
926 | GNUNET_assert (NULL != cl_active); | ||
927 | GNUNET_CONVERSATION_caller_hang_up (cl_active->caller); | ||
928 | cl_active = NULL; | ||
929 | phone_state = PS_LISTEN; | ||
930 | break; | ||
931 | } | ||
928 | } | 932 | } |
929 | 933 | ||
930 | 934 | ||
@@ -934,31 +938,31 @@ do_reject(const char *args) | |||
934 | static struct VoipCommand commands[] = { | 938 | static struct VoipCommand commands[] = { |
935 | { "/address", | 939 | { "/address", |
936 | &do_address, | 940 | &do_address, |
937 | gettext_noop( | 941 | gettext_noop ( |
938 | "Use `/address' to find out which address this phone should have in GNS") }, | 942 | "Use `/address' to find out which address this phone should have in GNS") }, |
939 | { "/call", &do_call, gettext_noop("Use `/call USER.gnu' to call USER") }, | 943 | { "/call", &do_call, gettext_noop ("Use `/call USER.gnu' to call USER") }, |
940 | { "/accept", | 944 | { "/accept", |
941 | &do_accept, | 945 | &do_accept, |
942 | gettext_noop("Use `/accept #NUM' to accept incoming call #NUM") }, | 946 | gettext_noop ("Use `/accept #NUM' to accept incoming call #NUM") }, |
943 | { "/suspend", | 947 | { "/suspend", |
944 | &do_suspend, | 948 | &do_suspend, |
945 | gettext_noop("Use `/suspend' to suspend the active call") }, | 949 | gettext_noop ("Use `/suspend' to suspend the active call") }, |
946 | { "/resume", | 950 | { "/resume", |
947 | &do_resume, | 951 | &do_resume, |
948 | gettext_noop( | 952 | gettext_noop ( |
949 | "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.") }, | 953 | "Use `/resume [#NUM]' to resume a call, #NUM is needed to resume incoming calls, no argument is needed to resume the current outgoing call.") }, |
950 | { "/cancel", | 954 | { "/cancel", |
951 | &do_reject, | 955 | &do_reject, |
952 | gettext_noop("Use `/cancel' to reject or terminate a call") }, | 956 | gettext_noop ("Use `/cancel' to reject or terminate a call") }, |
953 | { "/status", | 957 | { "/status", |
954 | &do_status, | 958 | &do_status, |
955 | gettext_noop("Use `/status' to print status information") }, | 959 | gettext_noop ("Use `/status' to print status information") }, |
956 | { "/quit", | 960 | { "/quit", |
957 | &do_quit, | 961 | &do_quit, |
958 | gettext_noop("Use `/quit' to terminate gnunet-conversation") }, | 962 | gettext_noop ("Use `/quit' to terminate gnunet-conversation") }, |
959 | { "/help", | 963 | { "/help", |
960 | &do_help, | 964 | &do_help, |
961 | gettext_noop("Use `/help command' to get help for a specific command") }, | 965 | gettext_noop ("Use `/help command' to get help for a specific command") }, |
962 | { "", &do_unknown, NULL }, | 966 | { "", &do_unknown, NULL }, |
963 | { NULL, NULL, NULL }, | 967 | { NULL, NULL, NULL }, |
964 | }; | 968 | }; |
@@ -970,30 +974,30 @@ static struct VoipCommand commands[] = { | |||
970 | * @param args arguments given to the command | 974 | * @param args arguments given to the command |
971 | */ | 975 | */ |
972 | static void | 976 | static void |
973 | do_help(const char *args) | 977 | do_help (const char *args) |
974 | { | 978 | { |
975 | unsigned int i; | 979 | unsigned int i; |
976 | 980 | ||
977 | i = 0; | 981 | i = 0; |
978 | while ((NULL != args) && (0 != strlen(args)) && | 982 | while ((NULL != args) && (0 != strlen (args)) && |
979 | (commands[i].Action != &do_help)) | 983 | (commands[i].Action != &do_help)) |
984 | { | ||
985 | if (0 == strncasecmp (&args[1], &commands[i].command[1], strlen (args) - 1)) | ||
980 | { | 986 | { |
981 | if (0 == strncasecmp(&args[1], &commands[i].command[1], strlen(args) - 1)) | 987 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); |
982 | { | 988 | return; |
983 | fprintf(stdout, "%s\n", gettext(commands[i].helptext)); | ||
984 | return; | ||
985 | } | ||
986 | i++; | ||
987 | } | 989 | } |
990 | i++; | ||
991 | } | ||
988 | i = 0; | 992 | i = 0; |
989 | fprintf(stdout, "%s", "Available commands:\n"); | 993 | fprintf (stdout, "%s", "Available commands:\n"); |
990 | while (commands[i].Action != &do_help) | 994 | while (commands[i].Action != &do_help) |
991 | { | 995 | { |
992 | fprintf(stdout, "%s\n", gettext(commands[i].command)); | 996 | fprintf (stdout, "%s\n", gettext (commands[i].command)); |
993 | i++; | 997 | i++; |
994 | } | 998 | } |
995 | fprintf(stdout, "%s", "\n"); | 999 | fprintf (stdout, "%s", "\n"); |
996 | fprintf(stdout, "%s\n", gettext(commands[i].helptext)); | 1000 | fprintf (stdout, "%s\n", gettext (commands[i].helptext)); |
997 | } | 1001 | } |
998 | 1002 | ||
999 | 1003 | ||
@@ -1003,36 +1007,36 @@ do_help(const char *args) | |||
1003 | * @param cls NULL | 1007 | * @param cls NULL |
1004 | */ | 1008 | */ |
1005 | static void | 1009 | static void |
1006 | do_stop_task(void *cls) | 1010 | do_stop_task (void *cls) |
1007 | { | 1011 | { |
1008 | (void)cls; | 1012 | (void) cls; |
1009 | if (NULL != call) | 1013 | if (NULL != call) |
1010 | { | 1014 | { |
1011 | GNUNET_CONVERSATION_call_stop(call); | 1015 | GNUNET_CONVERSATION_call_stop (call); |
1012 | call = NULL; | 1016 | call = NULL; |
1013 | } | 1017 | } |
1014 | if (NULL != phone) | 1018 | if (NULL != phone) |
1015 | { | 1019 | { |
1016 | GNUNET_CONVERSATION_phone_destroy(phone); | 1020 | GNUNET_CONVERSATION_phone_destroy (phone); |
1017 | phone = NULL; | 1021 | phone = NULL; |
1018 | } | 1022 | } |
1019 | if (NULL != handle_cmd_task) | 1023 | if (NULL != handle_cmd_task) |
1020 | { | 1024 | { |
1021 | GNUNET_SCHEDULER_cancel(handle_cmd_task); | 1025 | GNUNET_SCHEDULER_cancel (handle_cmd_task); |
1022 | handle_cmd_task = NULL; | 1026 | handle_cmd_task = NULL; |
1023 | } | 1027 | } |
1024 | if (NULL != id) | 1028 | if (NULL != id) |
1025 | { | 1029 | { |
1026 | GNUNET_IDENTITY_disconnect(id); | 1030 | GNUNET_IDENTITY_disconnect (id); |
1027 | id = NULL; | 1031 | id = NULL; |
1028 | } | 1032 | } |
1029 | GNUNET_SPEAKER_destroy(speaker); | 1033 | GNUNET_SPEAKER_destroy (speaker); |
1030 | speaker = NULL; | 1034 | speaker = NULL; |
1031 | GNUNET_MICROPHONE_destroy(mic); | 1035 | GNUNET_MICROPHONE_destroy (mic); |
1032 | mic = NULL; | 1036 | mic = NULL; |
1033 | GNUNET_free(ego_name); | 1037 | GNUNET_free (ego_name); |
1034 | ego_name = NULL; | 1038 | ego_name = NULL; |
1035 | GNUNET_free_non_null(peer_name); | 1039 | GNUNET_free_non_null (peer_name); |
1036 | peer_name = NULL; | 1040 | peer_name = NULL; |
1037 | phone_state = PS_ERROR; | 1041 | phone_state = PS_ERROR; |
1038 | } | 1042 | } |
@@ -1045,7 +1049,7 @@ do_stop_task(void *cls) | |||
1045 | * @param str_len number of bytes to process in @a message | 1049 | * @param str_len number of bytes to process in @a message |
1046 | */ | 1050 | */ |
1047 | static void | 1051 | static void |
1048 | handle_command_string(char *message, size_t str_len) | 1052 | handle_command_string (char *message, size_t str_len) |
1049 | { | 1053 | { |
1050 | size_t i; | 1054 | size_t i; |
1051 | const char *ptr; | 1055 | const char *ptr; |
@@ -1056,20 +1060,20 @@ handle_command_string(char *message, size_t str_len) | |||
1056 | message[str_len - 1] = '\0'; | 1060 | message[str_len - 1] = '\0'; |
1057 | if (message[str_len - 2] == '\r') | 1061 | if (message[str_len - 2] == '\r') |
1058 | message[str_len - 2] = '\0'; | 1062 | message[str_len - 2] = '\0'; |
1059 | if (0 == strlen(message)) | 1063 | if (0 == strlen (message)) |
1060 | return; | 1064 | return; |
1061 | i = 0; | 1065 | i = 0; |
1062 | while ( | 1066 | while ( |
1063 | (NULL != commands[i].command) && | 1067 | (NULL != commands[i].command) && |
1064 | (0 != | 1068 | (0 != |
1065 | strncasecmp(commands[i].command, message, strlen(commands[i].command)))) | 1069 | strncasecmp (commands[i].command, message, strlen (commands[i].command)))) |
1066 | i++; | 1070 | i++; |
1067 | ptr = &message[strlen(commands[i].command)]; | 1071 | ptr = &message[strlen (commands[i].command)]; |
1068 | while (isspace((unsigned char)*ptr)) | 1072 | while (isspace ((unsigned char) *ptr)) |
1069 | ptr++; | 1073 | ptr++; |
1070 | if ('\0' == *ptr) | 1074 | if ('\0' == *ptr) |
1071 | ptr = NULL; | 1075 | ptr = NULL; |
1072 | commands[i].Action(ptr); | 1076 | commands[i].Action (ptr); |
1073 | } | 1077 | } |
1074 | 1078 | ||
1075 | 1079 | ||
@@ -1079,21 +1083,21 @@ handle_command_string(char *message, size_t str_len) | |||
1079 | * @param cls NULL | 1083 | * @param cls NULL |
1080 | */ | 1084 | */ |
1081 | static void | 1085 | static void |
1082 | handle_command(void *cls) | 1086 | handle_command (void *cls) |
1083 | { | 1087 | { |
1084 | char message[MAX_MESSAGE_LENGTH + 1]; | 1088 | char message[MAX_MESSAGE_LENGTH + 1]; |
1085 | 1089 | ||
1086 | (void)cls; | 1090 | (void) cls; |
1087 | handle_cmd_task = | 1091 | handle_cmd_task = |
1088 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 1092 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
1089 | stdin_fh, | 1093 | stdin_fh, |
1090 | &handle_command, | 1094 | &handle_command, |
1091 | NULL); | 1095 | NULL); |
1092 | /* read message from command line and handle it */ | 1096 | /* read message from command line and handle it */ |
1093 | memset(message, 0, MAX_MESSAGE_LENGTH + 1); | 1097 | memset (message, 0, MAX_MESSAGE_LENGTH + 1); |
1094 | if (NULL == fgets(message, MAX_MESSAGE_LENGTH, stdin)) | 1098 | if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin)) |
1095 | return; | 1099 | return; |
1096 | handle_command_string(message, strlen(message)); | 1100 | handle_command_string (message, strlen (message)); |
1097 | } | 1101 | } |
1098 | 1102 | ||
1099 | 1103 | ||
@@ -1106,35 +1110,35 @@ handle_command(void *cls) | |||
1106 | * @param name name of the ego | 1110 | * @param name name of the ego |
1107 | */ | 1111 | */ |
1108 | static void | 1112 | static void |
1109 | identity_cb(void *cls, | 1113 | identity_cb (void *cls, |
1110 | struct GNUNET_IDENTITY_Ego *ego, | 1114 | struct GNUNET_IDENTITY_Ego *ego, |
1111 | void **ctx, | 1115 | void **ctx, |
1112 | const char *name) | 1116 | const char *name) |
1113 | { | 1117 | { |
1114 | (void)cls; | 1118 | (void) cls; |
1115 | (void)ctx; | 1119 | (void) ctx; |
1116 | if (NULL == name) | 1120 | if (NULL == name) |
1117 | return; | 1121 | return; |
1118 | if (ego == my_caller_id) | 1122 | if (ego == my_caller_id) |
1119 | { | 1123 | { |
1120 | if (verbose) | 1124 | if (verbose) |
1121 | fprintf(stdout, _("Name of our ego changed to `%s'\n"), name); | 1125 | fprintf (stdout, _ ("Name of our ego changed to `%s'\n"), name); |
1122 | GNUNET_free(ego_name); | 1126 | GNUNET_free (ego_name); |
1123 | ego_name = GNUNET_strdup(name); | 1127 | ego_name = GNUNET_strdup (name); |
1124 | return; | 1128 | return; |
1125 | } | 1129 | } |
1126 | if (0 != strcmp(name, ego_name)) | 1130 | if (0 != strcmp (name, ego_name)) |
1127 | return; | 1131 | return; |
1128 | if (NULL == ego) | 1132 | if (NULL == ego) |
1129 | { | 1133 | { |
1130 | if (verbose) | 1134 | if (verbose) |
1131 | fprintf(stdout, _("Our ego `%s' was deleted!\n"), ego_name); | 1135 | fprintf (stdout, _ ("Our ego `%s' was deleted!\n"), ego_name); |
1132 | my_caller_id = NULL; | 1136 | my_caller_id = NULL; |
1133 | return; | 1137 | return; |
1134 | } | 1138 | } |
1135 | my_caller_id = ego; | 1139 | my_caller_id = ego; |
1136 | GNUNET_CONFIGURATION_set_value_string(cfg, "CONVERSATION", "LINE", line); | 1140 | GNUNET_CONFIGURATION_set_value_string (cfg, "CONVERSATION", "LINE", line); |
1137 | start_phone(); | 1141 | start_phone (); |
1138 | } | 1142 | } |
1139 | 1143 | ||
1140 | 1144 | ||
@@ -1147,28 +1151,28 @@ identity_cb(void *cls, | |||
1147 | * @param c configuration | 1151 | * @param c configuration |
1148 | */ | 1152 | */ |
1149 | static void | 1153 | static void |
1150 | run(void *cls, | 1154 | run (void *cls, |
1151 | char *const *args, | 1155 | char *const *args, |
1152 | const char *cfgfile, | 1156 | const char *cfgfile, |
1153 | const struct GNUNET_CONFIGURATION_Handle *c) | 1157 | const struct GNUNET_CONFIGURATION_Handle *c) |
1154 | { | 1158 | { |
1155 | (void)cls; | 1159 | (void) cls; |
1156 | (void)args; | 1160 | (void) args; |
1157 | (void)cfgfile; | 1161 | (void) cfgfile; |
1158 | cfg = GNUNET_CONFIGURATION_dup(c); | 1162 | cfg = GNUNET_CONFIGURATION_dup (c); |
1159 | speaker = GNUNET_SPEAKER_create_from_hardware(cfg); | 1163 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); |
1160 | mic = GNUNET_MICROPHONE_create_from_hardware(cfg); | 1164 | mic = GNUNET_MICROPHONE_create_from_hardware (cfg); |
1161 | if (NULL == ego_name) | 1165 | if (NULL == ego_name) |
1162 | { | 1166 | { |
1163 | fprintf(stderr, "%s", _("You must specify the NAME of an ego to use\n")); | 1167 | fprintf (stderr, "%s", _ ("You must specify the NAME of an ego to use\n")); |
1164 | return; | 1168 | return; |
1165 | } | 1169 | } |
1166 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); | 1170 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
1167 | handle_cmd_task = | 1171 | handle_cmd_task = |
1168 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_UI, | 1172 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, |
1169 | &handle_command, | 1173 | &handle_command, |
1170 | NULL); | 1174 | NULL); |
1171 | GNUNET_SCHEDULER_add_shutdown(&do_stop_task, NULL); | 1175 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); |
1172 | } | 1176 | } |
1173 | 1177 | ||
1174 | 1178 | ||
@@ -1180,48 +1184,48 @@ run(void *cls, | |||
1180 | * @return 0 ok, 1 on error | 1184 | * @return 0 ok, 1 on error |
1181 | */ | 1185 | */ |
1182 | int | 1186 | int |
1183 | main(int argc, char *const *argv) | 1187 | main (int argc, char *const *argv) |
1184 | { | 1188 | { |
1185 | struct GNUNET_GETOPT_CommandLineOption options[] = | 1189 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1186 | { GNUNET_GETOPT_option_string( | 1190 | { GNUNET_GETOPT_option_string ( |
1187 | 'e', | 1191 | 'e', |
1188 | "ego", | 1192 | "ego", |
1189 | "NAME", | 1193 | "NAME", |
1190 | gettext_noop("sets the NAME of the ego to use for the caller ID"), | 1194 | gettext_noop ("sets the NAME of the ego to use for the caller ID"), |
1191 | &ego_name), | 1195 | &ego_name), |
1192 | GNUNET_GETOPT_option_string('p', | 1196 | GNUNET_GETOPT_option_string ('p', |
1193 | "phone", | 1197 | "phone", |
1194 | "LINE", | 1198 | "LINE", |
1195 | gettext_noop( | 1199 | gettext_noop ( |
1196 | "sets the LINE to use for the phone"), | 1200 | "sets the LINE to use for the phone"), |
1197 | &line), | 1201 | &line), |
1198 | GNUNET_GETOPT_OPTION_END }; | 1202 | GNUNET_GETOPT_OPTION_END }; |
1199 | int ret; | 1203 | int ret; |
1200 | 1204 | ||
1201 | int flags; | 1205 | int flags; |
1202 | flags = fcntl(0, F_GETFL, 0); | 1206 | flags = fcntl (0, F_GETFL, 0); |
1203 | flags |= O_NONBLOCK; | 1207 | flags |= O_NONBLOCK; |
1204 | if (0 != fcntl(0, F_SETFL, flags)) | 1208 | if (0 != fcntl (0, F_SETFL, flags)) |
1205 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "fcntl"); | 1209 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); |
1206 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd(0); | 1210 | stdin_fh = GNUNET_DISK_get_handle_from_int_fd (0); |
1207 | 1211 | ||
1208 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 1212 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1209 | return 2; | 1213 | return 2; |
1210 | ret = | 1214 | ret = |
1211 | GNUNET_PROGRAM_run(argc, | 1215 | GNUNET_PROGRAM_run (argc, |
1212 | argv, | 1216 | argv, |
1213 | "gnunet-conversation", | 1217 | "gnunet-conversation", |
1214 | gettext_noop( | 1218 | gettext_noop ( |
1215 | "Enables having a conversation with other GNUnet users."), | 1219 | "Enables having a conversation with other GNUnet users."), |
1216 | options, | 1220 | options, |
1217 | &run, | 1221 | &run, |
1218 | NULL); | 1222 | NULL); |
1219 | GNUNET_free((void *)argv); | 1223 | GNUNET_free ((void *) argv); |
1220 | if (NULL != cfg) | 1224 | if (NULL != cfg) |
1221 | { | 1225 | { |
1222 | GNUNET_CONFIGURATION_destroy(cfg); | 1226 | GNUNET_CONFIGURATION_destroy (cfg); |
1223 | cfg = NULL; | 1227 | cfg = NULL; |
1224 | } | 1228 | } |
1225 | return (GNUNET_OK == ret) ? 0 : 1; | 1229 | return (GNUNET_OK == ret) ? 0 : 1; |
1226 | } | 1230 | } |
1227 | 1231 | ||
diff --git a/src/conversation/gnunet-helper-audio-playback-gst.c b/src/conversation/gnunet-helper-audio-playback-gst.c index 6e16b9791..48f0c5b48 100644 --- a/src/conversation/gnunet-helper-audio-playback-gst.c +++ b/src/conversation/gnunet-helper-audio-playback-gst.c | |||
@@ -81,144 +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; | 154 | break; |
155 | } | 155 | } |
156 | 156 | ||
157 | default: | 157 | default: |
158 | break; | 158 | break; |
159 | } | 159 | } |
160 | 160 | ||
161 | return TRUE; | 161 | return TRUE; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | static void | 165 | static void |
166 | signalhandler(int s) | 166 | signalhandler (int s) |
167 | { | 167 | { |
168 | quit(); | 168 | quit (); |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | static int | 172 | static int |
173 | feed_buffer_to_gst(const char *audio, size_t b_len) | 173 | feed_buffer_to_gst (const char *audio, size_t b_len) |
174 | { | 174 | { |
175 | GstBuffer *b; | 175 | GstBuffer *b; |
176 | gchar *bufspace; | 176 | gchar *bufspace; |
177 | GstFlowReturn flow; | 177 | GstFlowReturn flow; |
178 | 178 | ||
179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
180 | "Feeding %u bytes to GStreamer\n", | 180 | "Feeding %u bytes to GStreamer\n", |
181 | (unsigned int)b_len); | 181 | (unsigned int) b_len); |
182 | 182 | ||
183 | bufspace = g_memdup(audio, b_len); | 183 | bufspace = g_memdup (audio, b_len); |
184 | b = gst_buffer_new_wrapped(bufspace, b_len); | 184 | b = gst_buffer_new_wrapped (bufspace, b_len); |
185 | if (NULL == b) | 185 | if (NULL == b) |
186 | { | 186 | { |
187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
188 | "Failed to wrap a buffer\n"); | 188 | "Failed to wrap a buffer\n"); |
189 | g_free(bufspace); | 189 | g_free (bufspace); |
190 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
191 | } | 191 | } |
192 | flow = gst_app_src_push_buffer(GST_APP_SRC(source), b); | 192 | flow = gst_app_src_push_buffer (GST_APP_SRC (source), b); |
193 | /* They all return GNUNET_OK, because currently player stops when | 193 | /* They all return GNUNET_OK, because currently player stops when |
194 | * 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 |
195 | * to also stop when pipeline breaks. | 195 | * to also stop when pipeline breaks. |
196 | */ | 196 | */ |
197 | switch (flow) | 197 | switch (flow) |
198 | { | 198 | { |
199 | case GST_FLOW_OK: | 199 | case GST_FLOW_OK: |
200 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "Fed %u bytes to the pipeline\n", | 201 | "Fed %u bytes to the pipeline\n", |
202 | (unsigned int)b_len); | 202 | (unsigned int) b_len); |
203 | break; | 203 | break; |
204 | 204 | ||
205 | case GST_FLOW_FLUSHING: | 205 | case GST_FLOW_FLUSHING: |
206 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ | 206 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ |
207 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
208 | "Dropped a buffer\n"); | 208 | "Dropped a buffer\n"); |
209 | break; | 209 | break; |
210 | 210 | ||
211 | case GST_FLOW_EOS: | 211 | case GST_FLOW_EOS: |
212 | /* end of stream */ | 212 | /* end of stream */ |
213 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 213 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
214 | "EOS\n"); | 214 | "EOS\n"); |
215 | break; | 215 | break; |
216 | 216 | ||
217 | default: | 217 | default: |
218 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
219 | "Unexpected push result\n"); | 219 | "Unexpected push result\n"); |
220 | break; | 220 | break; |
221 | } | 221 | } |
222 | return GNUNET_OK; | 222 | return GNUNET_OK; |
223 | } | 223 | } |
224 | 224 | ||
@@ -232,30 +232,30 @@ feed_buffer_to_gst(const char *audio, size_t b_len) | |||
232 | * #GNUNET_SYSERR to stop further processing due to error | 232 | * #GNUNET_SYSERR to stop further processing due to error |
233 | */ | 233 | */ |
234 | static int | 234 | static int |
235 | stdin_receiver(void *cls, | 235 | stdin_receiver (void *cls, |
236 | const struct GNUNET_MessageHeader *msg) | 236 | const struct GNUNET_MessageHeader *msg) |
237 | { | 237 | { |
238 | struct AudioMessage *audio; | 238 | struct AudioMessage *audio; |
239 | size_t b_len; | 239 | size_t b_len; |
240 | 240 | ||
241 | switch (ntohs(msg->type)) | 241 | switch (ntohs (msg->type)) |
242 | { | 242 | { |
243 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 243 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
244 | audio = (struct AudioMessage *)msg; | 244 | audio = (struct AudioMessage *) msg; |
245 | 245 | ||
246 | b_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); | 246 | b_len = ntohs (audio->header.size) - sizeof(struct AudioMessage); |
247 | feed_buffer_to_gst((const char *)&audio[1], b_len); | 247 | feed_buffer_to_gst ((const char *) &audio[1], b_len); |
248 | break; | 248 | break; |
249 | 249 | ||
250 | default: | 250 | default: |
251 | break; | 251 | break; |
252 | } | 252 | } |
253 | return GNUNET_OK; | 253 | return GNUNET_OK; |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
257 | int | 257 | int |
258 | main(int argc, char **argv) | 258 | main (int argc, char **argv) |
259 | { | 259 | { |
260 | GstBus *bus; | 260 | GstBus *bus; |
261 | guint bus_watch_id; | 261 | guint bus_watch_id; |
@@ -265,140 +265,141 @@ main(int argc, char **argv) | |||
265 | 265 | ||
266 | SignalHandlerPointer inthandler, termhandler; | 266 | SignalHandlerPointer inthandler, termhandler; |
267 | #ifdef DEBUG_READ_PURE_OGG | 267 | #ifdef DEBUG_READ_PURE_OGG |
268 | int read_pure_ogg = getenv("GNUNET_READ_PURE_OGG") ? 1 : 0; | 268 | int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0; |
269 | #endif | 269 | #endif |
270 | 270 | ||
271 | inthandler = signal(SIGINT, | 271 | inthandler = signal (SIGINT, |
272 | &signalhandler); | ||
273 | termhandler = signal(SIGTERM, | ||
274 | &signalhandler); | 272 | &signalhandler); |
273 | termhandler = signal (SIGTERM, | ||
274 | &signalhandler); | ||
275 | 275 | ||
276 | /* Initialisation */ | 276 | /* Initialisation */ |
277 | gst_init(&argc, &argv); | 277 | gst_init (&argc, &argv); |
278 | 278 | ||
279 | GNUNET_assert(GNUNET_OK == | 279 | GNUNET_assert (GNUNET_OK == |
280 | GNUNET_log_setup("gnunet-helper-audio-playback-gst", | 280 | GNUNET_log_setup ("gnunet-helper-audio-playback-gst", |
281 | "WARNING", | 281 | "WARNING", |
282 | NULL)); | 282 | NULL)); |
283 | 283 | ||
284 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
285 | "Audio sink starts\n"); | 285 | "Audio sink starts\n"); |
286 | 286 | ||
287 | stdin_mst = GNUNET_MST_create(&stdin_receiver, | 287 | stdin_mst = GNUNET_MST_create (&stdin_receiver, |
288 | NULL); | 288 | NULL); |
289 | 289 | ||
290 | /* Create gstreamer elements */ | 290 | /* Create gstreamer elements */ |
291 | pipeline = gst_pipeline_new("audio-player"); | 291 | pipeline = gst_pipeline_new ("audio-player"); |
292 | source = gst_element_factory_make("appsrc", "audio-input"); | 292 | source = gst_element_factory_make ("appsrc", "audio-input"); |
293 | demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer"); | 293 | demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); |
294 | decoder = gst_element_factory_make("opusdec", "opus-decoder"); | 294 | decoder = gst_element_factory_make ("opusdec", "opus-decoder"); |
295 | conv = gst_element_factory_make("audioconvert", "converter"); | 295 | conv = gst_element_factory_make ("audioconvert", "converter"); |
296 | resampler = gst_element_factory_make("audioresample", "resampler"); | 296 | resampler = gst_element_factory_make ("audioresample", "resampler"); |
297 | sink = gst_element_factory_make("autoaudiosink", "audiosink"); | 297 | sink = gst_element_factory_make ("autoaudiosink", "audiosink"); |
298 | 298 | ||
299 | if (!pipeline || !source || !conv || !resampler || !decoder || !demuxer || !sink) | 299 | if (! pipeline || ! source || ! conv || ! resampler || ! decoder || |
300 | { | 300 | ! demuxer || ! sink) |
301 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 301 | { |
302 | "One element could not be created. Exiting.\n"); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
303 | return -1; | 303 | "One element could not be created. Exiting.\n"); |
304 | } | 304 | return -1; |
305 | 305 | } | |
306 | g_signal_connect(sink, | 306 | |
307 | "child-added", | 307 | g_signal_connect (sink, |
308 | G_CALLBACK(sink_child_added), | 308 | "child-added", |
309 | NULL); | 309 | G_CALLBACK (sink_child_added), |
310 | g_signal_connect(demuxer, | 310 | NULL); |
311 | "pad-added", | 311 | g_signal_connect (demuxer, |
312 | G_CALLBACK(ogg_pad_added), | 312 | "pad-added", |
313 | decoder); | 313 | G_CALLBACK (ogg_pad_added), |
314 | decoder); | ||
314 | 315 | ||
315 | /* Keep a reference to it, we operate on it */ | 316 | /* Keep a reference to it, we operate on it */ |
316 | gst_object_ref(GST_OBJECT(source)); | 317 | gst_object_ref (GST_OBJECT (source)); |
317 | 318 | ||
318 | /* Set up the pipeline */ | 319 | /* Set up the pipeline */ |
319 | 320 | ||
320 | /* we feed appsrc as fast as possible, it just blocks when it's full */ | 321 | /* we feed appsrc as fast as possible, it just blocks when it's full */ |
321 | g_object_set(G_OBJECT(source), | 322 | g_object_set (G_OBJECT (source), |
322 | /* "format", GST_FORMAT_TIME,*/ | 323 | /* "format", GST_FORMAT_TIME,*/ |
323 | "block", TRUE, | 324 | "block", TRUE, |
324 | "is-live", TRUE, | 325 | "is-live", TRUE, |
325 | NULL); | 326 | NULL); |
326 | 327 | ||
327 | g_object_set(G_OBJECT(decoder), | 328 | g_object_set (G_OBJECT (decoder), |
328 | /* "plc", FALSE,*/ | 329 | /* "plc", FALSE,*/ |
329 | /* "apply-gain", TRUE,*/ | 330 | /* "apply-gain", TRUE,*/ |
330 | "use-inband-fec", TRUE, | 331 | "use-inband-fec", TRUE, |
331 | NULL); | 332 | NULL); |
332 | 333 | ||
333 | /* we add a message handler */ | 334 | /* we add a message handler */ |
334 | bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); | 335 | bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); |
335 | bus_watch_id = gst_bus_add_watch(bus, bus_call, pipeline); | 336 | bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); |
336 | gst_object_unref(bus); | 337 | gst_object_unref (bus); |
337 | 338 | ||
338 | /* we add all elements into the pipeline */ | 339 | /* we add all elements into the pipeline */ |
339 | /* audio-input | ogg-demuxer | opus-decoder | converter | resampler | audiosink */ | 340 | /* audio-input | ogg-demuxer | opus-decoder | converter | resampler | audiosink */ |
340 | gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, | 341 | gst_bin_add_many (GST_BIN (pipeline), source, demuxer, decoder, conv, |
341 | resampler, sink, NULL); | 342 | resampler, sink, NULL); |
342 | 343 | ||
343 | /* we link the elements together */ | 344 | /* we link the elements together */ |
344 | gst_element_link_many(source, demuxer, NULL); | 345 | gst_element_link_many (source, demuxer, NULL); |
345 | 346 | ||
346 | /* Set the pipeline to "playing" state*/ | 347 | /* Set the pipeline to "playing" state*/ |
347 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Now playing\n"); | 348 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); |
348 | gst_element_set_state(pipeline, GST_STATE_PLAYING); | 349 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
349 | 350 | ||
350 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running...\n"); | 351 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); |
351 | /* Iterate */ | 352 | /* Iterate */ |
352 | toff = 0; | 353 | toff = 0; |
353 | while (!abort_read) | 354 | while (! abort_read) |
355 | { | ||
356 | char readbuf[MAXLINE]; | ||
357 | int ret; | ||
358 | |||
359 | ret = read (0, readbuf, sizeof(readbuf)); | ||
360 | if (0 > ret) | ||
354 | { | 361 | { |
355 | char readbuf[MAXLINE]; | 362 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
356 | int ret; | 363 | _ ("Read error from STDIN: %d %s\n"), |
357 | 364 | ret, strerror (errno)); | |
358 | ret = read(0, readbuf, sizeof(readbuf)); | 365 | break; |
359 | if (0 > ret) | 366 | } |
360 | { | 367 | toff += ret; |
361 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
362 | _("Read error from STDIN: %d %s\n"), | 369 | "Received %d bytes of audio data (total: %llu)\n", |
363 | ret, strerror(errno)); | 370 | (int) ret, |
364 | break; | 371 | (unsigned long long) toff); |
365 | } | 372 | if (0 == ret) |
366 | toff += ret; | 373 | break; |
367 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
368 | "Received %d bytes of audio data (total: %llu)\n", | ||
369 | (int)ret, | ||
370 | (unsigned long long)toff); | ||
371 | if (0 == ret) | ||
372 | break; | ||
373 | #ifdef DEBUG_READ_PURE_OGG | 374 | #ifdef DEBUG_READ_PURE_OGG |
374 | if (read_pure_ogg) | 375 | if (read_pure_ogg) |
375 | { | 376 | { |
376 | feed_buffer_to_gst(readbuf, ret); | 377 | feed_buffer_to_gst (readbuf, ret); |
377 | } | ||
378 | else | ||
379 | #endif | ||
380 | GNUNET_MST_from_buffer(stdin_mst, | ||
381 | readbuf, | ||
382 | ret, | ||
383 | GNUNET_NO, | ||
384 | GNUNET_NO); | ||
385 | } | 378 | } |
386 | GNUNET_MST_destroy(stdin_mst); | 379 | else |
387 | 380 | #endif | |
388 | signal(SIGINT, inthandler); | 381 | GNUNET_MST_from_buffer (stdin_mst, |
389 | signal(SIGINT, termhandler); | 382 | readbuf, |
390 | 383 | ret, | |
391 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 384 | GNUNET_NO, |
392 | "Returned, stopping playback\n"); | 385 | GNUNET_NO); |
393 | quit(); | 386 | } |
394 | 387 | GNUNET_MST_destroy (stdin_mst); | |
395 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 388 | |
396 | "Deleting pipeline\n"); | 389 | signal (SIGINT, inthandler); |
397 | gst_object_unref(GST_OBJECT(source)); | 390 | signal (SIGINT, termhandler); |
391 | |||
392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
393 | "Returned, stopping playback\n"); | ||
394 | quit (); | ||
395 | |||
396 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
397 | "Deleting pipeline\n"); | ||
398 | gst_object_unref (GST_OBJECT (source)); | ||
398 | source = NULL; | 399 | source = NULL; |
399 | gst_object_unref(GST_OBJECT(pipeline)); | 400 | gst_object_unref (GST_OBJECT (pipeline)); |
400 | pipeline = NULL; | 401 | pipeline = NULL; |
401 | g_source_remove(bus_watch_id); | 402 | g_source_remove (bus_watch_id); |
402 | 403 | ||
403 | return 0; | 404 | return 0; |
404 | } | 405 | } |
diff --git a/src/conversation/gnunet-helper-audio-playback.c b/src/conversation/gnunet-helper-audio-playback.c index 34e61c100..d7e1cd036 100644 --- a/src/conversation/gnunet-helper-audio-playback.c +++ b/src/conversation/gnunet-helper-audio-playback.c | |||
@@ -124,7 +124,8 @@ 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 | { | ||
128 | uint8_t magic[8]; | 129 | uint8_t magic[8]; |
129 | uint8_t version; | 130 | uint8_t version; |
130 | uint8_t channels; | 131 | uint8_t channels; |
@@ -142,71 +143,71 @@ GNUNET_NETWORK_STRUCT_END | |||
142 | * elsewhere in the code. | 143 | * elsewhere in the code. |
143 | */ | 144 | */ |
144 | static OpusDecoder * | 145 | static OpusDecoder * |
145 | process_header(ogg_packet *op) | 146 | process_header (ogg_packet *op) |
146 | { | 147 | { |
147 | int err; | 148 | int err; |
148 | OpusDecoder *dec; | 149 | OpusDecoder *dec; |
149 | struct OpusHeadPacket header; | 150 | struct OpusHeadPacket header; |
150 | 151 | ||
151 | if (((unsigned int)op->bytes) < sizeof(header)) | 152 | if (((unsigned int) op->bytes) < sizeof(header)) |
152 | return NULL; | 153 | return NULL; |
153 | GNUNET_memcpy(&header, | 154 | GNUNET_memcpy (&header, |
154 | op->packet, | 155 | op->packet, |
155 | sizeof(header)); | 156 | sizeof(header)); |
156 | header.preskip = GNUNET_le16toh(header.preskip); | 157 | header.preskip = GNUNET_le16toh (header.preskip); |
157 | header.sampling_rate = GNUNET_le32toh(header.sampling_rate); | 158 | header.sampling_rate = GNUNET_le32toh (header.sampling_rate); |
158 | header.gain = GNUNET_le16toh(header.gain); | 159 | header.gain = GNUNET_le16toh (header.gain); |
159 | 160 | ||
160 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
161 | "Header: v%u, %u-ch, skip %u, %uHz, %u gain\n", | 162 | "Header: v%u, %u-ch, skip %u, %uHz, %u gain\n", |
162 | header.version, | 163 | header.version, |
163 | header.channels, | 164 | header.channels, |
164 | header.preskip, | 165 | header.preskip, |
165 | header.sampling_rate, | 166 | header.sampling_rate, |
166 | header.gain); | 167 | header.gain); |
167 | channels = header.channels; | 168 | channels = header.channels; |
168 | preskip = header.preskip; | 169 | preskip = header.preskip; |
169 | 170 | ||
170 | if (header.channel_mapping != 0) | 171 | if (header.channel_mapping != 0) |
171 | { | 172 | { |
172 | fprintf(stderr, | 173 | fprintf (stderr, |
173 | "This implementation does not support non-mono streams\n"); | 174 | "This implementation does not support non-mono streams\n"); |
174 | return NULL; | 175 | return NULL; |
175 | } | 176 | } |
176 | 177 | ||
177 | dec = opus_decoder_create(SAMPLING_RATE, channels, &err); | 178 | dec = opus_decoder_create (SAMPLING_RATE, channels, &err); |
178 | if (OPUS_OK != err) | 179 | 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) | ||
179 | { | 202 | { |
180 | fprintf(stderr, | 203 | gain = pow (10.0, gainadj / 5120.0); |
181 | "Cannot create encoder: %s\n", | ||
182 | opus_strerror(err)); | ||
183 | return NULL; | ||
184 | } | 204 | } |
185 | if (!dec) | 205 | else if (OPUS_OK != err) |
186 | { | 206 | { |
187 | fprintf(stderr, | 207 | fprintf (stderr, "Error setting gain: %s\n", opus_strerror (err)); |
188 | "Decoder initialization failed: %s\n", | ||
189 | opus_strerror(err)); | ||
190 | return NULL; | 208 | return NULL; |
191 | } | 209 | } |
192 | 210 | } | |
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 | } | ||
210 | 211 | ||
211 | return dec; | 212 | return dec; |
212 | } | 213 | } |
@@ -214,58 +215,58 @@ process_header(ogg_packet *op) | |||
214 | 215 | ||
215 | #ifdef DEBUG_DUMP_DECODED_OGG | 216 | #ifdef DEBUG_DUMP_DECODED_OGG |
216 | static size_t | 217 | static size_t |
217 | fwrite_le32(opus_int32 i32, FILE *file) | 218 | fwrite_le32 (opus_int32 i32, FILE *file) |
218 | { | 219 | { |
219 | unsigned char buf[4]; | 220 | unsigned char buf[4]; |
220 | 221 | ||
221 | buf[0] = (unsigned char)(i32 & 0xFF); | 222 | buf[0] = (unsigned char) (i32 & 0xFF); |
222 | buf[1] = (unsigned char)(i32 >> 8 & 0xFF); | 223 | buf[1] = (unsigned char) (i32 >> 8 & 0xFF); |
223 | buf[2] = (unsigned char)(i32 >> 16 & 0xFF); | 224 | buf[2] = (unsigned char) (i32 >> 16 & 0xFF); |
224 | buf[3] = (unsigned char)(i32 >> 24 & 0xFF); | 225 | buf[3] = (unsigned char) (i32 >> 24 & 0xFF); |
225 | return fwrite(buf, 4, 1, file); | 226 | return fwrite (buf, 4, 1, file); |
226 | } | 227 | } |
227 | 228 | ||
228 | 229 | ||
229 | static size_t | 230 | static size_t |
230 | fwrite_le16(int i16, FILE *file) | 231 | fwrite_le16 (int i16, FILE *file) |
231 | { | 232 | { |
232 | unsigned char buf[2]; | 233 | unsigned char buf[2]; |
233 | 234 | ||
234 | buf[0] = (unsigned char)(i16 & 0xFF); | 235 | buf[0] = (unsigned char) (i16 & 0xFF); |
235 | buf[1] = (unsigned char)(i16 >> 8 & 0xFF); | 236 | buf[1] = (unsigned char) (i16 >> 8 & 0xFF); |
236 | return fwrite(buf, 2, 1, file); | 237 | return fwrite (buf, 2, 1, file); |
237 | } | 238 | } |
238 | 239 | ||
239 | 240 | ||
240 | static int | 241 | static int |
241 | write_wav_header() | 242 | write_wav_header () |
242 | { | 243 | { |
243 | int ret; | 244 | int ret; |
244 | FILE *file = stdout; | 245 | FILE *file = stdout; |
245 | 246 | ||
246 | ret = fprintf(file, "RIFF") >= 0; | 247 | ret = fprintf (file, "RIFF") >= 0; |
247 | ret &= fwrite_le32(0x7fffffff, file); | 248 | ret &= fwrite_le32 (0x7fffffff, file); |
248 | 249 | ||
249 | ret &= fprintf(file, "WAVEfmt ") >= 0; | 250 | ret &= fprintf (file, "WAVEfmt ") >= 0; |
250 | ret &= fwrite_le32(16, file); | 251 | ret &= fwrite_le32 (16, file); |
251 | ret &= fwrite_le16(1, file); | 252 | ret &= fwrite_le16 (1, file); |
252 | ret &= fwrite_le16(channels, file); | 253 | ret &= fwrite_le16 (channels, file); |
253 | ret &= fwrite_le32(SAMPLING_RATE, file); | 254 | ret &= fwrite_le32 (SAMPLING_RATE, file); |
254 | ret &= fwrite_le32(2 * channels * SAMPLING_RATE, file); | 255 | ret &= fwrite_le32 (2 * channels * SAMPLING_RATE, file); |
255 | ret &= fwrite_le16(2 * channels, file); | 256 | ret &= fwrite_le16 (2 * channels, file); |
256 | ret &= fwrite_le16(16, file); | 257 | ret &= fwrite_le16 (16, file); |
257 | 258 | ||
258 | ret &= fprintf(file, "data") >= 0; | 259 | ret &= fprintf (file, "data") >= 0; |
259 | ret &= fwrite_le32(0x7fffffff, file); | 260 | ret &= fwrite_le32 (0x7fffffff, file); |
260 | 261 | ||
261 | return !ret ? -1 : 16; | 262 | return ! ret ? -1 : 16; |
262 | } | 263 | } |
263 | 264 | ||
264 | #endif | 265 | #endif |
265 | 266 | ||
266 | 267 | ||
267 | static int64_t | 268 | static int64_t |
268 | audio_write(int64_t maxout) | 269 | audio_write (int64_t maxout) |
269 | { | 270 | { |
270 | int64_t sampout = 0; | 271 | int64_t sampout = 0; |
271 | int tmp_skip; | 272 | int tmp_skip; |
@@ -276,66 +277,67 @@ audio_write(int64_t maxout) | |||
276 | #ifdef DEBUG_DUMP_DECODED_OGG | 277 | #ifdef DEBUG_DUMP_DECODED_OGG |
277 | static int wrote_wav_header; | 278 | static int wrote_wav_header; |
278 | 279 | ||
279 | if (dump_to_stdout && !wrote_wav_header) | 280 | if (dump_to_stdout && ! wrote_wav_header) |
280 | { | 281 | { |
281 | write_wav_header(); | 282 | write_wav_header (); |
282 | wrote_wav_header = 1; | 283 | wrote_wav_header = 1; |
283 | } | 284 | } |
284 | #endif | 285 | #endif |
285 | maxout = 0 > maxout ? 0 : maxout; | 286 | maxout = 0 > maxout ? 0 : maxout; |
286 | do | 287 | do |
288 | { | ||
289 | tmp_skip = (preskip > frame_size) ? (int) frame_size : preskip; | ||
290 | preskip -= tmp_skip; | ||
291 | output = pcm_buffer + channels * tmp_skip; | ||
292 | out_len = frame_size - tmp_skip; | ||
293 | if (out_len > MAX_FRAME_SIZE) | ||
294 | exit (6); | ||
295 | frame_size = 0; | ||
296 | |||
297 | to_write = out_len < maxout ? out_len : (unsigned) maxout; | ||
298 | if (0 < maxout) | ||
287 | { | 299 | { |
288 | tmp_skip = (preskip > frame_size) ? (int)frame_size : preskip; | 300 | int64_t wrote = 0; |
289 | preskip -= tmp_skip; | 301 | wrote = to_write; |
290 | output = pcm_buffer + channels * tmp_skip; | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | out_len = frame_size - tmp_skip; | 303 | "Writing %u * %u * %u = %llu bytes into PA\n", |
292 | if (out_len > MAX_FRAME_SIZE) | 304 | to_write, |
293 | exit(6); | 305 | channels, |
294 | frame_size = 0; | 306 | (unsigned int) sizeof(float), |
295 | 307 | (unsigned long long) (to_write * channels * sizeof(float))); | |
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))); | ||
307 | #ifdef DEBUG_DUMP_DECODED_OGG | 308 | #ifdef DEBUG_DUMP_DECODED_OGG |
308 | if (dump_to_stdout) | 309 | if (dump_to_stdout) |
309 | { | 310 | { |
310 | # define fminf(_x, _y) ((_x) < (_y) ? (_x) : (_y)) | 311 | # define fminf(_x, _y) ((_x) < (_y) ? (_x) : (_y)) |
311 | # define fmaxf(_x, _y) ((_x) > (_y) ? (_x) : (_y)) | 312 | # define fmaxf(_x, _y) ((_x) > (_y) ? (_x) : (_y)) |
312 | # define float2int(flt) ((int)(floor(.5 + flt))) | 313 | # define float2int(flt) ((int) (floor (.5 + flt))) |
313 | int i; | 314 | int i; |
314 | int16_t *out = alloca(sizeof(short) * MAX_FRAME_SIZE * channels); | 315 | int16_t *out = alloca (sizeof(short) * MAX_FRAME_SIZE * channels); |
315 | for (i = 0; i < (int)out_len * channels; i++) | 316 | for (i = 0; i < (int) out_len * channels; i++) |
316 | out[i] = (short)float2int(fmaxf(-32768, fminf(output[i] * 32768.f, 32767))); | 317 | out[i] = (short) float2int (fmaxf (-32768, fminf (output[i] * 32768.f, |
317 | 318 | 32767))); | |
318 | fwrite(out, 2 * channels, out_len < maxout ? out_len : maxout, stdout); | 319 | |
319 | } | 320 | fwrite (out, 2 * channels, out_len < maxout ? out_len : maxout, stdout); |
320 | else | 321 | } |
322 | else | ||
321 | #endif | 323 | #endif |
322 | if (pa_stream_write | 324 | if (pa_stream_write |
323 | (stream_out, output, to_write * channels * sizeof(float), NULL, 0, | 325 | (stream_out, output, to_write * channels * sizeof(float), NULL, 0, |
324 | PA_SEEK_RELATIVE) < 0) | 326 | PA_SEEK_RELATIVE) < 0) |
325 | { | 327 | { |
326 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
327 | _("pa_stream_write() failed: %s\n"), | 329 | _ ("pa_stream_write() failed: %s\n"), |
328 | pa_strerror(pa_context_errno(context))); | 330 | pa_strerror (pa_context_errno (context))); |
329 | } | 331 | } |
330 | sampout += wrote; | 332 | sampout += wrote; |
331 | maxout -= wrote; | 333 | maxout -= wrote; |
332 | } | ||
333 | } | 334 | } |
335 | } | ||
334 | while (0 < frame_size && 0 < maxout); | 336 | while (0 < frame_size && 0 < maxout); |
335 | 337 | ||
336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
337 | "Wrote %" PRId64 " samples\n", | 339 | "Wrote %" PRId64 " samples\n", |
338 | sampout); | 340 | sampout); |
339 | return sampout; | 341 | return sampout; |
340 | } | 342 | } |
341 | 343 | ||
@@ -344,16 +346,16 @@ audio_write(int64_t maxout) | |||
344 | * Pulseaudio shutdown task | 346 | * Pulseaudio shutdown task |
345 | */ | 347 | */ |
346 | static void | 348 | static void |
347 | quit(int ret) | 349 | quit (int ret) |
348 | { | 350 | { |
349 | mainloop_api->quit(mainloop_api, | 351 | mainloop_api->quit (mainloop_api, |
350 | ret); | 352 | ret); |
351 | exit(ret); | 353 | exit (ret); |
352 | } | 354 | } |
353 | 355 | ||
354 | 356 | ||
355 | static void | 357 | static void |
356 | ogg_demux_and_decode() | 358 | ogg_demux_and_decode () |
357 | { | 359 | { |
358 | ogg_page og; | 360 | ogg_page og; |
359 | static int stream_init; | 361 | static int stream_init; |
@@ -368,189 +370,204 @@ ogg_demux_and_decode() | |||
368 | static int total_links; | 370 | static int total_links; |
369 | static int gran_offset; | 371 | static int gran_offset; |
370 | 372 | ||
371 | while (1 == ogg_sync_pageout(&oy, &og)) | 373 | while (1 == ogg_sync_pageout (&oy, &og)) |
374 | { | ||
375 | if (0 == stream_init) | ||
376 | { | ||
377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
378 | "Initialized the stream\n"); | ||
379 | ogg_stream_init (&os, ogg_page_serialno (&og)); | ||
380 | stream_init = 1; | ||
381 | } | ||
382 | if (ogg_page_serialno (&og) != os.serialno) | ||
383 | { | ||
384 | /* so all streams are read. */ | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
386 | "Re-set serial number\n"); | ||
387 | ogg_stream_reset_serialno (&os, ogg_page_serialno (&og)); | ||
388 | } | ||
389 | /*Add page to the bitstream*/ | ||
390 | ogg_stream_pagein (&os, &og); | ||
391 | page_granule = ogg_page_granulepos (&og); | ||
392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
393 | "Reading page that ends at %" PRId64 "\n", | ||
394 | page_granule); | ||
395 | /*Extract all available packets*/ | ||
396 | while (1 == ogg_stream_packetout (&os, &op)) | ||
372 | { | 397 | { |
373 | if (0 == stream_init) | 398 | /*OggOpus streams are identified by a magic string in the initial |
399 | stream header.*/ | ||
400 | if (op.b_o_s &&(op.bytes >= 8) && ! memcmp (op.packet, "OpusHead", 8)) | ||
401 | { | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
403 | "Got Opus Header\n"); | ||
404 | if (has_opus_stream && has_tags_packet) | ||
374 | { | 405 | { |
375 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 406 | /*If we're seeing another BOS OpusHead now it means |
376 | "Initialized the stream\n"); | 407 | the stream is chained without an EOS. |
377 | ogg_stream_init(&os, ogg_page_serialno(&og)); | 408 | This can easily happen if record helper is terminated unexpectedly. |
378 | stream_init = 1; | 409 | */ |
410 | has_opus_stream = 0; | ||
411 | if (dec) | ||
412 | opus_decoder_destroy (dec); | ||
413 | dec = NULL; | ||
414 | fprintf (stderr, | ||
415 | "\nWarning: stream %" PRId64 | ||
416 | " ended without EOS and a new stream began.\n", | ||
417 | (int64_t) os.serialno); | ||
379 | } | 418 | } |
380 | if (ogg_page_serialno(&og) != os.serialno) | 419 | if (! has_opus_stream) |
381 | { | 420 | { |
382 | /* so all streams are read. */ | 421 | if ((packet_count > 0) &&(opus_serialno == os.serialno) ) |
383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 422 | { |
384 | "Re-set serial number\n"); | 423 | fprintf (stderr, |
385 | ogg_stream_reset_serialno(&os, ogg_page_serialno(&og)); | 424 | "\nError: Apparent chaining without changing serial number (%" |
425 | PRId64 "==%" PRId64 ").\n", | ||
426 | (int64_t) opus_serialno, (int64_t) os.serialno); | ||
427 | quit (1); | ||
428 | } | ||
429 | opus_serialno = os.serialno; | ||
430 | has_opus_stream = 1; | ||
431 | has_tags_packet = 0; | ||
432 | link_out = 0; | ||
433 | packet_count = 0; | ||
434 | eos = 0; | ||
435 | total_links++; | ||
436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
437 | "Got header for stream %" PRId64 ", this is %dth link\n", | ||
438 | (int64_t) opus_serialno, total_links); | ||
386 | } | 439 | } |
387 | /*Add page to the bitstream*/ | 440 | else |
388 | ogg_stream_pagein(&os, &og); | ||
389 | page_granule = ogg_page_granulepos(&og); | ||
390 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
391 | "Reading page that ends at %" PRId64 "\n", | ||
392 | page_granule); | ||
393 | /*Extract all available packets*/ | ||
394 | while (1 == ogg_stream_packetout(&os, &op)) | ||
395 | { | 441 | { |
396 | /*OggOpus streams are identified by a magic string in the initial | 442 | fprintf (stderr, "\nWarning: ignoring opus stream %" PRId64 "\n", |
397 | stream header.*/ | 443 | (int64_t) os.serialno); |
398 | if (op.b_o_s && op.bytes >= 8 && !memcmp(op.packet, "OpusHead", 8)) | ||
399 | { | ||
400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
401 | "Got Opus Header\n"); | ||
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++; | ||
545 | } | 444 | } |
546 | if (eos) | 445 | } |
446 | if (! has_opus_stream ||(os.serialno != opus_serialno) ) | ||
447 | { | ||
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
449 | "breaking out\n"); | ||
450 | break; | ||
451 | } | ||
452 | /*If first packet in a logical stream, process the Opus header*/ | ||
453 | if (0 == packet_count) | ||
454 | { | ||
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
456 | "Decoding header\n"); | ||
457 | dec = process_header (&op); | ||
458 | if (! dec) | ||
459 | quit (1); | ||
460 | |||
461 | if ((0 != ogg_stream_packetout (&os, &op)) ||(255 == | ||
462 | og.header[og.header_len | ||
463 | - 1]) ) | ||
547 | { | 464 | { |
548 | has_opus_stream = 0; | 465 | /*The format specifies that the initial header and tags packets are on their |
549 | if (dec) | 466 | own pages. To aid implementors in discovering that their files are wrong |
550 | opus_decoder_destroy(dec); | 467 | we reject them explicitly here. In some player designs files like this would |
551 | dec = NULL; | 468 | fail even without an explicit test.*/ |
469 | fprintf (stderr, | ||
470 | "Extra packets on initial header page. Invalid stream.\n"); | ||
471 | quit (1); | ||
472 | } | ||
473 | |||
474 | /*Remember how many samples at the front we were told to skip | ||
475 | so that we can adjust the timestamp counting.*/ | ||
476 | gran_offset = preskip; | ||
477 | |||
478 | if (! pcm_buffer) | ||
479 | { | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
481 | "Allocating %u * %u * %u = %llu bytes of buffer space\n", | ||
482 | MAX_FRAME_SIZE, | ||
483 | channels, | ||
484 | (unsigned int) sizeof(float), | ||
485 | (unsigned long long) (MAX_FRAME_SIZE * channels | ||
486 | * sizeof(float))); | ||
487 | pcm_buffer = pa_xmalloc (sizeof(float) * MAX_FRAME_SIZE * channels); | ||
488 | } | ||
489 | } | ||
490 | else if (1 == packet_count) | ||
491 | { | ||
492 | has_tags_packet = 1; | ||
493 | if ((0 != ogg_stream_packetout (&os, &op)) ||(255 == | ||
494 | og.header[og.header_len | ||
495 | - 1]) ) | ||
496 | { | ||
497 | fprintf (stderr, | ||
498 | "Extra packets on initial tags page. Invalid stream.\n"); | ||
499 | quit (1); | ||
552 | } | 500 | } |
501 | } | ||
502 | else | ||
503 | { | ||
504 | int ret; | ||
505 | int64_t maxout; | ||
506 | int64_t outsamp; | ||
507 | |||
508 | /*End of stream condition*/ | ||
509 | if (op.e_o_s &&(os.serialno == opus_serialno) ) | ||
510 | { | ||
511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
512 | "Got EOS\n"); | ||
513 | eos = 1; /* don't care for anything except opus eos */ | ||
514 | } | ||
515 | |||
516 | /*Decode Opus packet*/ | ||
517 | ret = opus_decode_float (dec, | ||
518 | (const unsigned char *) op.packet, | ||
519 | op.bytes, | ||
520 | pcm_buffer, | ||
521 | MAX_FRAME_SIZE, 0); | ||
522 | |||
523 | /*If the decoder returned less than zero, we have an error.*/ | ||
524 | if (0 > ret) | ||
525 | { | ||
526 | fprintf (stderr, "Decoding error: %s\n", opus_strerror (ret)); | ||
527 | break; | ||
528 | } | ||
529 | frame_size = ret; | ||
530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
531 | "Decoded %d bytes/channel (%d bytes) from %u compressed bytes\n", | ||
532 | ret, | ||
533 | ret * channels, | ||
534 | (unsigned int) op.bytes); | ||
535 | |||
536 | /*Apply header gain, if we're not using an opus library new | ||
537 | enough to do this internally.*/ | ||
538 | if (0 != gain) | ||
539 | { | ||
540 | int i; | ||
541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
542 | "Applying gain %f\n", | ||
543 | gain); | ||
544 | for (i = 0; i < frame_size * channels; i++) | ||
545 | pcm_buffer[i] *= gain; | ||
546 | } | ||
547 | |||
548 | /*This handles making sure that our output duration respects | ||
549 | the final end-trim by not letting the output sample count | ||
550 | get ahead of the granpos indicated value.*/ | ||
551 | maxout = ((page_granule - gran_offset) * SAMPLING_RATE / 48000) | ||
552 | - link_out; | ||
553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
554 | "Writing audio packet %" PRId64 ", at most %" PRId64 | ||
555 | " samples\n", | ||
556 | packet_count, maxout); | ||
557 | |||
558 | outsamp = audio_write (0 > maxout ? 0 : maxout); | ||
559 | link_out += outsamp; | ||
560 | } | ||
561 | packet_count++; | ||
553 | } | 562 | } |
563 | if (eos) | ||
564 | { | ||
565 | has_opus_stream = 0; | ||
566 | if (dec) | ||
567 | opus_decoder_destroy (dec); | ||
568 | dec = NULL; | ||
569 | } | ||
570 | } | ||
554 | } | 571 | } |
555 | 572 | ||
556 | 573 | ||
@@ -563,32 +580,32 @@ ogg_demux_and_decode() | |||
563 | * #GNUNET_SYSERR to stop further processing due to error | 580 | * #GNUNET_SYSERR to stop further processing due to error |
564 | */ | 581 | */ |
565 | static int | 582 | static int |
566 | stdin_receiver(void *cls, | 583 | stdin_receiver (void *cls, |
567 | const struct GNUNET_MessageHeader *msg) | 584 | const struct GNUNET_MessageHeader *msg) |
568 | { | 585 | { |
569 | struct AudioMessage *audio; | 586 | struct AudioMessage *audio; |
570 | char *data; | 587 | char *data; |
571 | size_t payload_len; | 588 | size_t payload_len; |
572 | 589 | ||
573 | (void)cls; | 590 | (void) cls; |
574 | switch (ntohs(msg->type)) | 591 | switch (ntohs (msg->type)) |
575 | { | 592 | { |
576 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 593 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
577 | audio = (struct AudioMessage *)msg; | 594 | audio = (struct AudioMessage *) msg; |
578 | payload_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); | 595 | payload_len = ntohs (audio->header.size) - sizeof(struct AudioMessage); |
579 | 596 | ||
580 | /*Get the ogg buffer for writing*/ | 597 | /*Get the ogg buffer for writing*/ |
581 | data = ogg_sync_buffer(&oy, payload_len); | 598 | data = ogg_sync_buffer (&oy, payload_len); |
582 | /*Read bitstream from input file*/ | 599 | /*Read bitstream from input file*/ |
583 | GNUNET_memcpy(data, (const unsigned char *)&audio[1], payload_len); | 600 | GNUNET_memcpy (data, (const unsigned char *) &audio[1], payload_len); |
584 | ogg_sync_wrote(&oy, payload_len); | 601 | ogg_sync_wrote (&oy, payload_len); |
585 | 602 | ||
586 | ogg_demux_and_decode(); | 603 | ogg_demux_and_decode (); |
587 | break; | 604 | break; |
588 | 605 | ||
589 | default: | 606 | default: |
590 | break; | 607 | break; |
591 | } | 608 | } |
592 | return GNUNET_OK; | 609 | return GNUNET_OK; |
593 | } | 610 | } |
594 | 611 | ||
@@ -597,20 +614,20 @@ stdin_receiver(void *cls, | |||
597 | * Callback when data is there for playback | 614 | * Callback when data is there for playback |
598 | */ | 615 | */ |
599 | static void | 616 | static void |
600 | stream_write_callback(pa_stream *s, | 617 | stream_write_callback (pa_stream *s, |
601 | size_t length, | 618 | size_t length, |
602 | void *userdata) | 619 | void *userdata) |
603 | { | 620 | { |
604 | /* unblock 'main' */ | 621 | /* unblock 'main' */ |
605 | (void)userdata; | 622 | (void) userdata; |
606 | (void)length; | 623 | (void) length; |
607 | (void)s; | 624 | (void) s; |
608 | if (-1 != ready_pipe[1]) | 625 | if (-1 != ready_pipe[1]) |
609 | { | 626 | { |
610 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
611 | "Unblocking main loop!\n"); | 628 | "Unblocking main loop!\n"); |
612 | (void)write(ready_pipe[1], "r", 1); | 629 | (void) write (ready_pipe[1], "r", 1); |
613 | } | 630 | } |
614 | } | 631 | } |
615 | 632 | ||
616 | 633 | ||
@@ -618,18 +635,18 @@ stream_write_callback(pa_stream *s, | |||
618 | * Exit callback for SIGTERM and SIGINT | 635 | * Exit callback for SIGTERM and SIGINT |
619 | */ | 636 | */ |
620 | static void | 637 | static void |
621 | exit_signal_callback(pa_mainloop_api *m, | 638 | exit_signal_callback (pa_mainloop_api *m, |
622 | pa_signal_event *e, | 639 | pa_signal_event *e, |
623 | int sig, | 640 | int sig, |
624 | void *userdata) | 641 | void *userdata) |
625 | { | 642 | { |
626 | (void)m; | 643 | (void) m; |
627 | (void)e; | 644 | (void) e; |
628 | (void)sig; | 645 | (void) sig; |
629 | (void)userdata; | 646 | (void) userdata; |
630 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 647 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
631 | _("gnunet-helper-audio-playback - Got signal, exiting\n")); | 648 | _ ("gnunet-helper-audio-playback - Got signal, exiting\n")); |
632 | quit(1); | 649 | quit (1); |
633 | } | 650 | } |
634 | 651 | ||
635 | 652 | ||
@@ -637,64 +654,66 @@ exit_signal_callback(pa_mainloop_api *m, | |||
637 | * Pulseaudio stream state callback | 654 | * Pulseaudio stream state callback |
638 | */ | 655 | */ |
639 | static void | 656 | static void |
640 | context_state_callback(pa_context *c, | 657 | context_state_callback (pa_context *c, |
641 | void *userdata) | 658 | void *userdata) |
642 | { | 659 | { |
643 | int p; | 660 | int p; |
644 | 661 | ||
645 | (void)userdata; | 662 | (void) userdata; |
646 | GNUNET_assert(NULL != c); | 663 | GNUNET_assert (NULL != c); |
647 | switch (pa_context_get_state(c)) | 664 | switch (pa_context_get_state (c)) |
648 | { | 665 | { |
649 | case PA_CONTEXT_CONNECTING: | 666 | case PA_CONTEXT_CONNECTING: |
650 | case PA_CONTEXT_AUTHORIZING: | 667 | case PA_CONTEXT_AUTHORIZING: |
651 | case PA_CONTEXT_SETTING_NAME: | 668 | case PA_CONTEXT_SETTING_NAME: |
652 | break; | 669 | break; |
653 | 670 | ||
654 | case PA_CONTEXT_READY: | 671 | case PA_CONTEXT_READY: |
655 | { | 672 | { |
656 | GNUNET_assert(!stream_out); | 673 | GNUNET_assert (! stream_out); |
657 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 674 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
658 | _("Connection established.\n")); | 675 | _ ("Connection established.\n")); |
659 | if (!(stream_out = | 676 | if (! (stream_out = |
660 | pa_stream_new(c, "GNUNET VoIP playback", &sample_spec, NULL))) | 677 | pa_stream_new (c, "GNUNET VoIP playback", &sample_spec, NULL))) |
661 | { | 678 | { |
662 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
663 | _("pa_stream_new() failed: %s\n"), | 680 | _ ("pa_stream_new() failed: %s\n"), |
664 | pa_strerror(pa_context_errno(c))); | 681 | pa_strerror (pa_context_errno (c))); |
665 | goto fail; | 682 | goto fail; |
666 | } | 683 | } |
667 | pa_stream_set_write_callback(stream_out, | 684 | pa_stream_set_write_callback (stream_out, |
668 | &stream_write_callback, | 685 | &stream_write_callback, |
669 | NULL); | 686 | NULL); |
670 | if ((p = | 687 | if ((p = |
671 | pa_stream_connect_playback(stream_out, NULL, | 688 | pa_stream_connect_playback (stream_out, NULL, |
672 | NULL, | 689 | NULL, |
673 | PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE, | 690 | PA_STREAM_ADJUST_LATENCY |
674 | NULL, NULL)) < 0) | 691 | | PA_STREAM_INTERPOLATE_TIMING |
675 | { | 692 | | PA_STREAM_AUTO_TIMING_UPDATE, |
676 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 693 | NULL, NULL)) < 0) |
677 | _("pa_stream_connect_playback() failed: %s\n"), | 694 | { |
678 | pa_strerror(pa_context_errno(c))); | 695 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
679 | goto fail; | 696 | _ ("pa_stream_connect_playback() failed: %s\n"), |
680 | } | 697 | pa_strerror (pa_context_errno (c))); |
698 | goto fail; | ||
699 | } | ||
681 | break; | 700 | break; |
682 | } | 701 | } |
683 | 702 | ||
684 | case PA_CONTEXT_TERMINATED: | 703 | case PA_CONTEXT_TERMINATED: |
685 | quit(0); | 704 | quit (0); |
686 | break; | 705 | break; |
687 | 706 | ||
688 | case PA_CONTEXT_FAILED: | 707 | case PA_CONTEXT_FAILED: |
689 | default: | 708 | default: |
690 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 709 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
691 | _("Connection failure: %s\n"), | 710 | _ ("Connection failure: %s\n"), |
692 | pa_strerror(pa_context_errno(c))); | 711 | pa_strerror (pa_context_errno (c))); |
693 | goto fail; | 712 | goto fail; |
694 | } | 713 | } |
695 | return; | 714 | return; |
696 | fail: | 715 | fail: |
697 | quit(1); | 716 | quit (1); |
698 | } | 717 | } |
699 | 718 | ||
700 | 719 | ||
@@ -702,66 +721,66 @@ fail: | |||
702 | * Pulseaudio initialization | 721 | * Pulseaudio initialization |
703 | */ | 722 | */ |
704 | static void | 723 | static void |
705 | pa_init() | 724 | pa_init () |
706 | { | 725 | { |
707 | int r; | 726 | int r; |
708 | 727 | ||
709 | if (!pa_sample_spec_valid(&sample_spec)) | 728 | if (! pa_sample_spec_valid (&sample_spec)) |
710 | { | 729 | { |
711 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 730 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
712 | _("Wrong Spec\n")); | 731 | _ ("Wrong Spec\n")); |
713 | } | 732 | } |
714 | /* set up threaded playback mainloop */ | 733 | /* set up threaded playback mainloop */ |
715 | if (!(m = pa_threaded_mainloop_new())) | 734 | if (! (m = pa_threaded_mainloop_new ())) |
716 | { | 735 | { |
717 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 736 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
718 | _("pa_mainloop_new() failed.\n")); | 737 | _ ("pa_mainloop_new() failed.\n")); |
719 | } | 738 | } |
720 | mainloop_api = pa_threaded_mainloop_get_api(m); | 739 | mainloop_api = pa_threaded_mainloop_get_api (m); |
721 | /* listen to signals */ | 740 | /* listen to signals */ |
722 | r = pa_signal_init(mainloop_api); | 741 | r = pa_signal_init (mainloop_api); |
723 | GNUNET_assert(r == 0); | 742 | GNUNET_assert (r == 0); |
724 | pa_signal_new(SIGINT, exit_signal_callback, NULL); | 743 | pa_signal_new (SIGINT, exit_signal_callback, NULL); |
725 | pa_signal_new(SIGTERM, exit_signal_callback, NULL); | 744 | pa_signal_new (SIGTERM, exit_signal_callback, NULL); |
726 | 745 | ||
727 | 746 | ||
728 | /* connect to the main pulseaudio context */ | 747 | /* connect to the main pulseaudio context */ |
729 | if (!(context = pa_context_new(mainloop_api, "GNUnet VoIP"))) | 748 | if (! (context = pa_context_new (mainloop_api, "GNUnet VoIP"))) |
730 | { | 749 | { |
731 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 750 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
732 | _("pa_context_new() failed.\n")); | 751 | _ ("pa_context_new() failed.\n")); |
733 | } | 752 | } |
734 | pa_context_set_state_callback(context, context_state_callback, NULL); | 753 | pa_context_set_state_callback (context, context_state_callback, NULL); |
735 | 754 | ||
736 | if (pa_context_connect(context, NULL, 0, NULL) < 0) | 755 | if (pa_context_connect (context, NULL, 0, NULL) < 0) |
737 | { | 756 | { |
738 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 757 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
739 | _("pa_context_connect() failed: %s\n"), | 758 | _ ("pa_context_connect() failed: %s\n"), |
740 | pa_strerror(pa_context_errno(context))); | 759 | pa_strerror (pa_context_errno (context))); |
741 | } | 760 | } |
742 | if (pa_threaded_mainloop_start(m) < 0) | 761 | if (pa_threaded_mainloop_start (m) < 0) |
743 | { | 762 | { |
744 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 763 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
745 | _("pa_mainloop_run() failed.\n")); | 764 | _ ("pa_mainloop_run() failed.\n")); |
746 | } | 765 | } |
747 | } | 766 | } |
748 | 767 | ||
749 | 768 | ||
750 | static void | 769 | static void |
751 | ogg_init() | 770 | ogg_init () |
752 | { | 771 | { |
753 | ogg_sync_init(&oy); | 772 | ogg_sync_init (&oy); |
754 | } | 773 | } |
755 | 774 | ||
756 | 775 | ||
757 | static void | 776 | static void |
758 | drain_callback(pa_stream*s, int success, void *userdata) | 777 | drain_callback (pa_stream*s, int success, void *userdata) |
759 | { | 778 | { |
760 | (void)s; | 779 | (void) s; |
761 | (void)success; | 780 | (void) success; |
762 | (void)userdata; | 781 | (void) userdata; |
763 | pa_threaded_mainloop_signal(m, | 782 | pa_threaded_mainloop_signal (m, |
764 | 0); | 783 | 0); |
765 | } | 784 | } |
766 | 785 | ||
767 | 786 | ||
@@ -773,7 +792,7 @@ drain_callback(pa_stream*s, int success, void *userdata) | |||
773 | * @return 0 ok, 1 on error | 792 | * @return 0 ok, 1 on error |
774 | */ | 793 | */ |
775 | int | 794 | int |
776 | main(int argc, char *argv[]) | 795 | main (int argc, char *argv[]) |
777 | { | 796 | { |
778 | static unsigned long long toff; | 797 | static unsigned long long toff; |
779 | char readbuf[MAXLINE]; | 798 | char readbuf[MAXLINE]; |
@@ -782,87 +801,87 @@ main(int argc, char *argv[]) | |||
782 | ssize_t ret; | 801 | ssize_t ret; |
783 | 802 | ||
784 | #ifdef DEBUG_READ_PURE_OGG | 803 | #ifdef DEBUG_READ_PURE_OGG |
785 | int read_pure_ogg = getenv("GNUNET_READ_PURE_OGG") ? 1 : 0; | 804 | int read_pure_ogg = getenv ("GNUNET_READ_PURE_OGG") ? 1 : 0; |
786 | #endif | 805 | #endif |
787 | 806 | ||
788 | (void)argc; | 807 | (void) argc; |
789 | (void)argv; | 808 | (void) argv; |
790 | GNUNET_assert(GNUNET_OK == | 809 | GNUNET_assert (GNUNET_OK == |
791 | GNUNET_log_setup("gnunet-helper-audio-playback", | 810 | GNUNET_log_setup ("gnunet-helper-audio-playback", |
792 | "WARNING", | 811 | "WARNING", |
793 | NULL)); | 812 | NULL)); |
794 | if (0 != pipe(ready_pipe)) | 813 | if (0 != pipe (ready_pipe)) |
795 | { | 814 | { |
796 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "pipe"); | 815 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
797 | return 1; | 816 | return 1; |
798 | } | 817 | } |
799 | stdin_mst = GNUNET_MST_create(&stdin_receiver, NULL); | 818 | stdin_mst = GNUNET_MST_create (&stdin_receiver, NULL); |
800 | ogg_init(); | 819 | ogg_init (); |
801 | pa_init(); | 820 | pa_init (); |
802 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
803 | "Waiting for PulseAudio to be ready.\n"); | 822 | "Waiting for PulseAudio to be ready.\n"); |
804 | GNUNET_assert(1 == read(ready_pipe[0], &c, 1)); | 823 | GNUNET_assert (1 == read (ready_pipe[0], &c, 1)); |
805 | close(ready_pipe[0]); | 824 | close (ready_pipe[0]); |
806 | close(ready_pipe[1]); | 825 | close (ready_pipe[1]); |
807 | ready_pipe[0] = -1; | 826 | ready_pipe[0] = -1; |
808 | ready_pipe[1] = -1; | 827 | ready_pipe[1] = -1; |
809 | #ifdef DEBUG_DUMP_DECODED_OGG | 828 | #ifdef DEBUG_DUMP_DECODED_OGG |
810 | dump_to_stdout = getenv("GNUNET_DUMP_DECODED_OGG") ? 1 : 0; | 829 | dump_to_stdout = getenv ("GNUNET_DUMP_DECODED_OGG") ? 1 : 0; |
811 | #endif | 830 | #endif |
812 | while (1) | 831 | while (1) |
832 | { | ||
833 | ret = read (STDIN_FILENO, | ||
834 | readbuf, | ||
835 | sizeof(readbuf)); | ||
836 | toff += ret; | ||
837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
838 | "Received %d bytes of audio data (total: %llu)\n", | ||
839 | (int) ret, | ||
840 | toff); | ||
841 | if (0 > ret) | ||
813 | { | 842 | { |
814 | ret = read(STDIN_FILENO, | 843 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
815 | readbuf, | 844 | _ ("Read error from STDIN: %s\n"), |
816 | sizeof(readbuf)); | 845 | strerror (errno)); |
817 | toff += ret; | 846 | break; |
818 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 847 | } |
819 | "Received %d bytes of audio data (total: %llu)\n", | 848 | if (0 == ret) |
820 | (int)ret, | 849 | break; |
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; | ||
831 | #ifdef DEBUG_READ_PURE_OGG | 850 | #ifdef DEBUG_READ_PURE_OGG |
832 | if (read_pure_ogg) | 851 | if (read_pure_ogg) |
833 | { | 852 | { |
834 | char *data = ogg_sync_buffer(&oy, ret); | 853 | char *data = ogg_sync_buffer (&oy, ret); |
835 | GNUNET_memcpy(data, readbuf, ret); | 854 | GNUNET_memcpy (data, readbuf, ret); |
836 | ogg_sync_wrote(&oy, ret); | 855 | ogg_sync_wrote (&oy, ret); |
837 | ogg_demux_and_decode(); | 856 | ogg_demux_and_decode (); |
838 | } | ||
839 | else | ||
840 | #endif | ||
841 | GNUNET_MST_from_buffer(stdin_mst, | ||
842 | readbuf, ret, | ||
843 | GNUNET_NO, GNUNET_NO); | ||
844 | } | 857 | } |
845 | GNUNET_MST_destroy(stdin_mst); | 858 | else |
859 | #endif | ||
860 | GNUNET_MST_from_buffer (stdin_mst, | ||
861 | readbuf, ret, | ||
862 | GNUNET_NO, GNUNET_NO); | ||
863 | } | ||
864 | GNUNET_MST_destroy (stdin_mst); | ||
846 | if (stream_out) | 865 | if (stream_out) |
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
868 | "Locking\n"); | ||
869 | pa_threaded_mainloop_lock (m); | ||
870 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
871 | "Draining\n"); | ||
872 | pa_operation *o = pa_stream_drain (stream_out, drain_callback, NULL); | ||
873 | while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) | ||
847 | { | 874 | { |
848 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
849 | "Locking\n"); | 876 | "Waiting\n"); |
850 | pa_threaded_mainloop_lock(m); | 877 | pa_threaded_mainloop_wait (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); | ||
866 | } | 878 | } |
879 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
880 | "Unreffing\n"); | ||
881 | pa_operation_unref (o); | ||
882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
883 | "Unlocking\n"); | ||
884 | pa_threaded_mainloop_unlock (m); | ||
885 | } | ||
867 | return 0; | 886 | return 0; |
868 | } | 887 | } |
diff --git a/src/conversation/gnunet-helper-audio-record-gst.c b/src/conversation/gnunet-helper-audio-record-gst.c index f41f529ea..a3607014e 100644 --- a/src/conversation/gnunet-helper-audio-record-gst.c +++ b/src/conversation/gnunet-helper-audio-record-gst.c | |||
@@ -102,61 +102,63 @@ 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; | 134 | break; |
135 | } | 135 | } |
136 | 136 | ||
137 | default: | 137 | default: |
138 | break; | 138 | break; |
139 | } | 139 | } |
140 | 140 | ||
141 | return TRUE; | 141 | return TRUE; |
142 | } | 142 | } |
143 | 143 | ||
144 | void | 144 | void |
145 | source_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) | 145 | source_child_added (GstChildProxy *child_proxy, GObject *object, gchar *name, |
146 | gpointer user_data) | ||
146 | { | 147 | { |
147 | if (GST_IS_AUDIO_BASE_SRC(object)) | 148 | if (GST_IS_AUDIO_BASE_SRC (object)) |
148 | g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); | 149 | g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", |
150 | (gint64) LATENCY_TIME, NULL); | ||
149 | } | 151 | } |
150 | 152 | ||
151 | static void | 153 | static void |
152 | signalhandler(int s) | 154 | signalhandler (int s) |
153 | { | 155 | { |
154 | quit(); | 156 | quit (); |
155 | } | 157 | } |
156 | 158 | ||
157 | 159 | ||
158 | int | 160 | int |
159 | main(int argc, char **argv) | 161 | main (int argc, char **argv) |
160 | { | 162 | { |
161 | GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; | 163 | GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; |
162 | GstCaps *caps; | 164 | GstCaps *caps; |
@@ -168,214 +170,221 @@ main(int argc, char **argv) | |||
168 | typedef void (*SignalHandlerPointer) (int); | 170 | typedef void (*SignalHandlerPointer) (int); |
169 | 171 | ||
170 | SignalHandlerPointer inthandler, termhandler; | 172 | SignalHandlerPointer inthandler, termhandler; |
171 | inthandler = signal(SIGINT, signalhandler); | 173 | inthandler = signal (SIGINT, signalhandler); |
172 | termhandler = signal(SIGTERM, signalhandler); | 174 | termhandler = signal (SIGTERM, signalhandler); |
173 | 175 | ||
174 | #ifdef DEBUG_RECORD_PURE_OGG | 176 | #ifdef DEBUG_RECORD_PURE_OGG |
175 | dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; | 177 | dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; |
176 | #endif | 178 | #endif |
177 | 179 | ||
178 | /* Initialisation */ | 180 | /* Initialisation */ |
179 | gst_init(&argc, &argv); | 181 | gst_init (&argc, &argv); |
180 | 182 | ||
181 | GNUNET_assert(GNUNET_OK == | 183 | GNUNET_assert (GNUNET_OK == |
182 | GNUNET_log_setup("gnunet-helper-audio-record", | 184 | GNUNET_log_setup ("gnunet-helper-audio-record", |
183 | "WARNING", | 185 | "WARNING", |
184 | NULL)); | 186 | NULL)); |
185 | 187 | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
187 | "Audio source starts\n"); | 189 | "Audio source starts\n"); |
188 | 190 | ||
189 | audio_message.header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 191 | audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
190 | 192 | ||
191 | /* Create gstreamer elements */ | 193 | /* Create gstreamer elements */ |
192 | pipeline = gst_pipeline_new("audio-recorder"); | 194 | pipeline = gst_pipeline_new ("audio-recorder"); |
193 | source = gst_element_factory_make("autoaudiosrc", "audiosource"); | 195 | source = gst_element_factory_make ("autoaudiosrc", "audiosource"); |
194 | filter = gst_element_factory_make("capsfilter", "filter"); | 196 | filter = gst_element_factory_make ("capsfilter", "filter"); |
195 | conv = gst_element_factory_make("audioconvert", "converter"); | 197 | conv = gst_element_factory_make ("audioconvert", "converter"); |
196 | resampler = gst_element_factory_make("audioresample", "resampler"); | 198 | resampler = gst_element_factory_make ("audioresample", "resampler"); |
197 | encoder = gst_element_factory_make("opusenc", "opus-encoder"); | 199 | encoder = gst_element_factory_make ("opusenc", "opus-encoder"); |
198 | oggmux = gst_element_factory_make("oggmux", "ogg-muxer"); | 200 | oggmux = gst_element_factory_make ("oggmux", "ogg-muxer"); |
199 | sink = gst_element_factory_make("appsink", "audio-output"); | 201 | sink = gst_element_factory_make ("appsink", "audio-output"); |
200 | 202 | ||
201 | if (!pipeline || !filter || !source || !conv || !resampler || !encoder || !oggmux || !sink) | 203 | if (! pipeline || ! filter || ! source || ! conv || ! resampler || |
202 | { | 204 | ! encoder || ! oggmux || ! sink) |
203 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 205 | { |
204 | "One element could not be created. Exiting.\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
205 | return -1; | 207 | "One element could not be created. Exiting.\n"); |
206 | } | 208 | return -1; |
207 | 209 | } | |
208 | g_signal_connect(source, "child-added", G_CALLBACK(source_child_added), NULL); | 210 | |
211 | g_signal_connect (source, "child-added", G_CALLBACK (source_child_added), | ||
212 | NULL); | ||
209 | 213 | ||
210 | /* Set up the pipeline */ | 214 | /* Set up the pipeline */ |
211 | 215 | ||
212 | caps = gst_caps_new_simple("audio/x-raw", | 216 | caps = gst_caps_new_simple ("audio/x-raw", |
213 | "format", G_TYPE_STRING, "S16LE", | 217 | "format", G_TYPE_STRING, "S16LE", |
214 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ | 218 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ |
215 | "channels", G_TYPE_INT, OPUS_CHANNELS, | 219 | "channels", G_TYPE_INT, OPUS_CHANNELS, |
216 | /* "layout", G_TYPE_STRING, "interleaved",*/ | 220 | /* "layout", G_TYPE_STRING, "interleaved",*/ |
217 | NULL); | 221 | NULL); |
218 | g_object_set(G_OBJECT(filter), | 222 | g_object_set (G_OBJECT (filter), |
219 | "caps", caps, | 223 | "caps", caps, |
220 | NULL); | 224 | NULL); |
221 | gst_caps_unref(caps); | 225 | gst_caps_unref (caps); |
222 | 226 | ||
223 | g_object_set(G_OBJECT(encoder), | 227 | g_object_set (G_OBJECT (encoder), |
224 | /* "bitrate", 64000, */ | 228 | /* "bitrate", 64000, */ |
225 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | 229 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ |
226 | "inband-fec", INBAND_FEC_MODE, | 230 | "inband-fec", INBAND_FEC_MODE, |
227 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | 231 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, |
228 | "max-payload-size", MAX_PAYLOAD_SIZE, | 232 | "max-payload-size", MAX_PAYLOAD_SIZE, |
229 | "audio", FALSE, /* VoIP, not audio */ | 233 | "audio", FALSE, /* VoIP, not audio */ |
230 | "frame-size", OPUS_FRAME_SIZE, | 234 | "frame-size", OPUS_FRAME_SIZE, |
231 | NULL); | 235 | NULL); |
232 | 236 | ||
233 | g_object_set(G_OBJECT(oggmux), | 237 | g_object_set (G_OBJECT (oggmux), |
234 | "max-delay", OGG_MAX_DELAY, | 238 | "max-delay", OGG_MAX_DELAY, |
235 | "max-page-delay", OGG_MAX_PAGE_DELAY, | 239 | "max-page-delay", OGG_MAX_PAGE_DELAY, |
236 | NULL); | 240 | NULL); |
237 | 241 | ||
238 | /* we add a message handler */ | 242 | /* we add a message handler */ |
239 | bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); | 243 | bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); |
240 | bus_watch_id = gst_bus_add_watch(bus, bus_call, pipeline); | 244 | bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); |
241 | gst_object_unref(bus); | 245 | gst_object_unref (bus); |
242 | 246 | ||
243 | /* we add all elements into the pipeline */ | 247 | /* we add all elements into the pipeline */ |
244 | /* audiosource | converter | resampler | opus-encoder | audio-output */ | 248 | /* audiosource | converter | resampler | opus-encoder | audio-output */ |
245 | gst_bin_add_many(GST_BIN(pipeline), source, filter, conv, resampler, encoder, | 249 | gst_bin_add_many (GST_BIN (pipeline), source, filter, conv, resampler, |
246 | oggmux, sink, NULL); | 250 | encoder, |
251 | oggmux, sink, NULL); | ||
247 | 252 | ||
248 | /* we link the elements together */ | 253 | /* we link the elements together */ |
249 | gst_element_link_many(source, filter, conv, resampler, encoder, oggmux, sink, NULL); | 254 | gst_element_link_many (source, filter, conv, resampler, encoder, oggmux, sink, |
255 | NULL); | ||
250 | 256 | ||
251 | /* Set the pipeline to "playing" state*/ | 257 | /* Set the pipeline to "playing" state*/ |
252 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Now playing\n"); | 258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); |
253 | gst_element_set_state(pipeline, GST_STATE_PLAYING); | 259 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
254 | 260 | ||
255 | 261 | ||
256 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running...\n"); | 262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); |
257 | /* Iterate */ | 263 | /* Iterate */ |
258 | while (!abort_send) | 264 | while (! abort_send) |
265 | { | ||
266 | GstSample *s; | ||
267 | GstBuffer *b; | ||
268 | GstMapInfo m; | ||
269 | size_t len, msg_size; | ||
270 | const char *ptr; | ||
271 | int phase; | ||
272 | |||
273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); | ||
274 | s = gst_app_sink_pull_sample (GST_APP_SINK (sink)); | ||
275 | if (NULL == s) | ||
276 | { | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); | ||
278 | break; | ||
279 | } | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); | ||
259 | { | 281 | { |
260 | GstSample *s; | 282 | const GstStructure *si; |
261 | GstBuffer *b; | 283 | char *si_str; |
262 | GstMapInfo m; | 284 | GstCaps *s_caps; |
263 | size_t len, msg_size; | 285 | char *caps_str; |
264 | const char *ptr; | 286 | si = gst_sample_get_info (s); |
265 | int phase; | 287 | if (si) |
266 | 288 | { | |
267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); | 289 | si_str = gst_structure_to_string (si); |
268 | s = gst_app_sink_pull_sample(GST_APP_SINK(sink)); | 290 | if (si_str) |
269 | if (NULL == s) | ||
270 | { | 291 | { |
271 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); |
272 | break; | 293 | g_free (si_str); |
273 | } | 294 | } |
274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); | ||
275 | { | ||
276 | const GstStructure *si; | ||
277 | char *si_str; | ||
278 | GstCaps *s_caps; | ||
279 | char *caps_str; | ||
280 | si = gst_sample_get_info(s); | ||
281 | if (si) | ||
282 | { | ||
283 | si_str = gst_structure_to_string(si); | ||
284 | if (si_str) | ||
285 | { | ||
286 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); | ||
287 | g_free(si_str); | ||
288 | } | ||
289 | } | ||
290 | else | ||
291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); | ||
292 | s_caps = gst_sample_get_caps(s); | ||
293 | if (s_caps) | ||
294 | { | ||
295 | caps_str = gst_caps_to_string(s_caps); | ||
296 | if (caps_str) | ||
297 | { | ||
298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str); | ||
299 | g_free(caps_str); | ||
300 | } | ||
301 | } | ||
302 | else | ||
303 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | ||
304 | } | 295 | } |
305 | b = gst_sample_get_buffer(s); | 296 | else |
306 | if (NULL == b || !gst_buffer_map(b, &m, GST_MAP_READ)) | 297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); |
298 | s_caps = gst_sample_get_caps (s); | ||
299 | if (s_caps) | ||
300 | { | ||
301 | caps_str = gst_caps_to_string (s_caps); | ||
302 | if (caps_str) | ||
307 | { | 303 | { |
308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); | 304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", |
309 | gst_sample_unref(s); | 305 | caps_str); |
310 | continue; | 306 | g_free (caps_str); |
311 | } | 307 | } |
308 | } | ||
309 | else | ||
310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); | ||
311 | } | ||
312 | b = gst_sample_get_buffer (s); | ||
313 | if ((NULL == b) || ! gst_buffer_map (b, &m, GST_MAP_READ)) | ||
314 | { | ||
315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
316 | "got NULL buffer %p or failed to map the buffer\n", b); | ||
317 | gst_sample_unref (s); | ||
318 | continue; | ||
319 | } | ||
312 | 320 | ||
313 | len = m.size; | 321 | len = m.size; |
314 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) | 322 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) |
315 | { | 323 | { |
316 | GNUNET_break(0); | 324 | GNUNET_break (0); |
317 | len = UINT16_MAX - sizeof(struct AudioMessage); | 325 | len = UINT16_MAX - sizeof(struct AudioMessage); |
318 | } | 326 | } |
319 | msg_size = sizeof(struct AudioMessage) + len; | 327 | msg_size = sizeof(struct AudioMessage) + len; |
320 | audio_message.header.size = htons((uint16_t)msg_size); | 328 | audio_message.header.size = htons ((uint16_t) msg_size); |
321 | 329 | ||
322 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
323 | "Sending %u bytes of audio data\n", (unsigned int)msg_size); | 331 | "Sending %u bytes of audio data\n", (unsigned int) msg_size); |
324 | for (phase = 0; phase < 2; phase++) | 332 | for (phase = 0; phase < 2; phase++) |
325 | { | 333 | { |
326 | size_t offset; | 334 | size_t offset; |
327 | size_t to_send; | 335 | size_t to_send; |
328 | ssize_t ret; | 336 | ssize_t ret; |
329 | if (0 == phase) | 337 | if (0 == phase) |
330 | { | 338 | { |
331 | #ifdef DEBUG_RECORD_PURE_OGG | 339 | #ifdef DEBUG_RECORD_PURE_OGG |
332 | if (dump_pure_ogg) | 340 | if (dump_pure_ogg) |
333 | continue; | 341 | continue; |
334 | #endif | 342 | #endif |
335 | ptr = (const char *)&audio_message; | 343 | ptr = (const char *) &audio_message; |
336 | to_send = sizeof(audio_message); | 344 | to_send = sizeof(audio_message); |
337 | } | 345 | } |
338 | else | 346 | else |
339 | { | 347 | { |
340 | ptr = (const char *)m.data; | 348 | ptr = (const char *) m.data; |
341 | to_send = len; | 349 | to_send = len; |
342 | } | 350 | } |
343 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | "Sending %u bytes on phase %d\n", (unsigned int)to_send, phase); | 352 | "Sending %u bytes on phase %d\n", (unsigned int) to_send, |
345 | for (offset = 0; offset < to_send; offset += ret) | 353 | phase); |
346 | { | 354 | for (offset = 0; offset < to_send; offset += ret) |
347 | ret = write(1, &ptr[offset], to_send - offset); | 355 | { |
348 | if (0 >= ret) | 356 | ret = write (1, &ptr[offset], to_send - offset); |
349 | { | 357 | if (0 >= ret) |
350 | if (-1 == ret) | 358 | { |
351 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 359 | if (-1 == ret) |
352 | "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
353 | (unsigned int)(to_send - offset), | 361 | "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", |
354 | (unsigned int)offset, | 362 | (unsigned int) (to_send - offset), |
355 | (unsigned int)(to_send + offset), | 363 | (unsigned int) offset, |
356 | phase, | 364 | (unsigned int) (to_send + offset), |
357 | strerror(errno)); | 365 | phase, |
358 | abort_send = 1; | 366 | strerror (errno)); |
359 | break; | 367 | abort_send = 1; |
360 | } | 368 | break; |
361 | } | ||
362 | if (abort_send) | ||
363 | break; | ||
364 | } | 369 | } |
365 | gst_buffer_unmap(b, &m); | 370 | } |
366 | gst_sample_unref(s); | 371 | if (abort_send) |
372 | break; | ||
367 | } | 373 | } |
374 | gst_buffer_unmap (b, &m); | ||
375 | gst_sample_unref (s); | ||
376 | } | ||
368 | 377 | ||
369 | signal(SIGINT, inthandler); | 378 | signal (SIGINT, inthandler); |
370 | signal(SIGINT, termhandler); | 379 | signal (SIGINT, termhandler); |
371 | 380 | ||
372 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); | 381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); |
373 | quit(); | 382 | quit (); |
374 | 383 | ||
375 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); | 384 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); |
376 | gst_object_unref(GST_OBJECT(pipeline)); | 385 | gst_object_unref (GST_OBJECT (pipeline)); |
377 | pipeline = NULL; | 386 | pipeline = NULL; |
378 | g_source_remove(bus_watch_id); | 387 | g_source_remove (bus_watch_id); |
379 | 388 | ||
380 | return 0; | 389 | return 0; |
381 | } | 390 | } |
diff --git a/src/conversation/gnunet-helper-audio-record.c b/src/conversation/gnunet-helper-audio-record.c index 0cfc04578..16311cf69 100644 --- a/src/conversation/gnunet-helper-audio-record.c +++ b/src/conversation/gnunet-helper-audio-record.c | |||
@@ -149,7 +149,8 @@ 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 | { | ||
153 | uint8_t magic[8]; | 154 | uint8_t magic[8]; |
154 | uint8_t version; | 155 | uint8_t version; |
155 | uint8_t channels; | 156 | uint8_t channels; |
@@ -159,7 +160,8 @@ struct OpusHeadPacket { | |||
159 | uint8_t channel_mapping; | 160 | uint8_t channel_mapping; |
160 | }; | 161 | }; |
161 | 162 | ||
162 | struct OpusCommentsPacket { | 163 | struct OpusCommentsPacket |
164 | { | ||
163 | uint8_t magic[8]; | 165 | uint8_t magic[8]; |
164 | uint32_t vendor_length; | 166 | uint32_t vendor_length; |
165 | /* followed by: | 167 | /* followed by: |
@@ -265,63 +267,64 @@ static int dump_pure_ogg; | |||
265 | * Pulseaudio shutdown task | 267 | * Pulseaudio shutdown task |
266 | */ | 268 | */ |
267 | static void | 269 | static void |
268 | quit(int ret) | 270 | quit (int ret) |
269 | { | 271 | { |
270 | mainloop_api->quit(mainloop_api, | 272 | mainloop_api->quit (mainloop_api, |
271 | ret); | 273 | ret); |
272 | exit(ret); | 274 | exit (ret); |
273 | } | 275 | } |
274 | 276 | ||
275 | 277 | ||
276 | static void | 278 | static void |
277 | write_data(const char *ptr, | 279 | write_data (const char *ptr, |
278 | size_t msg_size) | 280 | size_t msg_size) |
279 | { | 281 | { |
280 | ssize_t ret; | 282 | ssize_t ret; |
281 | size_t off; | 283 | size_t off; |
282 | 284 | ||
283 | off = 0; | 285 | off = 0; |
284 | while (off < msg_size) | 286 | while (off < msg_size) |
287 | { | ||
288 | ret = write (STDOUT_FILENO, | ||
289 | &ptr[off], | ||
290 | msg_size - off); | ||
291 | if (0 >= ret) | ||
285 | { | 292 | { |
286 | ret = write(STDOUT_FILENO, | 293 | if (-1 == ret) |
287 | &ptr[off], | 294 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
288 | msg_size - off); | 295 | "write"); |
289 | if (0 >= ret) | 296 | quit (2); |
290 | { | ||
291 | if (-1 == ret) | ||
292 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | ||
293 | "write"); | ||
294 | quit(2); | ||
295 | } | ||
296 | off += ret; | ||
297 | } | 297 | } |
298 | off += ret; | ||
299 | } | ||
298 | } | 300 | } |
299 | 301 | ||
300 | 302 | ||
301 | static void | 303 | static void |
302 | write_page(ogg_page *og) | 304 | write_page (ogg_page *og) |
303 | { | 305 | { |
304 | static unsigned long long toff; | 306 | static unsigned long long toff; |
305 | size_t msg_size; | 307 | size_t msg_size; |
306 | 308 | ||
307 | msg_size = sizeof(struct AudioMessage) + og->header_len + og->body_len; | 309 | msg_size = sizeof(struct AudioMessage) + og->header_len + og->body_len; |
308 | audio_message->header.size = htons((uint16_t)msg_size); | 310 | audio_message->header.size = htons ((uint16_t) msg_size); |
309 | GNUNET_memcpy(&audio_message[1], og->header, og->header_len); | 311 | 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); | 312 | GNUNET_memcpy (((char *) &audio_message[1]) + og->header_len, og->body, |
313 | og->body_len); | ||
311 | 314 | ||
312 | toff += msg_size; | 315 | toff += msg_size; |
313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
314 | "Sending %u bytes of audio data (total: %llu)\n", | 317 | "Sending %u bytes of audio data (total: %llu)\n", |
315 | (unsigned int)msg_size, | 318 | (unsigned int) msg_size, |
316 | toff); | 319 | toff); |
317 | #ifdef DEBUG_RECORD_PURE_OGG | 320 | #ifdef DEBUG_RECORD_PURE_OGG |
318 | if (dump_pure_ogg) | 321 | if (dump_pure_ogg) |
319 | write_data((const char *)&audio_message[1], | 322 | write_data ((const char *) &audio_message[1], |
320 | og->header_len + og->body_len); | 323 | og->header_len + og->body_len); |
321 | else | 324 | else |
322 | #endif | 325 | #endif |
323 | write_data((const char *)audio_message, | 326 | write_data ((const char *) audio_message, |
324 | msg_size); | 327 | msg_size); |
325 | } | 328 | } |
326 | 329 | ||
327 | 330 | ||
@@ -329,7 +332,7 @@ write_page(ogg_page *og) | |||
329 | * Creates OPUS packets from PCM data | 332 | * Creates OPUS packets from PCM data |
330 | */ | 333 | */ |
331 | static void | 334 | static void |
332 | packetizer() | 335 | packetizer () |
333 | { | 336 | { |
334 | char *nbuf; | 337 | char *nbuf; |
335 | size_t new_size; | 338 | size_t new_size; |
@@ -338,68 +341,68 @@ packetizer() | |||
338 | ogg_page og; | 341 | ogg_page og; |
339 | 342 | ||
340 | while (transmit_buffer_length >= transmit_buffer_index + pcm_length) | 343 | while (transmit_buffer_length >= transmit_buffer_index + pcm_length) |
344 | { | ||
345 | GNUNET_memcpy (pcm_buffer, | ||
346 | &transmit_buffer[transmit_buffer_index], | ||
347 | pcm_length); | ||
348 | transmit_buffer_index += pcm_length; | ||
349 | len = | ||
350 | opus_encode_float (enc, pcm_buffer, FRAME_SIZE, opus_data, | ||
351 | MAX_PAYLOAD_BYTES); | ||
352 | |||
353 | if (len < 0) | ||
341 | { | 354 | { |
342 | GNUNET_memcpy(pcm_buffer, | 355 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
343 | &transmit_buffer[transmit_buffer_index], | 356 | _ ("opus_encode_float() failed: %s. Aborting\n"), |
344 | pcm_length); | 357 | opus_strerror (len)); |
345 | transmit_buffer_index += pcm_length; | 358 | quit (5); |
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 | { | ||
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 | } | ||
386 | } | 359 | } |
387 | 360 | if (((uint32_t) len) > UINT16_MAX - sizeof(struct AudioMessage)) | |
388 | new_size = transmit_buffer_length - transmit_buffer_index; | ||
389 | if (0 != new_size) | ||
390 | { | 361 | { |
391 | nbuf = pa_xmalloc(new_size); | 362 | GNUNET_break (0); |
392 | memmove(nbuf, | 363 | continue; |
393 | &transmit_buffer[transmit_buffer_index], | ||
394 | new_size); | ||
395 | pa_xfree(transmit_buffer); | ||
396 | transmit_buffer = nbuf; | ||
397 | } | 364 | } |
398 | else | 365 | |
366 | /* As per OggOpus spec, granule is calculated as if the audio | ||
367 | had 48kHz sampling rate. */ | ||
368 | enc_granulepos += FRAME_SIZE * 48000 / SAMPLING_RATE; | ||
369 | |||
370 | op.packet = (unsigned char *) opus_data; | ||
371 | op.bytes = len; | ||
372 | op.b_o_s = 0; | ||
373 | op.e_o_s = 0; | ||
374 | op.granulepos = enc_granulepos; | ||
375 | op.packetno = packet_id++; | ||
376 | ogg_stream_packetin (&os, &op); | ||
377 | |||
378 | while (ogg_stream_flush_fill (&os, &og, PAGE_WATERLINE)) | ||
399 | { | 379 | { |
400 | pa_xfree(transmit_buffer); | 380 | if (((unsigned long long) og.header_len) |
401 | transmit_buffer = NULL; | 381 | + ((unsigned long long) og.body_len) > |
382 | UINT16_MAX - sizeof(struct AudioMessage)) | ||
383 | { | ||
384 | GNUNET_assert (0); | ||
385 | continue; | ||
386 | } | ||
387 | write_page (&og); | ||
402 | } | 388 | } |
389 | } | ||
390 | |||
391 | new_size = transmit_buffer_length - transmit_buffer_index; | ||
392 | if (0 != new_size) | ||
393 | { | ||
394 | nbuf = pa_xmalloc (new_size); | ||
395 | memmove (nbuf, | ||
396 | &transmit_buffer[transmit_buffer_index], | ||
397 | new_size); | ||
398 | pa_xfree (transmit_buffer); | ||
399 | transmit_buffer = nbuf; | ||
400 | } | ||
401 | else | ||
402 | { | ||
403 | pa_xfree (transmit_buffer); | ||
404 | transmit_buffer = NULL; | ||
405 | } | ||
403 | transmit_buffer_index = 0; | 406 | transmit_buffer_index = 0; |
404 | transmit_buffer_length = new_size; | 407 | transmit_buffer_length = new_size; |
405 | } | 408 | } |
@@ -409,51 +412,51 @@ packetizer() | |||
409 | * Pulseaudio callback when new data is available. | 412 | * Pulseaudio callback when new data is available. |
410 | */ | 413 | */ |
411 | static void | 414 | static void |
412 | stream_read_callback(pa_stream * s, | 415 | stream_read_callback (pa_stream *s, |
413 | size_t length, | 416 | size_t length, |
414 | void *userdata) | 417 | void *userdata) |
415 | { | 418 | { |
416 | const void *data; | 419 | const void *data; |
417 | 420 | ||
418 | (void)userdata; | 421 | (void) userdata; |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
420 | "Got %u/%d bytes of PCM data\n", | 423 | "Got %u/%d bytes of PCM data\n", |
421 | (unsigned int)length, | 424 | (unsigned int) length, |
422 | pcm_length); | 425 | pcm_length); |
423 | 426 | ||
424 | GNUNET_assert(NULL != s); | 427 | GNUNET_assert (NULL != s); |
425 | GNUNET_assert(length > 0); | 428 | GNUNET_assert (length > 0); |
426 | if (stdio_event) | 429 | if (stdio_event) |
427 | mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT); | 430 | mainloop_api->io_enable (stdio_event, PA_IO_EVENT_OUTPUT); |
428 | 431 | ||
429 | if (pa_stream_peek(s, (const void **)&data, &length) < 0) | 432 | if (pa_stream_peek (s, (const void **) &data, &length) < 0) |
430 | { | 433 | { |
431 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 434 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
432 | _("pa_stream_peek() failed: %s\n"), | 435 | _ ("pa_stream_peek() failed: %s\n"), |
433 | pa_strerror(pa_context_errno(context))); | 436 | pa_strerror (pa_context_errno (context))); |
434 | quit(1); | 437 | quit (1); |
435 | return; | 438 | return; |
436 | } | 439 | } |
437 | GNUNET_assert(NULL != data); | 440 | GNUNET_assert (NULL != data); |
438 | GNUNET_assert(length > 0); | 441 | GNUNET_assert (length > 0); |
439 | if (NULL != transmit_buffer) | 442 | if (NULL != transmit_buffer) |
440 | { | 443 | { |
441 | transmit_buffer = pa_xrealloc(transmit_buffer, | 444 | transmit_buffer = pa_xrealloc (transmit_buffer, |
442 | transmit_buffer_length + length); | 445 | transmit_buffer_length + length); |
443 | GNUNET_memcpy(&transmit_buffer[transmit_buffer_length], | 446 | GNUNET_memcpy (&transmit_buffer[transmit_buffer_length], |
444 | data, | 447 | data, |
445 | length); | 448 | length); |
446 | transmit_buffer_length += length; | 449 | transmit_buffer_length += length; |
447 | } | 450 | } |
448 | else | 451 | else |
449 | { | 452 | { |
450 | transmit_buffer = pa_xmalloc(length); | 453 | transmit_buffer = pa_xmalloc (length); |
451 | GNUNET_memcpy(transmit_buffer, data, length); | 454 | GNUNET_memcpy (transmit_buffer, data, length); |
452 | transmit_buffer_length = length; | 455 | transmit_buffer_length = length; |
453 | transmit_buffer_index = 0; | 456 | transmit_buffer_index = 0; |
454 | } | 457 | } |
455 | pa_stream_drop(s); | 458 | pa_stream_drop (s); |
456 | packetizer(); | 459 | packetizer (); |
457 | } | 460 | } |
458 | 461 | ||
459 | 462 | ||
@@ -461,18 +464,18 @@ stream_read_callback(pa_stream * s, | |||
461 | * Exit callback for SIGTERM and SIGINT | 464 | * Exit callback for SIGTERM and SIGINT |
462 | */ | 465 | */ |
463 | static void | 466 | static void |
464 | exit_signal_callback(pa_mainloop_api * m, | 467 | exit_signal_callback (pa_mainloop_api *m, |
465 | pa_signal_event * e, | 468 | pa_signal_event *e, |
466 | int sig, | 469 | int sig, |
467 | void *userdata) | 470 | void *userdata) |
468 | { | 471 | { |
469 | (void)m; | 472 | (void) m; |
470 | (void)e; | 473 | (void) e; |
471 | (void)sig; | 474 | (void) sig; |
472 | (void)userdata; | 475 | (void) userdata; |
473 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 476 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
474 | _("Got signal, exiting.\n")); | 477 | _ ("Got signal, exiting.\n")); |
475 | quit(1); | 478 | quit (1); |
476 | } | 479 | } |
477 | 480 | ||
478 | 481 | ||
@@ -480,61 +483,61 @@ exit_signal_callback(pa_mainloop_api * m, | |||
480 | * Pulseaudio stream state callback | 483 | * Pulseaudio stream state callback |
481 | */ | 484 | */ |
482 | static void | 485 | static void |
483 | stream_state_callback(pa_stream * s, | 486 | stream_state_callback (pa_stream *s, |
484 | void *userdata) | 487 | void *userdata) |
485 | { | 488 | { |
486 | (void)userdata; | 489 | (void) userdata; |
487 | GNUNET_assert(NULL != s); | 490 | GNUNET_assert (NULL != s); |
488 | switch (pa_stream_get_state(s)) | 491 | switch (pa_stream_get_state (s)) |
489 | { | 492 | { |
490 | case PA_STREAM_CREATING: | 493 | case PA_STREAM_CREATING: |
491 | case PA_STREAM_TERMINATED: | 494 | case PA_STREAM_TERMINATED: |
492 | break; | 495 | break; |
493 | 496 | ||
494 | case PA_STREAM_READY: | 497 | case PA_STREAM_READY: |
495 | { | 498 | { |
496 | const pa_buffer_attr *a; | 499 | const pa_buffer_attr *a; |
497 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX]; | 500 | char cmt[PA_CHANNEL_MAP_SNPRINT_MAX]; |
498 | char sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; | 501 | char sst[PA_SAMPLE_SPEC_SNPRINT_MAX]; |
499 | 502 | ||
500 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
501 | _("Stream successfully created.\n")); | 504 | _ ("Stream successfully created.\n")); |
502 | 505 | ||
503 | if (!(a = pa_stream_get_buffer_attr(s))) | 506 | if (! (a = pa_stream_get_buffer_attr (s))) |
504 | { | 507 | { |
505 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
506 | _("pa_stream_get_buffer_attr() failed: %s\n"), | 509 | _ ("pa_stream_get_buffer_attr() failed: %s\n"), |
507 | pa_strerror(pa_context_errno | 510 | pa_strerror (pa_context_errno |
508 | (pa_stream_get_context(s)))); | 511 | (pa_stream_get_context (s)))); |
509 | } | 512 | } |
510 | else | 513 | else |
511 | { | 514 | { |
512 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
513 | _("Buffer metrics: maxlength=%u, fragsize=%u\n"), | 516 | _ ("Buffer metrics: maxlength=%u, fragsize=%u\n"), |
514 | a->maxlength, a->fragsize); | 517 | a->maxlength, a->fragsize); |
515 | } | 518 | } |
516 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 519 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
517 | _("Using sample spec '%s', channel map '%s'.\n"), | 520 | _ ("Using sample spec '%s', channel map '%s'.\n"), |
518 | pa_sample_spec_snprint(sst, sizeof(sst), | 521 | pa_sample_spec_snprint (sst, sizeof(sst), |
519 | pa_stream_get_sample_spec(s)), | 522 | pa_stream_get_sample_spec (s)), |
520 | pa_channel_map_snprint(cmt, sizeof(cmt), | 523 | pa_channel_map_snprint (cmt, sizeof(cmt), |
521 | pa_stream_get_channel_map(s))); | 524 | pa_stream_get_channel_map (s))); |
522 | 525 | ||
523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 526 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
524 | _("Connected to device %s (%u, %ssuspended).\n"), | 527 | _ ("Connected to device %s (%u, %ssuspended).\n"), |
525 | pa_stream_get_device_name(s), | 528 | pa_stream_get_device_name (s), |
526 | pa_stream_get_device_index(s), | 529 | pa_stream_get_device_index (s), |
527 | pa_stream_is_suspended(s) ? "" : "not "); | 530 | pa_stream_is_suspended (s) ? "" : "not "); |
528 | } | 531 | } |
529 | break; | 532 | break; |
530 | 533 | ||
531 | case PA_STREAM_FAILED: | 534 | case PA_STREAM_FAILED: |
532 | default: | 535 | default: |
533 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
534 | _("Stream error: %s\n"), | 537 | _ ("Stream error: %s\n"), |
535 | pa_strerror(pa_context_errno(pa_stream_get_context(s)))); | 538 | pa_strerror (pa_context_errno (pa_stream_get_context (s)))); |
536 | quit(1); | 539 | quit (1); |
537 | } | 540 | } |
538 | } | 541 | } |
539 | 542 | ||
540 | 543 | ||
@@ -542,67 +545,67 @@ stream_state_callback(pa_stream * s, | |||
542 | * Pulseaudio context state callback | 545 | * Pulseaudio context state callback |
543 | */ | 546 | */ |
544 | static void | 547 | static void |
545 | context_state_callback(pa_context * c, | 548 | context_state_callback (pa_context *c, |
546 | void *userdata) | 549 | void *userdata) |
547 | { | 550 | { |
548 | (void)userdata; | 551 | (void) userdata; |
549 | GNUNET_assert(c); | 552 | GNUNET_assert (c); |
550 | 553 | ||
551 | switch (pa_context_get_state(c)) | 554 | switch (pa_context_get_state (c)) |
552 | { | 555 | { |
553 | case PA_CONTEXT_CONNECTING: | 556 | case PA_CONTEXT_CONNECTING: |
554 | case PA_CONTEXT_AUTHORIZING: | 557 | case PA_CONTEXT_AUTHORIZING: |
555 | case PA_CONTEXT_SETTING_NAME: | 558 | case PA_CONTEXT_SETTING_NAME: |
556 | break; | 559 | break; |
557 | 560 | ||
558 | case PA_CONTEXT_READY: | 561 | case PA_CONTEXT_READY: |
559 | { | 562 | { |
560 | int r; | 563 | int r; |
561 | pa_buffer_attr na; | 564 | pa_buffer_attr na; |
562 | 565 | ||
563 | GNUNET_assert(!stream_in); | 566 | GNUNET_assert (! stream_in); |
564 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 567 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
565 | _("Connection established.\n")); | 568 | _ ("Connection established.\n")); |
566 | if (!(stream_in = | 569 | if (! (stream_in = |
567 | pa_stream_new(c, "GNUNET_VoIP recorder", &sample_spec, NULL))) | 570 | pa_stream_new (c, "GNUNET_VoIP recorder", &sample_spec, NULL))) |
568 | { | 571 | { |
569 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 572 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
570 | _("pa_stream_new() failed: %s\n"), | 573 | _ ("pa_stream_new() failed: %s\n"), |
571 | pa_strerror(pa_context_errno(c))); | 574 | pa_strerror (pa_context_errno (c))); |
572 | goto fail; | 575 | goto fail; |
573 | } | 576 | } |
574 | pa_stream_set_state_callback(stream_in, &stream_state_callback, NULL); | 577 | pa_stream_set_state_callback (stream_in, &stream_state_callback, NULL); |
575 | pa_stream_set_read_callback(stream_in, &stream_read_callback, NULL); | 578 | pa_stream_set_read_callback (stream_in, &stream_read_callback, NULL); |
576 | memset(&na, 0, sizeof(na)); | 579 | memset (&na, 0, sizeof(na)); |
577 | na.maxlength = UINT32_MAX; | 580 | na.maxlength = UINT32_MAX; |
578 | na.fragsize = pcm_length; | 581 | na.fragsize = pcm_length; |
579 | if ((r = pa_stream_connect_record(stream_in, NULL, &na, | 582 | if ((r = pa_stream_connect_record (stream_in, NULL, &na, |
580 | PA_STREAM_ADJUST_LATENCY)) < 0) | 583 | PA_STREAM_ADJUST_LATENCY)) < 0) |
581 | { | 584 | { |
582 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 585 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
583 | _("pa_stream_connect_record() failed: %s\n"), | 586 | _ ("pa_stream_connect_record() failed: %s\n"), |
584 | pa_strerror(pa_context_errno(c))); | 587 | pa_strerror (pa_context_errno (c))); |
585 | goto fail; | 588 | goto fail; |
586 | } | 589 | } |
587 | 590 | ||
588 | break; | 591 | break; |
589 | } | 592 | } |
590 | 593 | ||
591 | case PA_CONTEXT_TERMINATED: | 594 | case PA_CONTEXT_TERMINATED: |
592 | quit(0); | 595 | quit (0); |
593 | break; | 596 | break; |
594 | 597 | ||
595 | case PA_CONTEXT_FAILED: | 598 | case PA_CONTEXT_FAILED: |
596 | default: | 599 | default: |
597 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
598 | _("Connection failure: %s\n"), | 601 | _ ("Connection failure: %s\n"), |
599 | pa_strerror(pa_context_errno(c))); | 602 | pa_strerror (pa_context_errno (c))); |
600 | goto fail; | 603 | goto fail; |
601 | } | 604 | } |
602 | return; | 605 | return; |
603 | 606 | ||
604 | fail: | 607 | fail: |
605 | quit(1); | 608 | quit (1); |
606 | } | 609 | } |
607 | 610 | ||
608 | 611 | ||
@@ -610,49 +613,49 @@ fail: | |||
610 | * Pulsaudio init | 613 | * Pulsaudio init |
611 | */ | 614 | */ |
612 | static void | 615 | static void |
613 | pa_init() | 616 | pa_init () |
614 | { | 617 | { |
615 | int r; | 618 | int r; |
616 | int i; | 619 | int i; |
617 | 620 | ||
618 | if (!pa_sample_spec_valid(&sample_spec)) | 621 | if (! pa_sample_spec_valid (&sample_spec)) |
619 | { | 622 | { |
620 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 623 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
621 | _("Wrong Spec\n")); | 624 | _ ("Wrong Spec\n")); |
622 | } | 625 | } |
623 | /* set up main record loop */ | 626 | /* set up main record loop */ |
624 | if (!(m = pa_mainloop_new())) | 627 | if (! (m = pa_mainloop_new ())) |
625 | { | 628 | { |
626 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 629 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
627 | _("pa_mainloop_new() failed.\n")); | 630 | _ ("pa_mainloop_new() failed.\n")); |
628 | } | 631 | } |
629 | mainloop_api = pa_mainloop_get_api(m); | 632 | mainloop_api = pa_mainloop_get_api (m); |
630 | 633 | ||
631 | /* listen to signals */ | 634 | /* listen to signals */ |
632 | r = pa_signal_init(mainloop_api); | 635 | r = pa_signal_init (mainloop_api); |
633 | GNUNET_assert(r == 0); | 636 | GNUNET_assert (r == 0); |
634 | pa_signal_new(SIGINT, &exit_signal_callback, NULL); | 637 | pa_signal_new (SIGINT, &exit_signal_callback, NULL); |
635 | pa_signal_new(SIGTERM, &exit_signal_callback, NULL); | 638 | pa_signal_new (SIGTERM, &exit_signal_callback, NULL); |
636 | 639 | ||
637 | /* connect to the main pulseaudio context */ | 640 | /* connect to the main pulseaudio context */ |
638 | 641 | ||
639 | if (!(context = pa_context_new(mainloop_api, "GNUNET VoIP"))) | 642 | if (! (context = pa_context_new (mainloop_api, "GNUNET VoIP"))) |
640 | { | 643 | { |
641 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 644 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
642 | _("pa_context_new() failed.\n")); | 645 | _ ("pa_context_new() failed.\n")); |
643 | } | 646 | } |
644 | pa_context_set_state_callback(context, &context_state_callback, NULL); | 647 | pa_context_set_state_callback (context, &context_state_callback, NULL); |
645 | if (pa_context_connect(context, NULL, 0, NULL) < 0) | 648 | if (pa_context_connect (context, NULL, 0, NULL) < 0) |
646 | { | 649 | { |
647 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 650 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
648 | _("pa_context_connect() failed: %s\n"), | 651 | _ ("pa_context_connect() failed: %s\n"), |
649 | pa_strerror(pa_context_errno(context))); | 652 | pa_strerror (pa_context_errno (context))); |
650 | } | 653 | } |
651 | if (pa_mainloop_run(m, &i) < 0) | 654 | if (pa_mainloop_run (m, &i) < 0) |
652 | { | 655 | { |
653 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
654 | _("pa_mainloop_run() failed.\n")); | 657 | _ ("pa_mainloop_run() failed.\n")); |
655 | } | 658 | } |
656 | } | 659 | } |
657 | 660 | ||
658 | 661 | ||
@@ -660,45 +663,46 @@ pa_init() | |||
660 | * OPUS init | 663 | * OPUS init |
661 | */ | 664 | */ |
662 | static void | 665 | static void |
663 | opus_init() | 666 | opus_init () |
664 | { | 667 | { |
665 | int err; | 668 | int err; |
666 | 669 | ||
667 | pcm_length = FRAME_SIZE * CHANNELS * sizeof(float); | 670 | pcm_length = FRAME_SIZE * CHANNELS * sizeof(float); |
668 | pcm_buffer = pa_xmalloc(pcm_length); | 671 | pcm_buffer = pa_xmalloc (pcm_length); |
669 | opus_data = GNUNET_malloc(MAX_PAYLOAD_BYTES); | 672 | opus_data = GNUNET_malloc (MAX_PAYLOAD_BYTES); |
670 | enc = opus_encoder_create(SAMPLING_RATE, | 673 | enc = opus_encoder_create (SAMPLING_RATE, |
671 | CHANNELS, | 674 | CHANNELS, |
672 | CONV_OPUS_APP_TYPE, | 675 | CONV_OPUS_APP_TYPE, |
673 | &err); | 676 | &err); |
674 | opus_encoder_ctl(enc, | 677 | opus_encoder_ctl (enc, |
675 | OPUS_SET_PACKET_LOSS_PERC(CONV_OPUS_PACKET_LOSS_PERCENTAGE)); | 678 | OPUS_SET_PACKET_LOSS_PERC ( |
676 | opus_encoder_ctl(enc, | 679 | CONV_OPUS_PACKET_LOSS_PERCENTAGE)); |
677 | OPUS_SET_COMPLEXITY(CONV_OPUS_ENCODING_COMPLEXITY)); | 680 | opus_encoder_ctl (enc, |
678 | opus_encoder_ctl(enc, | 681 | OPUS_SET_COMPLEXITY (CONV_OPUS_ENCODING_COMPLEXITY)); |
679 | OPUS_SET_INBAND_FEC(CONV_OPUS_INBAND_FEC)); | 682 | opus_encoder_ctl (enc, |
680 | opus_encoder_ctl(enc, | 683 | OPUS_SET_INBAND_FEC (CONV_OPUS_INBAND_FEC)); |
681 | OPUS_SET_SIGNAL(CONV_OPUS_SIGNAL)); | 684 | opus_encoder_ctl (enc, |
685 | OPUS_SET_SIGNAL (CONV_OPUS_SIGNAL)); | ||
682 | } | 686 | } |
683 | 687 | ||
684 | 688 | ||
685 | static void | 689 | static void |
686 | ogg_init() | 690 | ogg_init () |
687 | { | 691 | { |
688 | int serialno; | 692 | int serialno; |
689 | struct OpusHeadPacket headpacket; | 693 | struct OpusHeadPacket headpacket; |
690 | struct OpusCommentsPacket *commentspacket; | 694 | struct OpusCommentsPacket *commentspacket; |
691 | size_t commentspacket_len; | 695 | size_t commentspacket_len; |
692 | 696 | ||
693 | serialno = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, | 697 | serialno = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, |
694 | 0x7FFFFFFF); | 698 | 0x7FFFFFFF); |
695 | /*Initialize Ogg stream struct*/ | 699 | /*Initialize Ogg stream struct*/ |
696 | if (-1 == ogg_stream_init(&os, serialno)) | 700 | if (-1 == ogg_stream_init (&os, serialno)) |
697 | { | 701 | { |
698 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 702 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
699 | _("ogg_stream_init() failed.\n")); | 703 | _ ("ogg_stream_init() failed.\n")); |
700 | exit(3); | 704 | exit (3); |
701 | } | 705 | } |
702 | 706 | ||
703 | packet_id = 0; | 707 | packet_id = 0; |
704 | 708 | ||
@@ -709,64 +713,64 @@ ogg_init() | |||
709 | const char *opusver; | 713 | const char *opusver; |
710 | int vendor_length; | 714 | int vendor_length; |
711 | 715 | ||
712 | GNUNET_memcpy(headpacket.magic, "OpusHead", 8); | 716 | GNUNET_memcpy (headpacket.magic, "OpusHead", 8); |
713 | headpacket.version = 1; | 717 | headpacket.version = 1; |
714 | headpacket.channels = CHANNELS; | 718 | headpacket.channels = CHANNELS; |
715 | headpacket.preskip = GNUNET_htole16(0); | 719 | headpacket.preskip = GNUNET_htole16 (0); |
716 | headpacket.sampling_rate = GNUNET_htole32(SAMPLING_RATE); | 720 | headpacket.sampling_rate = GNUNET_htole32 (SAMPLING_RATE); |
717 | headpacket.gain = GNUNET_htole16(0); | 721 | headpacket.gain = GNUNET_htole16 (0); |
718 | headpacket.channel_mapping = 0; /* Mono or stereo */ | 722 | headpacket.channel_mapping = 0; /* Mono or stereo */ |
719 | 723 | ||
720 | op.packet = (unsigned char *)&headpacket; | 724 | op.packet = (unsigned char *) &headpacket; |
721 | op.bytes = sizeof(headpacket); | 725 | op.bytes = sizeof(headpacket); |
722 | op.b_o_s = 1; | 726 | op.b_o_s = 1; |
723 | op.e_o_s = 0; | 727 | op.e_o_s = 0; |
724 | op.granulepos = 0; | 728 | op.granulepos = 0; |
725 | op.packetno = packet_id++; | 729 | op.packetno = packet_id++; |
726 | ogg_stream_packetin(&os, &op); | 730 | ogg_stream_packetin (&os, &op); |
727 | 731 | ||
728 | /* Head packet must be alone on its page */ | 732 | /* Head packet must be alone on its page */ |
729 | while (ogg_stream_flush(&os, &og)) | 733 | while (ogg_stream_flush (&os, &og)) |
730 | { | 734 | { |
731 | write_page(&og); | 735 | write_page (&og); |
732 | } | 736 | } |
733 | 737 | ||
734 | commentspacket_len = sizeof(*commentspacket); | 738 | commentspacket_len = sizeof(*commentspacket); |
735 | opusver = opus_get_version_string(); | 739 | opusver = opus_get_version_string (); |
736 | vendor_length = strlen(opusver); | 740 | vendor_length = strlen (opusver); |
737 | commentspacket_len += vendor_length; | 741 | commentspacket_len += vendor_length; |
738 | commentspacket_len += sizeof(uint32_t); | 742 | commentspacket_len += sizeof(uint32_t); |
739 | 743 | ||
740 | commentspacket = (struct OpusCommentsPacket *)malloc(commentspacket_len); | 744 | commentspacket = (struct OpusCommentsPacket *) malloc (commentspacket_len); |
741 | if (NULL == commentspacket) | 745 | if (NULL == commentspacket) |
742 | { | 746 | { |
743 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 747 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
744 | _("Failed to allocate %u bytes for second packet\n"), | 748 | _ ("Failed to allocate %u bytes for second packet\n"), |
745 | (unsigned int)commentspacket_len); | 749 | (unsigned int) commentspacket_len); |
746 | exit(5); | 750 | exit (5); |
747 | } | 751 | } |
748 | 752 | ||
749 | GNUNET_memcpy(commentspacket->magic, "OpusTags", 8); | 753 | GNUNET_memcpy (commentspacket->magic, "OpusTags", 8); |
750 | commentspacket->vendor_length = GNUNET_htole32(vendor_length); | 754 | commentspacket->vendor_length = GNUNET_htole32 (vendor_length); |
751 | GNUNET_memcpy(&commentspacket[1], opusver, vendor_length); | 755 | GNUNET_memcpy (&commentspacket[1], opusver, vendor_length); |
752 | *(uint32_t *)&((char *)&commentspacket[1])[vendor_length] = \ | 756 | *(uint32_t *) &((char *) &commentspacket[1])[vendor_length] = \ |
753 | GNUNET_htole32(0); /* no tags */ | 757 | GNUNET_htole32 (0); /* no tags */ |
754 | 758 | ||
755 | op.packet = (unsigned char *)commentspacket; | 759 | op.packet = (unsigned char *) commentspacket; |
756 | op.bytes = commentspacket_len; | 760 | op.bytes = commentspacket_len; |
757 | op.b_o_s = 0; | 761 | op.b_o_s = 0; |
758 | op.e_o_s = 0; | 762 | op.e_o_s = 0; |
759 | op.granulepos = 0; | 763 | op.granulepos = 0; |
760 | op.packetno = packet_id++; | 764 | op.packetno = packet_id++; |
761 | ogg_stream_packetin(&os, &op); | 765 | ogg_stream_packetin (&os, &op); |
762 | 766 | ||
763 | /* Comment packets must not be mixed with audio packets on their pages */ | 767 | /* Comment packets must not be mixed with audio packets on their pages */ |
764 | while (ogg_stream_flush(&os, &og)) | 768 | while (ogg_stream_flush (&os, &og)) |
765 | { | 769 | { |
766 | write_page(&og); | 770 | write_page (&og); |
767 | } | 771 | } |
768 | 772 | ||
769 | free(commentspacket); | 773 | free (commentspacket); |
770 | } | 774 | } |
771 | } | 775 | } |
772 | 776 | ||
@@ -778,25 +782,25 @@ ogg_init() | |||
778 | * @return 0 ok, 1 on error | 782 | * @return 0 ok, 1 on error |
779 | */ | 783 | */ |
780 | int | 784 | int |
781 | main(int argc, | 785 | main (int argc, |
782 | char *argv[]) | 786 | char *argv[]) |
783 | { | 787 | { |
784 | (void)argc; | 788 | (void) argc; |
785 | (void)argv; | 789 | (void) argv; |
786 | GNUNET_assert(GNUNET_OK == | 790 | GNUNET_assert (GNUNET_OK == |
787 | GNUNET_log_setup("gnunet-helper-audio-record", | 791 | GNUNET_log_setup ("gnunet-helper-audio-record", |
788 | "WARNING", | 792 | "WARNING", |
789 | NULL)); | 793 | NULL)); |
790 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 794 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Audio source starts\n"); | 795 | "Audio source starts\n"); |
792 | audio_message = GNUNET_malloc(UINT16_MAX); | 796 | audio_message = GNUNET_malloc (UINT16_MAX); |
793 | audio_message->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 797 | audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
794 | 798 | ||
795 | #ifdef DEBUG_RECORD_PURE_OGG | 799 | #ifdef DEBUG_RECORD_PURE_OGG |
796 | dump_pure_ogg = getenv("GNUNET_RECORD_PURE_OGG") ? 1 : 0; | 800 | dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; |
797 | #endif | 801 | #endif |
798 | ogg_init(); | 802 | ogg_init (); |
799 | opus_init(); | 803 | opus_init (); |
800 | pa_init(); | 804 | pa_init (); |
801 | return 0; | 805 | return 0; |
802 | } | 806 | } |
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index e5e225623..12b943217 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c | |||
@@ -52,7 +52,8 @@ struct Line; | |||
52 | /** | 52 | /** |
53 | * The possible connection status | 53 | * The possible connection status |
54 | */ | 54 | */ |
55 | enum ChannelStatus { | 55 | enum ChannelStatus |
56 | { | ||
56 | /** | 57 | /** |
57 | * We just got the connection, but no introduction yet. | 58 | * We just got the connection, but no introduction yet. |
58 | */ | 59 | */ |
@@ -96,7 +97,8 @@ enum ChannelStatus { | |||
96 | * be attached the the same `struct Line`, which represents a local | 97 | * be attached the the same `struct Line`, which represents a local |
97 | * client. We keep them in a linked list. | 98 | * client. We keep them in a linked list. |
98 | */ | 99 | */ |
99 | struct Channel { | 100 | struct Channel |
101 | { | ||
100 | /** | 102 | /** |
101 | * This is a DLL. | 103 | * This is a DLL. |
102 | */ | 104 | */ |
@@ -152,7 +154,8 @@ struct Channel { | |||
152 | /** | 154 | /** |
153 | * A `struct Line` connects a local client with cadet channels. | 155 | * A `struct Line` connects a local client with cadet channels. |
154 | */ | 156 | */ |
155 | struct Line { | 157 | struct Line |
158 | { | ||
156 | /** | 159 | /** |
157 | * This is a DLL. | 160 | * This is a DLL. |
158 | */ | 161 | */ |
@@ -216,7 +219,7 @@ static struct GNUNET_PeerIdentity my_identity; | |||
216 | * @return NULL for not found | 219 | * @return NULL for not found |
217 | */ | 220 | */ |
218 | static struct Channel * | 221 | static struct Channel * |
219 | find_channel_by_line(struct Line *line, uint32_t cid) | 222 | find_channel_by_line (struct Line *line, uint32_t cid) |
220 | { | 223 | { |
221 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) | 224 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) |
222 | if (cid == ch->cid) | 225 | if (cid == ch->cid) |
@@ -232,8 +235,8 @@ find_channel_by_line(struct Line *line, uint32_t cid) | |||
232 | * @param msg the message from the client | 235 | * @param msg the message from the client |
233 | */ | 236 | */ |
234 | static void | 237 | static void |
235 | handle_client_pickup_message(void *cls, | 238 | handle_client_pickup_message (void *cls, |
236 | const struct ClientPhonePickupMessage *msg) | 239 | const struct ClientPhonePickupMessage *msg) |
237 | { | 240 | { |
238 | struct Line *line = cls; | 241 | struct Line *line = cls; |
239 | struct CadetPhonePickupMessage *mppm; | 242 | struct CadetPhonePickupMessage *mppm; |
@@ -241,56 +244,56 @@ handle_client_pickup_message(void *cls, | |||
241 | struct Channel *ch; | 244 | struct Channel *ch; |
242 | 245 | ||
243 | if (NULL == line->port) | 246 | if (NULL == line->port) |
244 | { | 247 | { |
245 | /* we never opened the port, bad client! */ | 248 | /* we never opened the port, bad client! */ |
246 | GNUNET_break_op(0); | 249 | GNUNET_break_op (0); |
247 | GNUNET_SERVICE_client_drop(line->client); | 250 | GNUNET_SERVICE_client_drop (line->client); |
248 | return; | 251 | return; |
249 | } | 252 | } |
250 | for (ch = line->channel_head; NULL != ch; ch = ch->next) | 253 | for (ch = line->channel_head; NULL != ch; ch = ch->next) |
251 | if (msg->cid == ch->cid) | 254 | if (msg->cid == ch->cid) |
252 | break; | 255 | break; |
253 | if (NULL == ch) | 256 | if (NULL == ch) |
254 | { | 257 | { |
255 | /* could have been destroyed asynchronously, ignore message */ | 258 | /* could have been destroyed asynchronously, ignore message */ |
256 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
257 | GNUNET_SERVICE_client_continue(line->client); | 260 | GNUNET_SERVICE_client_continue (line->client); |
258 | return; | 261 | return; |
259 | } | 262 | } |
260 | switch (ch->status) | 263 | switch (ch->status) |
261 | { | 264 | { |
262 | case CS_CALLEE_INIT: | 265 | case CS_CALLEE_INIT: |
263 | GNUNET_break(0); | 266 | GNUNET_break (0); |
264 | GNUNET_SERVICE_client_drop(line->client); | 267 | GNUNET_SERVICE_client_drop (line->client); |
265 | return; | 268 | return; |
266 | 269 | ||
267 | case CS_CALLEE_RINGING: | 270 | case CS_CALLEE_RINGING: |
268 | ch->status = CS_CALLEE_CONNECTED; | 271 | ch->status = CS_CALLEE_CONNECTED; |
269 | break; | 272 | break; |
270 | 273 | ||
271 | case CS_CALLEE_CONNECTED: | 274 | case CS_CALLEE_CONNECTED: |
272 | GNUNET_break(0); | 275 | GNUNET_break (0); |
273 | GNUNET_SERVICE_client_drop(line->client); | 276 | GNUNET_SERVICE_client_drop (line->client); |
274 | return; | 277 | return; |
275 | 278 | ||
276 | case CS_CALLEE_SHUTDOWN: | 279 | case CS_CALLEE_SHUTDOWN: |
277 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
278 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); | 281 | "Ignoring client's PICKUP message, line is in SHUTDOWN\n"); |
279 | break; | 282 | break; |
280 | 283 | ||
281 | case CS_CALLER_CALLING: | 284 | case CS_CALLER_CALLING: |
282 | case CS_CALLER_CONNECTED: | 285 | case CS_CALLER_CONNECTED: |
283 | case CS_CALLER_SHUTDOWN: | 286 | case CS_CALLER_SHUTDOWN: |
284 | GNUNET_break(0); | 287 | GNUNET_break (0); |
285 | GNUNET_SERVICE_client_drop(line->client); | 288 | GNUNET_SERVICE_client_drop (line->client); |
286 | return; | 289 | return; |
287 | } | 290 | } |
288 | GNUNET_break(CS_CALLEE_CONNECTED == ch->status); | 291 | GNUNET_break (CS_CALLEE_CONNECTED == ch->status); |
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); |
290 | env = | 293 | env = |
291 | GNUNET_MQ_msg(mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); | 294 | GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); |
292 | GNUNET_MQ_send(ch->mq, env); | 295 | GNUNET_MQ_send (ch->mq, env); |
293 | GNUNET_SERVICE_client_continue(line->client); | 296 | GNUNET_SERVICE_client_continue (line->client); |
294 | } | 297 | } |
295 | 298 | ||
296 | 299 | ||
@@ -301,35 +304,35 @@ handle_client_pickup_message(void *cls, | |||
301 | * @param ch channel that went down | 304 | * @param ch channel that went down |
302 | */ | 305 | */ |
303 | static void | 306 | static void |
304 | clean_up_channel(struct Channel *ch) | 307 | clean_up_channel (struct Channel *ch) |
305 | { | 308 | { |
306 | struct Line *line = ch->line; | 309 | struct Line *line = ch->line; |
307 | struct GNUNET_MQ_Envelope *env; | 310 | struct GNUNET_MQ_Envelope *env; |
308 | struct ClientPhoneHangupMessage *hup; | 311 | struct ClientPhoneHangupMessage *hup; |
309 | 312 | ||
310 | switch (ch->status) | 313 | switch (ch->status) |
314 | { | ||
315 | case CS_CALLEE_INIT: | ||
316 | case CS_CALLEE_SHUTDOWN: | ||
317 | case CS_CALLER_SHUTDOWN: | ||
318 | break; | ||
319 | |||
320 | case CS_CALLEE_RINGING: | ||
321 | case CS_CALLEE_CONNECTED: | ||
322 | case CS_CALLER_CALLING: | ||
323 | case CS_CALLER_CONNECTED: | ||
324 | if (NULL != line) | ||
311 | { | 325 | { |
312 | case CS_CALLEE_INIT: | 326 | env = |
313 | case CS_CALLEE_SHUTDOWN: | 327 | GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); |
314 | case CS_CALLER_SHUTDOWN: | 328 | hup->cid = ch->cid; |
315 | break; | 329 | GNUNET_MQ_send (line->mq, env); |
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; | ||
329 | } | 330 | } |
331 | break; | ||
332 | } | ||
330 | if (NULL != line) | 333 | if (NULL != line) |
331 | GNUNET_CONTAINER_DLL_remove(line->channel_head, line->channel_tail, ch); | 334 | GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch); |
332 | GNUNET_free(ch); | 335 | GNUNET_free (ch); |
333 | } | 336 | } |
334 | 337 | ||
335 | 338 | ||
@@ -339,15 +342,15 @@ clean_up_channel(struct Channel *ch) | |||
339 | * @param ch channel to destroy. | 342 | * @param ch channel to destroy. |
340 | */ | 343 | */ |
341 | static void | 344 | static void |
342 | destroy_line_cadet_channels(struct Channel *ch) | 345 | destroy_line_cadet_channels (struct Channel *ch) |
343 | { | 346 | { |
344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); |
345 | if (NULL != ch->channel) | 348 | if (NULL != ch->channel) |
346 | { | 349 | { |
347 | GNUNET_CADET_channel_destroy(ch->channel); | 350 | GNUNET_CADET_channel_destroy (ch->channel); |
348 | ch->channel = NULL; | 351 | ch->channel = NULL; |
349 | } | 352 | } |
350 | clean_up_channel(ch); | 353 | clean_up_channel (ch); |
351 | } | 354 | } |
352 | 355 | ||
353 | 356 | ||
@@ -358,40 +361,40 @@ destroy_line_cadet_channels(struct Channel *ch) | |||
358 | * @param cls the `struct Channel` to reset/terminate | 361 | * @param cls the `struct Channel` to reset/terminate |
359 | */ | 362 | */ |
360 | static void | 363 | static void |
361 | mq_done_finish_caller_shutdown(void *cls) | 364 | mq_done_finish_caller_shutdown (void *cls) |
362 | { | 365 | { |
363 | struct Channel *ch = cls; | 366 | struct Channel *ch = cls; |
364 | 367 | ||
365 | switch (ch->status) | 368 | switch (ch->status) |
366 | { | 369 | { |
367 | case CS_CALLEE_INIT: | 370 | case CS_CALLEE_INIT: |
368 | GNUNET_break(0); | 371 | GNUNET_break (0); |
369 | break; | 372 | break; |
370 | 373 | ||
371 | case CS_CALLEE_RINGING: | 374 | case CS_CALLEE_RINGING: |
372 | GNUNET_break(0); | 375 | GNUNET_break (0); |
373 | break; | 376 | break; |
374 | 377 | ||
375 | case CS_CALLEE_CONNECTED: | 378 | case CS_CALLEE_CONNECTED: |
376 | GNUNET_break(0); | 379 | GNUNET_break (0); |
377 | break; | 380 | break; |
378 | 381 | ||
379 | case CS_CALLEE_SHUTDOWN: | 382 | case CS_CALLEE_SHUTDOWN: |
380 | destroy_line_cadet_channels(ch); | 383 | destroy_line_cadet_channels (ch); |
381 | break; | 384 | break; |
382 | 385 | ||
383 | case CS_CALLER_CALLING: | 386 | case CS_CALLER_CALLING: |
384 | GNUNET_break(0); | 387 | GNUNET_break (0); |
385 | break; | 388 | break; |
386 | 389 | ||
387 | case CS_CALLER_CONNECTED: | 390 | case CS_CALLER_CONNECTED: |
388 | GNUNET_break(0); | 391 | GNUNET_break (0); |
389 | break; | 392 | break; |
390 | 393 | ||
391 | case CS_CALLER_SHUTDOWN: | 394 | case CS_CALLER_SHUTDOWN: |
392 | destroy_line_cadet_channels(ch); | 395 | destroy_line_cadet_channels (ch); |
393 | break; | 396 | break; |
394 | } | 397 | } |
395 | } | 398 | } |
396 | 399 | ||
397 | 400 | ||
@@ -402,8 +405,8 @@ mq_done_finish_caller_shutdown(void *cls) | |||
402 | * @param msg the message from the client | 405 | * @param msg the message from the client |
403 | */ | 406 | */ |
404 | static void | 407 | static void |
405 | handle_client_hangup_message(void *cls, | 408 | handle_client_hangup_message (void *cls, |
406 | const struct ClientPhoneHangupMessage *msg) | 409 | const struct ClientPhoneHangupMessage *msg) |
407 | { | 410 | { |
408 | struct Line *line = cls; | 411 | struct Line *line = cls; |
409 | struct GNUNET_MQ_Envelope *e; | 412 | struct GNUNET_MQ_Envelope *e; |
@@ -414,55 +417,55 @@ handle_client_hangup_message(void *cls, | |||
414 | if (msg->cid == ch->cid) | 417 | if (msg->cid == ch->cid) |
415 | break; | 418 | break; |
416 | if (NULL == ch) | 419 | if (NULL == ch) |
417 | { | 420 | { |
418 | /* could have been destroyed asynchronously, ignore message */ | 421 | /* could have been destroyed asynchronously, ignore message */ |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
420 | GNUNET_SERVICE_client_continue(line->client); | 423 | GNUNET_SERVICE_client_continue (line->client); |
421 | return; | 424 | return; |
422 | } | 425 | } |
423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
424 | "Received HANGUP for channel %u which is in state %d\n", | 427 | "Received HANGUP for channel %u which is in state %d\n", |
425 | msg->cid, | 428 | msg->cid, |
426 | ch->status); | 429 | ch->status); |
427 | switch (ch->status) | 430 | switch (ch->status) |
428 | { | 431 | { |
429 | case CS_CALLEE_INIT: | 432 | case CS_CALLEE_INIT: |
430 | GNUNET_break(0); | 433 | GNUNET_break (0); |
431 | GNUNET_SERVICE_client_drop(line->client); | 434 | GNUNET_SERVICE_client_drop (line->client); |
432 | return; | 435 | return; |
433 | 436 | ||
434 | case CS_CALLEE_RINGING: | 437 | case CS_CALLEE_RINGING: |
435 | ch->status = CS_CALLEE_SHUTDOWN; | 438 | ch->status = CS_CALLEE_SHUTDOWN; |
436 | break; | 439 | break; |
437 | 440 | ||
438 | case CS_CALLEE_CONNECTED: | 441 | case CS_CALLEE_CONNECTED: |
439 | ch->status = CS_CALLEE_SHUTDOWN; | 442 | ch->status = CS_CALLEE_SHUTDOWN; |
440 | break; | 443 | break; |
441 | 444 | ||
442 | case CS_CALLEE_SHUTDOWN: | 445 | case CS_CALLEE_SHUTDOWN: |
443 | /* maybe the other peer closed asynchronously... */ | 446 | /* maybe the other peer closed asynchronously... */ |
444 | GNUNET_SERVICE_client_continue(line->client); | 447 | GNUNET_SERVICE_client_continue (line->client); |
445 | return; | 448 | return; |
446 | 449 | ||
447 | case CS_CALLER_CALLING: | 450 | case CS_CALLER_CALLING: |
448 | ch->status = CS_CALLER_SHUTDOWN; | 451 | ch->status = CS_CALLER_SHUTDOWN; |
449 | break; | 452 | break; |
450 | 453 | ||
451 | case CS_CALLER_CONNECTED: | 454 | case CS_CALLER_CONNECTED: |
452 | ch->status = CS_CALLER_SHUTDOWN; | 455 | ch->status = CS_CALLER_SHUTDOWN; |
453 | break; | 456 | break; |
454 | 457 | ||
455 | case CS_CALLER_SHUTDOWN: | 458 | case CS_CALLER_SHUTDOWN: |
456 | /* maybe the other peer closed asynchronously... */ | 459 | /* maybe the other peer closed asynchronously... */ |
457 | GNUNET_SERVICE_client_continue(line->client); | 460 | GNUNET_SERVICE_client_continue (line->client); |
458 | return; | 461 | return; |
459 | } | 462 | } |
460 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); | 463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); |
461 | e = | 464 | e = |
462 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); | 465 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); |
463 | GNUNET_MQ_notify_sent(e, &mq_done_finish_caller_shutdown, ch); | 466 | GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch); |
464 | GNUNET_MQ_send(ch->mq, e); | 467 | GNUNET_MQ_send (ch->mq, e); |
465 | GNUNET_SERVICE_client_continue(line->client); | 468 | GNUNET_SERVICE_client_continue (line->client); |
466 | } | 469 | } |
467 | 470 | ||
468 | 471 | ||
@@ -473,8 +476,8 @@ handle_client_hangup_message(void *cls, | |||
473 | * @param msg the message from the client | 476 | * @param msg the message from the client |
474 | */ | 477 | */ |
475 | static void | 478 | static void |
476 | handle_client_suspend_message(void *cls, | 479 | handle_client_suspend_message (void *cls, |
477 | const struct ClientPhoneSuspendMessage *msg) | 480 | const struct ClientPhoneSuspendMessage *msg) |
478 | { | 481 | { |
479 | struct Line *line = cls; | 482 | struct Line *line = cls; |
480 | struct GNUNET_MQ_Envelope *e; | 483 | struct GNUNET_MQ_Envelope *e; |
@@ -485,62 +488,62 @@ handle_client_suspend_message(void *cls, | |||
485 | if (msg->cid == ch->cid) | 488 | if (msg->cid == ch->cid) |
486 | break; | 489 | break; |
487 | if (NULL == ch) | 490 | if (NULL == ch) |
488 | { | 491 | { |
489 | /* could have been destroyed asynchronously, ignore message */ | 492 | /* could have been destroyed asynchronously, ignore message */ |
490 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
491 | GNUNET_SERVICE_client_continue(line->client); | 494 | GNUNET_SERVICE_client_continue (line->client); |
492 | return; | 495 | return; |
493 | } | 496 | } |
494 | if (GNUNET_YES == ch->suspended_local) | 497 | if (GNUNET_YES == ch->suspended_local) |
495 | { | 498 | { |
496 | GNUNET_break(0); | 499 | GNUNET_break (0); |
497 | GNUNET_SERVICE_client_drop(line->client); | 500 | GNUNET_SERVICE_client_drop (line->client); |
498 | return; | 501 | return; |
499 | } | 502 | } |
500 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
501 | "Received SUSPEND for channel %u which is in state %d\n", | 504 | "Received SUSPEND for channel %u which is in state %d\n", |
502 | msg->cid, | 505 | msg->cid, |
503 | ch->status); | 506 | ch->status); |
504 | switch (ch->status) | 507 | switch (ch->status) |
505 | { | 508 | { |
506 | case CS_CALLEE_INIT: | 509 | case CS_CALLEE_INIT: |
507 | GNUNET_break(0); | 510 | GNUNET_break (0); |
508 | GNUNET_SERVICE_client_drop(line->client); | 511 | GNUNET_SERVICE_client_drop (line->client); |
509 | return; | 512 | return; |
510 | 513 | ||
511 | case CS_CALLEE_RINGING: | 514 | case CS_CALLEE_RINGING: |
512 | GNUNET_break(0); | 515 | GNUNET_break (0); |
513 | GNUNET_SERVICE_client_drop(line->client); | 516 | GNUNET_SERVICE_client_drop (line->client); |
514 | return; | 517 | return; |
515 | 518 | ||
516 | case CS_CALLEE_CONNECTED: | 519 | case CS_CALLEE_CONNECTED: |
517 | ch->suspended_local = GNUNET_YES; | 520 | ch->suspended_local = GNUNET_YES; |
518 | break; | 521 | break; |
519 | 522 | ||
520 | case CS_CALLEE_SHUTDOWN: | 523 | case CS_CALLEE_SHUTDOWN: |
521 | /* maybe the other peer closed asynchronously... */ | 524 | /* maybe the other peer closed asynchronously... */ |
522 | GNUNET_SERVICE_client_continue(line->client); | 525 | GNUNET_SERVICE_client_continue (line->client); |
523 | return; | 526 | return; |
524 | 527 | ||
525 | case CS_CALLER_CALLING: | 528 | case CS_CALLER_CALLING: |
526 | GNUNET_break(0); | 529 | GNUNET_break (0); |
527 | GNUNET_SERVICE_client_drop(line->client); | 530 | GNUNET_SERVICE_client_drop (line->client); |
528 | return; | 531 | return; |
529 | 532 | ||
530 | case CS_CALLER_CONNECTED: | 533 | case CS_CALLER_CONNECTED: |
531 | ch->suspended_local = GNUNET_YES; | 534 | ch->suspended_local = GNUNET_YES; |
532 | break; | 535 | break; |
533 | 536 | ||
534 | case CS_CALLER_SHUTDOWN: | 537 | case CS_CALLER_SHUTDOWN: |
535 | /* maybe the other peer closed asynchronously... */ | 538 | /* maybe the other peer closed asynchronously... */ |
536 | GNUNET_SERVICE_client_continue(line->client); | 539 | GNUNET_SERVICE_client_continue (line->client); |
537 | return; | 540 | return; |
538 | } | 541 | } |
539 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); | 542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); |
540 | e = | 543 | e = |
541 | GNUNET_MQ_msg(mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); | 544 | GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); |
542 | GNUNET_MQ_send(ch->mq, e); | 545 | GNUNET_MQ_send (ch->mq, e); |
543 | GNUNET_SERVICE_client_continue(line->client); | 546 | GNUNET_SERVICE_client_continue (line->client); |
544 | } | 547 | } |
545 | 548 | ||
546 | 549 | ||
@@ -551,8 +554,8 @@ handle_client_suspend_message(void *cls, | |||
551 | * @param msg the message from the client | 554 | * @param msg the message from the client |
552 | */ | 555 | */ |
553 | static void | 556 | static void |
554 | handle_client_resume_message(void *cls, | 557 | handle_client_resume_message (void *cls, |
555 | const struct ClientPhoneResumeMessage *msg) | 558 | const struct ClientPhoneResumeMessage *msg) |
556 | { | 559 | { |
557 | struct Line *line = cls; | 560 | struct Line *line = cls; |
558 | struct GNUNET_MQ_Envelope *e; | 561 | struct GNUNET_MQ_Envelope *e; |
@@ -563,61 +566,61 @@ handle_client_resume_message(void *cls, | |||
563 | if (msg->cid == ch->cid) | 566 | if (msg->cid == ch->cid) |
564 | break; | 567 | break; |
565 | if (NULL == ch) | 568 | if (NULL == ch) |
566 | { | 569 | { |
567 | /* could have been destroyed asynchronously, ignore message */ | 570 | /* could have been destroyed asynchronously, ignore message */ |
568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
569 | GNUNET_SERVICE_client_continue(line->client); | 572 | GNUNET_SERVICE_client_continue (line->client); |
570 | return; | 573 | return; |
571 | } | 574 | } |
572 | if (GNUNET_YES != ch->suspended_local) | 575 | if (GNUNET_YES != ch->suspended_local) |
573 | { | 576 | { |
574 | GNUNET_break(0); | 577 | GNUNET_break (0); |
575 | GNUNET_SERVICE_client_drop(line->client); | 578 | GNUNET_SERVICE_client_drop (line->client); |
576 | return; | 579 | return; |
577 | } | 580 | } |
578 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
579 | "Received RESUME for channel %u which is in state %d\n", | 582 | "Received RESUME for channel %u which is in state %d\n", |
580 | msg->cid, | 583 | msg->cid, |
581 | ch->status); | 584 | ch->status); |
582 | switch (ch->status) | 585 | switch (ch->status) |
583 | { | 586 | { |
584 | case CS_CALLEE_INIT: | 587 | case CS_CALLEE_INIT: |
585 | GNUNET_break(0); | 588 | GNUNET_break (0); |
586 | GNUNET_SERVICE_client_drop(line->client); | 589 | GNUNET_SERVICE_client_drop (line->client); |
587 | return; | 590 | return; |
588 | 591 | ||
589 | case CS_CALLEE_RINGING: | 592 | case CS_CALLEE_RINGING: |
590 | GNUNET_break(0); | 593 | GNUNET_break (0); |
591 | GNUNET_SERVICE_client_drop(line->client); | 594 | GNUNET_SERVICE_client_drop (line->client); |
592 | return; | 595 | return; |
593 | 596 | ||
594 | case CS_CALLEE_CONNECTED: | 597 | case CS_CALLEE_CONNECTED: |
595 | ch->suspended_local = GNUNET_NO; | 598 | ch->suspended_local = GNUNET_NO; |
596 | break; | 599 | break; |
597 | 600 | ||
598 | case CS_CALLEE_SHUTDOWN: | 601 | case CS_CALLEE_SHUTDOWN: |
599 | /* maybe the other peer closed asynchronously... */ | 602 | /* maybe the other peer closed asynchronously... */ |
600 | GNUNET_SERVICE_client_continue(line->client); | 603 | GNUNET_SERVICE_client_continue (line->client); |
601 | return; | 604 | return; |
602 | 605 | ||
603 | case CS_CALLER_CALLING: | 606 | case CS_CALLER_CALLING: |
604 | GNUNET_break(0); | 607 | GNUNET_break (0); |
605 | GNUNET_SERVICE_client_drop(line->client); | 608 | GNUNET_SERVICE_client_drop (line->client); |
606 | return; | 609 | return; |
607 | 610 | ||
608 | case CS_CALLER_CONNECTED: | 611 | case CS_CALLER_CONNECTED: |
609 | ch->suspended_local = GNUNET_NO; | 612 | ch->suspended_local = GNUNET_NO; |
610 | break; | 613 | break; |
611 | 614 | ||
612 | case CS_CALLER_SHUTDOWN: | 615 | case CS_CALLER_SHUTDOWN: |
613 | /* maybe the other peer closed asynchronously... */ | 616 | /* maybe the other peer closed asynchronously... */ |
614 | GNUNET_SERVICE_client_drop(line->client); | 617 | GNUNET_SERVICE_client_drop (line->client); |
615 | return; | 618 | return; |
616 | } | 619 | } |
617 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); | 620 | 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); | 621 | e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); |
619 | GNUNET_MQ_send(ch->mq, e); | 622 | GNUNET_MQ_send (ch->mq, e); |
620 | GNUNET_SERVICE_client_continue(line->client); | 623 | GNUNET_SERVICE_client_continue (line->client); |
621 | } | 624 | } |
622 | 625 | ||
623 | 626 | ||
@@ -627,7 +630,7 @@ handle_client_resume_message(void *cls, | |||
627 | * @param cls the `struct Channel` we are transmitting for | 630 | * @param cls the `struct Channel` we are transmitting for |
628 | */ | 631 | */ |
629 | static void | 632 | static void |
630 | channel_audio_sent_notify(void *cls) | 633 | channel_audio_sent_notify (void *cls) |
631 | { | 634 | { |
632 | struct Channel *ch = cls; | 635 | struct Channel *ch = cls; |
633 | 636 | ||
@@ -643,10 +646,10 @@ channel_audio_sent_notify(void *cls) | |||
643 | * @return #GNUNET_OK (any data is ok) | 646 | * @return #GNUNET_OK (any data is ok) |
644 | */ | 647 | */ |
645 | static int | 648 | static int |
646 | check_client_audio_message(void *cls, const struct ClientAudioMessage *msg) | 649 | check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) |
647 | { | 650 | { |
648 | (void)cls; | 651 | (void) cls; |
649 | (void)msg; | 652 | (void) msg; |
650 | return GNUNET_OK; | 653 | return GNUNET_OK; |
651 | } | 654 | } |
652 | 655 | ||
@@ -658,72 +661,72 @@ check_client_audio_message(void *cls, const struct ClientAudioMessage *msg) | |||
658 | * @param msg the message from the client | 661 | * @param msg the message from the client |
659 | */ | 662 | */ |
660 | static void | 663 | static void |
661 | handle_client_audio_message(void *cls, const struct ClientAudioMessage *msg) | 664 | handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) |
662 | { | 665 | { |
663 | struct Line *line = cls; | 666 | struct Line *line = cls; |
664 | struct CadetAudioMessage *mam; | 667 | struct CadetAudioMessage *mam; |
665 | struct Channel *ch; | 668 | struct Channel *ch; |
666 | size_t size; | 669 | size_t size; |
667 | 670 | ||
668 | size = ntohs(msg->header.size) - sizeof(struct ClientAudioMessage); | 671 | size = ntohs (msg->header.size) - sizeof(struct ClientAudioMessage); |
669 | ch = find_channel_by_line(line, msg->cid); | 672 | ch = find_channel_by_line (line, msg->cid); |
670 | if (NULL == ch) | 673 | if (NULL == ch) |
671 | { | 674 | { |
672 | /* could have been destroyed asynchronously, ignore message */ | 675 | /* could have been destroyed asynchronously, ignore message */ |
673 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); | 676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); |
674 | GNUNET_SERVICE_client_continue(line->client); | 677 | GNUNET_SERVICE_client_continue (line->client); |
675 | return; | 678 | return; |
676 | } | 679 | } |
677 | 680 | ||
678 | switch (ch->status) | 681 | switch (ch->status) |
679 | { | 682 | { |
680 | case CS_CALLEE_INIT: | 683 | case CS_CALLEE_INIT: |
681 | case CS_CALLEE_RINGING: | 684 | case CS_CALLEE_RINGING: |
682 | case CS_CALLER_CALLING: | 685 | case CS_CALLER_CALLING: |
683 | GNUNET_break(0); | 686 | GNUNET_break (0); |
684 | GNUNET_SERVICE_client_drop(line->client); | 687 | GNUNET_SERVICE_client_drop (line->client); |
685 | return; | 688 | return; |
686 | 689 | ||
687 | case CS_CALLEE_CONNECTED: | 690 | case CS_CALLEE_CONNECTED: |
688 | case CS_CALLER_CONNECTED: | 691 | case CS_CALLER_CONNECTED: |
689 | /* common case, handled below */ | 692 | /* common case, handled below */ |
690 | break; | 693 | break; |
691 | 694 | ||
692 | case CS_CALLEE_SHUTDOWN: | 695 | case CS_CALLEE_SHUTDOWN: |
693 | case CS_CALLER_SHUTDOWN: | 696 | case CS_CALLER_SHUTDOWN: |
694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
695 | "Cadet audio channel in shutdown; audio data dropped\n"); | 698 | "Cadet audio channel in shutdown; audio data dropped\n"); |
696 | GNUNET_SERVICE_client_continue(line->client); | 699 | GNUNET_SERVICE_client_continue (line->client); |
697 | return; | 700 | return; |
698 | } | 701 | } |
699 | if (GNUNET_YES == ch->suspended_local) | 702 | if (GNUNET_YES == ch->suspended_local) |
700 | { | 703 | { |
701 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 704 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
702 | "This channel is suspended locally\n"); | 705 | "This channel is suspended locally\n"); |
703 | GNUNET_SERVICE_client_drop(line->client); | 706 | GNUNET_SERVICE_client_drop (line->client); |
704 | return; | 707 | return; |
705 | } | 708 | } |
706 | if (NULL != ch->env) | 709 | if (NULL != ch->env) |
707 | { | 710 | { |
708 | /* NOTE: we may want to not do this and instead combine the data */ | 711 | /* NOTE: we may want to not do this and instead combine the data */ |
709 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
710 | "Bandwidth insufficient; dropping previous audio data segment\n"); | 713 | "Bandwidth insufficient; dropping previous audio data segment\n"); |
711 | GNUNET_MQ_send_cancel(ch->env); | 714 | GNUNET_MQ_send_cancel (ch->env); |
712 | ch->env = NULL; | 715 | ch->env = NULL; |
713 | } | 716 | } |
714 | 717 | ||
715 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
716 | "Received %u bytes of AUDIO data from client CID %u\n", | 719 | "Received %u bytes of AUDIO data from client CID %u\n", |
717 | (unsigned int)size, | 720 | (unsigned int) size, |
718 | msg->cid); | 721 | msg->cid); |
719 | ch->env = GNUNET_MQ_msg_extra(mam, | 722 | ch->env = GNUNET_MQ_msg_extra (mam, |
720 | size, | 723 | size, |
721 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); | 724 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); |
722 | GNUNET_memcpy(&mam[1], &msg[1], size); | 725 | GNUNET_memcpy (&mam[1], &msg[1], size); |
723 | /* FIXME: set options for unreliable transmission */ | 726 | /* FIXME: set options for unreliable transmission */ |
724 | GNUNET_MQ_notify_sent(ch->env, &channel_audio_sent_notify, ch); | 727 | GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch); |
725 | GNUNET_MQ_send(ch->mq, ch->env); | 728 | GNUNET_MQ_send (ch->mq, ch->env); |
726 | GNUNET_SERVICE_client_continue(line->client); | 729 | GNUNET_SERVICE_client_continue (line->client); |
727 | } | 730 | } |
728 | 731 | ||
729 | 732 | ||
@@ -734,7 +737,7 @@ handle_client_audio_message(void *cls, const struct ClientAudioMessage *msg) | |||
734 | * @param msg the incoming message | 737 | * @param msg the incoming message |
735 | */ | 738 | */ |
736 | static void | 739 | static void |
737 | handle_cadet_ring_message(void *cls, const struct CadetPhoneRingMessage *msg) | 740 | handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) |
738 | { | 741 | { |
739 | struct Channel *ch = cls; | 742 | struct Channel *ch = cls; |
740 | struct Line *line = ch->line; | 743 | struct Line *line = ch->line; |
@@ -742,49 +745,49 @@ handle_cadet_ring_message(void *cls, const struct CadetPhoneRingMessage *msg) | |||
742 | struct ClientPhoneRingMessage *cring; | 745 | struct ClientPhoneRingMessage *cring; |
743 | struct CadetPhoneRingInfoPS rs; | 746 | struct CadetPhoneRingInfoPS rs; |
744 | 747 | ||
745 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 748 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
746 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); | 749 | rs.purpose.size = htonl (sizeof(struct CadetPhoneRingInfoPS)); |
747 | rs.line_port = line->line_port; | 750 | rs.line_port = line->line_port; |
748 | rs.target_peer = my_identity; | 751 | rs.target_peer = my_identity; |
749 | rs.expiration_time = msg->expiration_time; | 752 | rs.expiration_time = msg->expiration_time; |
750 | 753 | ||
751 | if (GNUNET_OK != | 754 | if (GNUNET_OK != |
752 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, | 755 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, |
753 | &rs.purpose, | 756 | &rs.purpose, |
754 | &msg->signature, | 757 | &msg->signature, |
755 | &msg->caller_id)) | 758 | &msg->caller_id)) |
756 | { | 759 | { |
757 | GNUNET_break_op(0); | 760 | GNUNET_break_op (0); |
758 | destroy_line_cadet_channels(ch); | 761 | destroy_line_cadet_channels (ch); |
759 | return; | 762 | return; |
760 | } | 763 | } |
761 | if (0 == GNUNET_TIME_absolute_get_remaining( | 764 | if (0 == GNUNET_TIME_absolute_get_remaining ( |
762 | GNUNET_TIME_absolute_ntoh(msg->expiration_time)) | 765 | GNUNET_TIME_absolute_ntoh (msg->expiration_time)) |
763 | .rel_value_us) | 766 | .rel_value_us) |
764 | { | 767 | { |
765 | /* ancient call, replay? */ | 768 | /* ancient call, replay? */ |
766 | GNUNET_break_op(0); | 769 | GNUNET_break_op (0); |
767 | /* Note that our reliance on time here is awkward; better would be | 770 | /* Note that our reliance on time here is awkward; better would be |
768 | to use a more complex challenge-response protocol against | 771 | to use a more complex challenge-response protocol against |
769 | replay attacks. Left for future work ;-). */ | 772 | replay attacks. Left for future work ;-). */ |
770 | destroy_line_cadet_channels(ch); | 773 | destroy_line_cadet_channels (ch); |
771 | return; | 774 | return; |
772 | } | 775 | } |
773 | if (CS_CALLEE_INIT != ch->status) | 776 | if (CS_CALLEE_INIT != ch->status) |
774 | { | 777 | { |
775 | GNUNET_break_op(0); | 778 | GNUNET_break_op (0); |
776 | destroy_line_cadet_channels(ch); | 779 | destroy_line_cadet_channels (ch); |
777 | return; | 780 | return; |
778 | } | 781 | } |
779 | GNUNET_CADET_receive_done(ch->channel); | 782 | GNUNET_CADET_receive_done (ch->channel); |
780 | ch->status = CS_CALLEE_RINGING; | 783 | ch->status = CS_CALLEE_RINGING; |
781 | env = GNUNET_MQ_msg(cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); | 784 | env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); |
782 | cring->cid = ch->cid; | 785 | cring->cid = ch->cid; |
783 | cring->caller_id = msg->caller_id; | 786 | cring->caller_id = msg->caller_id; |
784 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
785 | "Sending RING message to client. CID is %u\n", | 788 | "Sending RING message to client. CID is %u\n", |
786 | (unsigned int)ch->cid); | 789 | (unsigned int) ch->cid); |
787 | GNUNET_MQ_send(line->mq, env); | 790 | GNUNET_MQ_send (line->mq, env); |
788 | } | 791 | } |
789 | 792 | ||
790 | 793 | ||
@@ -795,8 +798,8 @@ handle_cadet_ring_message(void *cls, const struct CadetPhoneRingMessage *msg) | |||
795 | * @param message the incoming message | 798 | * @param message the incoming message |
796 | */ | 799 | */ |
797 | static void | 800 | static void |
798 | handle_cadet_hangup_message(void *cls, | 801 | handle_cadet_hangup_message (void *cls, |
799 | const struct CadetPhoneHangupMessage *message) | 802 | const struct CadetPhoneHangupMessage *message) |
800 | { | 803 | { |
801 | struct Channel *ch = cls; | 804 | struct Channel *ch = cls; |
802 | struct Line *line = ch->line; | 805 | struct Line *line = ch->line; |
@@ -805,35 +808,35 @@ handle_cadet_hangup_message(void *cls, | |||
805 | enum ChannelStatus status; | 808 | enum ChannelStatus status; |
806 | uint32_t cid; | 809 | uint32_t cid; |
807 | 810 | ||
808 | (void)message; | 811 | (void) message; |
809 | GNUNET_CADET_receive_done(ch->channel); | 812 | GNUNET_CADET_receive_done (ch->channel); |
810 | cid = ch->cid; | 813 | cid = ch->cid; |
811 | status = ch->status; | 814 | status = ch->status; |
812 | destroy_line_cadet_channels(ch); | 815 | destroy_line_cadet_channels (ch); |
813 | switch (status) | 816 | switch (status) |
814 | { | 817 | { |
815 | case CS_CALLEE_INIT: | 818 | case CS_CALLEE_INIT: |
816 | GNUNET_break_op(0); | 819 | GNUNET_break_op (0); |
817 | return; | 820 | return; |
818 | 821 | ||
819 | case CS_CALLEE_RINGING: | 822 | case CS_CALLEE_RINGING: |
820 | case CS_CALLEE_CONNECTED: | 823 | case CS_CALLEE_CONNECTED: |
821 | break; | 824 | break; |
822 | 825 | ||
823 | case CS_CALLEE_SHUTDOWN: | 826 | case CS_CALLEE_SHUTDOWN: |
824 | return; | 827 | return; |
825 | 828 | ||
826 | case CS_CALLER_CALLING: | 829 | case CS_CALLER_CALLING: |
827 | case CS_CALLER_CONNECTED: | 830 | case CS_CALLER_CONNECTED: |
828 | break; | 831 | break; |
829 | 832 | ||
830 | case CS_CALLER_SHUTDOWN: | 833 | case CS_CALLER_SHUTDOWN: |
831 | return; | 834 | return; |
832 | } | 835 | } |
833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); | 836 | 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); | 837 | env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); |
835 | hup->cid = cid; | 838 | hup->cid = cid; |
836 | GNUNET_MQ_send(line->mq, env); | 839 | GNUNET_MQ_send (line->mq, env); |
837 | } | 840 | } |
838 | 841 | ||
839 | 842 | ||
@@ -844,48 +847,48 @@ handle_cadet_hangup_message(void *cls, | |||
844 | * @param message the incoming message | 847 | * @param message the incoming message |
845 | */ | 848 | */ |
846 | static void | 849 | static void |
847 | handle_cadet_pickup_message(void *cls, | 850 | handle_cadet_pickup_message (void *cls, |
848 | const struct CadetPhonePickupMessage *message) | 851 | const struct CadetPhonePickupMessage *message) |
849 | { | 852 | { |
850 | struct Channel *ch = cls; | 853 | struct Channel *ch = cls; |
851 | struct Line *line = ch->line; | 854 | struct Line *line = ch->line; |
852 | struct GNUNET_MQ_Envelope *env; | 855 | struct GNUNET_MQ_Envelope *env; |
853 | struct ClientPhonePickedupMessage *pick; | 856 | struct ClientPhonePickedupMessage *pick; |
854 | 857 | ||
855 | (void)message; | 858 | (void) message; |
856 | GNUNET_CADET_receive_done(ch->channel); | 859 | GNUNET_CADET_receive_done (ch->channel); |
857 | switch (ch->status) | 860 | switch (ch->status) |
858 | { | 861 | { |
859 | case CS_CALLEE_INIT: | 862 | case CS_CALLEE_INIT: |
860 | case CS_CALLEE_RINGING: | 863 | case CS_CALLEE_RINGING: |
861 | case CS_CALLEE_CONNECTED: | 864 | case CS_CALLEE_CONNECTED: |
862 | GNUNET_break_op(0); | 865 | GNUNET_break_op (0); |
863 | destroy_line_cadet_channels(ch); | 866 | destroy_line_cadet_channels (ch); |
864 | return; | 867 | return; |
865 | 868 | ||
866 | case CS_CALLEE_SHUTDOWN: | 869 | case CS_CALLEE_SHUTDOWN: |
867 | GNUNET_break_op(0); | 870 | GNUNET_break_op (0); |
868 | destroy_line_cadet_channels(ch); | 871 | destroy_line_cadet_channels (ch); |
869 | return; | 872 | return; |
870 | 873 | ||
871 | case CS_CALLER_CALLING: | 874 | case CS_CALLER_CALLING: |
872 | ch->status = CS_CALLER_CONNECTED; | 875 | ch->status = CS_CALLER_CONNECTED; |
873 | break; | 876 | break; |
874 | 877 | ||
875 | case CS_CALLER_CONNECTED: | 878 | case CS_CALLER_CONNECTED: |
876 | GNUNET_break_op(0); | 879 | GNUNET_break_op (0); |
877 | return; | 880 | return; |
878 | 881 | ||
879 | case CS_CALLER_SHUTDOWN: | 882 | case CS_CALLER_SHUTDOWN: |
880 | GNUNET_break_op(0); | 883 | GNUNET_break_op (0); |
881 | mq_done_finish_caller_shutdown(ch); | 884 | mq_done_finish_caller_shutdown (ch); |
882 | return; | 885 | return; |
883 | } | 886 | } |
884 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); | 887 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); |
885 | env = | 888 | env = |
886 | GNUNET_MQ_msg(pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); | 889 | GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); |
887 | pick->cid = ch->cid; | 890 | pick->cid = ch->cid; |
888 | GNUNET_MQ_send(line->mq, env); | 891 | GNUNET_MQ_send (line->mq, env); |
889 | } | 892 | } |
890 | 893 | ||
891 | 894 | ||
@@ -896,49 +899,49 @@ handle_cadet_pickup_message(void *cls, | |||
896 | * @param message the incoming message | 899 | * @param message the incoming message |
897 | */ | 900 | */ |
898 | static void | 901 | static void |
899 | handle_cadet_suspend_message(void *cls, | 902 | handle_cadet_suspend_message (void *cls, |
900 | const struct CadetPhoneSuspendMessage *message) | 903 | const struct CadetPhoneSuspendMessage *message) |
901 | { | 904 | { |
902 | struct Channel *ch = cls; | 905 | struct Channel *ch = cls; |
903 | struct Line *line = ch->line; | 906 | struct Line *line = ch->line; |
904 | struct GNUNET_MQ_Envelope *env; | 907 | struct GNUNET_MQ_Envelope *env; |
905 | struct ClientPhoneSuspendMessage *suspend; | 908 | struct ClientPhoneSuspendMessage *suspend; |
906 | 909 | ||
907 | (void)message; | 910 | (void) message; |
908 | GNUNET_CADET_receive_done(ch->channel); | 911 | GNUNET_CADET_receive_done (ch->channel); |
909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); | 912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); |
910 | switch (ch->status) | 913 | switch (ch->status) |
911 | { | 914 | { |
912 | case CS_CALLEE_INIT: | 915 | case CS_CALLEE_INIT: |
913 | GNUNET_break_op(0); | 916 | GNUNET_break_op (0); |
914 | break; | 917 | break; |
915 | 918 | ||
916 | case CS_CALLEE_RINGING: | 919 | case CS_CALLEE_RINGING: |
917 | GNUNET_break_op(0); | 920 | GNUNET_break_op (0); |
918 | break; | 921 | break; |
919 | 922 | ||
920 | case CS_CALLEE_CONNECTED: | 923 | case CS_CALLEE_CONNECTED: |
921 | ch->suspended_remote = GNUNET_YES; | 924 | ch->suspended_remote = GNUNET_YES; |
922 | break; | 925 | break; |
923 | 926 | ||
924 | case CS_CALLEE_SHUTDOWN: | 927 | case CS_CALLEE_SHUTDOWN: |
925 | return; | 928 | return; |
926 | 929 | ||
927 | case CS_CALLER_CALLING: | 930 | case CS_CALLER_CALLING: |
928 | GNUNET_break_op(0); | 931 | GNUNET_break_op (0); |
929 | break; | 932 | break; |
930 | 933 | ||
931 | case CS_CALLER_CONNECTED: | 934 | case CS_CALLER_CONNECTED: |
932 | ch->suspended_remote = GNUNET_YES; | 935 | ch->suspended_remote = GNUNET_YES; |
933 | break; | 936 | break; |
934 | 937 | ||
935 | case CS_CALLER_SHUTDOWN: | 938 | case CS_CALLER_SHUTDOWN: |
936 | return; | 939 | return; |
937 | } | 940 | } |
938 | env = | 941 | env = |
939 | GNUNET_MQ_msg(suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 942 | GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
940 | suspend->cid = ch->cid; | 943 | suspend->cid = ch->cid; |
941 | GNUNET_MQ_send(line->mq, env); | 944 | GNUNET_MQ_send (line->mq, env); |
942 | } | 945 | } |
943 | 946 | ||
944 | 947 | ||
@@ -949,57 +952,57 @@ handle_cadet_suspend_message(void *cls, | |||
949 | * @param msg the incoming message | 952 | * @param msg the incoming message |
950 | */ | 953 | */ |
951 | static void | 954 | static void |
952 | handle_cadet_resume_message(void *cls, | 955 | handle_cadet_resume_message (void *cls, |
953 | const struct CadetPhoneResumeMessage *msg) | 956 | const struct CadetPhoneResumeMessage *msg) |
954 | { | 957 | { |
955 | struct Channel *ch = cls; | 958 | struct Channel *ch = cls; |
956 | struct Line *line; | 959 | struct Line *line; |
957 | struct GNUNET_MQ_Envelope *env; | 960 | struct GNUNET_MQ_Envelope *env; |
958 | struct ClientPhoneResumeMessage *resume; | 961 | struct ClientPhoneResumeMessage *resume; |
959 | 962 | ||
960 | (void)msg; | 963 | (void) msg; |
961 | line = ch->line; | 964 | line = ch->line; |
962 | GNUNET_CADET_receive_done(ch->channel); | 965 | GNUNET_CADET_receive_done (ch->channel); |
963 | if (GNUNET_YES != ch->suspended_remote) | 966 | if (GNUNET_YES != ch->suspended_remote) |
964 | { | 967 | { |
965 | GNUNET_log( | 968 | GNUNET_log ( |
966 | GNUNET_ERROR_TYPE_DEBUG, | 969 | GNUNET_ERROR_TYPE_DEBUG, |
967 | "RESUME message received for non-suspended channel, dropping channel.\n"); | 970 | "RESUME message received for non-suspended channel, dropping channel.\n"); |
968 | destroy_line_cadet_channels(ch); | 971 | destroy_line_cadet_channels (ch); |
969 | return; | 972 | return; |
970 | } | 973 | } |
971 | switch (ch->status) | 974 | switch (ch->status) |
972 | { | 975 | { |
973 | case CS_CALLEE_INIT: | 976 | case CS_CALLEE_INIT: |
974 | GNUNET_break(0); | 977 | GNUNET_break (0); |
975 | break; | 978 | break; |
976 | 979 | ||
977 | case CS_CALLEE_RINGING: | 980 | case CS_CALLEE_RINGING: |
978 | GNUNET_break(0); | 981 | GNUNET_break (0); |
979 | break; | 982 | break; |
980 | 983 | ||
981 | case CS_CALLEE_CONNECTED: | 984 | case CS_CALLEE_CONNECTED: |
982 | ch->suspended_remote = GNUNET_NO; | 985 | ch->suspended_remote = GNUNET_NO; |
983 | break; | 986 | break; |
984 | 987 | ||
985 | case CS_CALLEE_SHUTDOWN: | 988 | case CS_CALLEE_SHUTDOWN: |
986 | return; | 989 | return; |
987 | 990 | ||
988 | case CS_CALLER_CALLING: | 991 | case CS_CALLER_CALLING: |
989 | GNUNET_break(0); | 992 | GNUNET_break (0); |
990 | break; | 993 | break; |
991 | 994 | ||
992 | case CS_CALLER_CONNECTED: | 995 | case CS_CALLER_CONNECTED: |
993 | ch->suspended_remote = GNUNET_NO; | 996 | ch->suspended_remote = GNUNET_NO; |
994 | break; | 997 | break; |
995 | 998 | ||
996 | case CS_CALLER_SHUTDOWN: | 999 | case CS_CALLER_SHUTDOWN: |
997 | return; | 1000 | return; |
998 | } | 1001 | } |
999 | env = | 1002 | env = |
1000 | GNUNET_MQ_msg(resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 1003 | GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
1001 | resume->cid = ch->cid; | 1004 | resume->cid = ch->cid; |
1002 | GNUNET_MQ_send(line->mq, env); | 1005 | GNUNET_MQ_send (line->mq, env); |
1003 | } | 1006 | } |
1004 | 1007 | ||
1005 | 1008 | ||
@@ -1011,10 +1014,10 @@ handle_cadet_resume_message(void *cls, | |||
1011 | * @return #GNUNET_OK (always) | 1014 | * @return #GNUNET_OK (always) |
1012 | */ | 1015 | */ |
1013 | static int | 1016 | static int |
1014 | check_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) | 1017 | check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) |
1015 | { | 1018 | { |
1016 | (void)cls; | 1019 | (void) cls; |
1017 | (void)msg; | 1020 | (void) msg; |
1018 | return GNUNET_OK; /* any payload is fine */ | 1021 | return GNUNET_OK; /* any payload is fine */ |
1019 | } | 1022 | } |
1020 | 1023 | ||
@@ -1026,33 +1029,33 @@ check_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) | |||
1026 | * @param msg the incoming message | 1029 | * @param msg the incoming message |
1027 | */ | 1030 | */ |
1028 | static void | 1031 | static void |
1029 | handle_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) | 1032 | handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) |
1030 | { | 1033 | { |
1031 | struct Channel *ch = cls; | 1034 | struct Channel *ch = cls; |
1032 | size_t msize = ntohs(msg->header.size) - sizeof(struct CadetAudioMessage); | 1035 | size_t msize = ntohs (msg->header.size) - sizeof(struct CadetAudioMessage); |
1033 | struct GNUNET_MQ_Envelope *env; | 1036 | struct GNUNET_MQ_Envelope *env; |
1034 | struct ClientAudioMessage *cam; | 1037 | struct ClientAudioMessage *cam; |
1035 | 1038 | ||
1036 | GNUNET_CADET_receive_done(ch->channel); | 1039 | GNUNET_CADET_receive_done (ch->channel); |
1037 | if ((GNUNET_YES == ch->suspended_local) || | 1040 | if ((GNUNET_YES == ch->suspended_local) || |
1038 | (GNUNET_YES == ch->suspended_remote)) | 1041 | (GNUNET_YES == ch->suspended_remote)) |
1039 | { | 1042 | { |
1040 | GNUNET_log( | 1043 | GNUNET_log ( |
1041 | GNUNET_ERROR_TYPE_DEBUG, | 1044 | GNUNET_ERROR_TYPE_DEBUG, |
1042 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", | 1045 | "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", |
1043 | (unsigned int)msize, | 1046 | (unsigned int) msize, |
1044 | ch->cid); | 1047 | ch->cid); |
1045 | return; | 1048 | return; |
1046 | } | 1049 | } |
1047 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1050 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1048 | "Forwarding %u bytes of AUDIO data to client CID %u\n", | 1051 | "Forwarding %u bytes of AUDIO data to client CID %u\n", |
1049 | (unsigned int)msize, | 1052 | (unsigned int) msize, |
1050 | ch->cid); | 1053 | ch->cid); |
1051 | env = | 1054 | env = |
1052 | GNUNET_MQ_msg_extra(cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 1055 | GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
1053 | cam->cid = ch->cid; | 1056 | cam->cid = ch->cid; |
1054 | GNUNET_memcpy(&cam[1], &msg[1], msize); | 1057 | GNUNET_memcpy (&cam[1], &msg[1], msize); |
1055 | GNUNET_MQ_send(ch->line->mq, env); | 1058 | GNUNET_MQ_send (ch->line->mq, env); |
1056 | } | 1059 | } |
1057 | 1060 | ||
1058 | 1061 | ||
@@ -1064,16 +1067,16 @@ handle_cadet_audio_message(void *cls, const struct CadetAudioMessage *msg) | |||
1064 | * @param channel connection to the other end (henceforth invalid) | 1067 | * @param channel connection to the other end (henceforth invalid) |
1065 | */ | 1068 | */ |
1066 | static void | 1069 | static void |
1067 | inbound_end(void *cls, const struct GNUNET_CADET_Channel *channel) | 1070 | inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) |
1068 | { | 1071 | { |
1069 | struct Channel *ch = cls; | 1072 | struct Channel *ch = cls; |
1070 | 1073 | ||
1071 | GNUNET_assert(channel == ch->channel); | 1074 | GNUNET_assert (channel == ch->channel); |
1072 | ch->channel = NULL; | 1075 | ch->channel = NULL; |
1073 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1076 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1074 | "Channel destroyed by CADET in state %d\n", | 1077 | "Channel destroyed by CADET in state %d\n", |
1075 | ch->status); | 1078 | ch->status); |
1076 | clean_up_channel(ch); | 1079 | clean_up_channel (ch); |
1077 | } | 1080 | } |
1078 | 1081 | ||
1079 | 1082 | ||
@@ -1084,63 +1087,63 @@ inbound_end(void *cls, const struct GNUNET_CADET_Channel *channel) | |||
1084 | * @param msg the message from the client | 1087 | * @param msg the message from the client |
1085 | */ | 1088 | */ |
1086 | static void | 1089 | static void |
1087 | handle_client_call_message(void *cls, const struct ClientCallMessage *msg) | 1090 | handle_client_call_message (void *cls, const struct ClientCallMessage *msg) |
1088 | { | 1091 | { |
1089 | struct Line *line = cls; | 1092 | struct Line *line = cls; |
1090 | struct Channel *ch = GNUNET_new(struct Channel); | 1093 | struct Channel *ch = GNUNET_new (struct Channel); |
1091 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1094 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1092 | { GNUNET_MQ_hd_fixed_size(cadet_hangup_message, | 1095 | { GNUNET_MQ_hd_fixed_size (cadet_hangup_message, |
1093 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1096 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1094 | struct CadetPhoneHangupMessage, | 1097 | struct CadetPhoneHangupMessage, |
1095 | ch), | 1098 | ch), |
1096 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, | 1099 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, |
1097 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | 1100 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, |
1098 | struct CadetPhonePickupMessage, | 1101 | struct CadetPhonePickupMessage, |
1099 | ch), | 1102 | ch), |
1100 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, | 1103 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, |
1101 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | 1104 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, |
1102 | struct CadetPhoneSuspendMessage, | 1105 | struct CadetPhoneSuspendMessage, |
1103 | ch), | 1106 | ch), |
1104 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, | 1107 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, |
1105 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | 1108 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, |
1106 | struct CadetPhoneResumeMessage, | 1109 | struct CadetPhoneResumeMessage, |
1107 | ch), | 1110 | ch), |
1108 | GNUNET_MQ_hd_var_size(cadet_audio_message, | 1111 | GNUNET_MQ_hd_var_size (cadet_audio_message, |
1109 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | 1112 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, |
1110 | struct CadetAudioMessage, | 1113 | struct CadetAudioMessage, |
1111 | ch), | 1114 | ch), |
1112 | GNUNET_MQ_handler_end() }; | 1115 | GNUNET_MQ_handler_end () }; |
1113 | struct GNUNET_MQ_Envelope *e; | 1116 | struct GNUNET_MQ_Envelope *e; |
1114 | struct CadetPhoneRingMessage *ring; | 1117 | struct CadetPhoneRingMessage *ring; |
1115 | struct CadetPhoneRingInfoPS rs; | 1118 | struct CadetPhoneRingInfoPS rs; |
1116 | 1119 | ||
1117 | line->line_port = msg->line_port; | 1120 | line->line_port = msg->line_port; |
1118 | rs.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); | 1121 | rs.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING); |
1119 | rs.purpose.size = htonl(sizeof(struct CadetPhoneRingInfoPS)); | 1122 | rs.purpose.size = htonl (sizeof(struct CadetPhoneRingInfoPS)); |
1120 | rs.line_port = line->line_port; | 1123 | rs.line_port = line->line_port; |
1121 | rs.target_peer = msg->target; | 1124 | rs.target_peer = msg->target; |
1122 | rs.expiration_time = | 1125 | rs.expiration_time = |
1123 | GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(RING_TIMEOUT)); | 1126 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); |
1124 | ch->line = line; | 1127 | ch->line = line; |
1125 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); | 1128 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); |
1126 | ch->status = CS_CALLER_CALLING; | 1129 | ch->status = CS_CALLER_CALLING; |
1127 | ch->channel = GNUNET_CADET_channel_create(cadet, | 1130 | ch->channel = GNUNET_CADET_channel_create (cadet, |
1128 | ch, | 1131 | ch, |
1129 | &msg->target, | 1132 | &msg->target, |
1130 | &msg->line_port, | 1133 | &msg->line_port, |
1131 | NULL, | 1134 | NULL, |
1132 | &inbound_end, | 1135 | &inbound_end, |
1133 | cadet_handlers); | 1136 | cadet_handlers); |
1134 | ch->mq = GNUNET_CADET_get_mq(ch->channel); | 1137 | ch->mq = GNUNET_CADET_get_mq (ch->channel); |
1135 | e = GNUNET_MQ_msg(ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); | 1138 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); |
1136 | GNUNET_CRYPTO_ecdsa_key_get_public(&msg->caller_id, &ring->caller_id); | 1139 | GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id); |
1137 | ring->expiration_time = rs.expiration_time; | 1140 | ring->expiration_time = rs.expiration_time; |
1138 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign(&msg->caller_id, | 1141 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, |
1139 | &rs.purpose, | 1142 | &rs.purpose, |
1140 | &ring->signature)); | 1143 | &ring->signature)); |
1141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); | 1144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); |
1142 | GNUNET_MQ_send(ch->mq, e); | 1145 | GNUNET_MQ_send (ch->mq, e); |
1143 | GNUNET_SERVICE_client_continue(line->client); | 1146 | GNUNET_SERVICE_client_continue (line->client); |
1144 | } | 1147 | } |
1145 | 1148 | ||
1146 | 1149 | ||
@@ -1154,24 +1157,24 @@ handle_client_call_message(void *cls, const struct ClientCallMessage *msg) | |||
1154 | * @return initial channel context for the channel | 1157 | * @return initial channel context for the channel |
1155 | */ | 1158 | */ |
1156 | static void * | 1159 | static void * |
1157 | inbound_channel(void *cls, | 1160 | inbound_channel (void *cls, |
1158 | struct GNUNET_CADET_Channel *channel, | 1161 | struct GNUNET_CADET_Channel *channel, |
1159 | const struct GNUNET_PeerIdentity *initiator) | 1162 | const struct GNUNET_PeerIdentity *initiator) |
1160 | { | 1163 | { |
1161 | struct Line *line = cls; | 1164 | struct Line *line = cls; |
1162 | struct Channel *ch; | 1165 | struct Channel *ch; |
1163 | 1166 | ||
1164 | (void)initiator; | 1167 | (void) initiator; |
1165 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1166 | "Received incoming cadet channel on line %p\n", | 1169 | "Received incoming cadet channel on line %p\n", |
1167 | line); | 1170 | line); |
1168 | ch = GNUNET_new(struct Channel); | 1171 | ch = GNUNET_new (struct Channel); |
1169 | ch->status = CS_CALLEE_INIT; | 1172 | ch->status = CS_CALLEE_INIT; |
1170 | ch->line = line; | 1173 | ch->line = line; |
1171 | ch->channel = channel; | 1174 | ch->channel = channel; |
1172 | ch->mq = GNUNET_CADET_get_mq(ch->channel); | 1175 | ch->mq = GNUNET_CADET_get_mq (ch->channel); |
1173 | ch->cid = line->cid_gen++; | 1176 | ch->cid = line->cid_gen++; |
1174 | GNUNET_CONTAINER_DLL_insert(line->channel_head, line->channel_tail, ch); | 1177 | GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); |
1175 | return ch; | 1178 | return ch; |
1176 | } | 1179 | } |
1177 | 1180 | ||
@@ -1185,14 +1188,14 @@ inbound_channel(void *cls, | |||
1185 | * @return the `struct Line` for the client | 1188 | * @return the `struct Line` for the client |
1186 | */ | 1189 | */ |
1187 | static void * | 1190 | static void * |
1188 | client_connect_cb(void *cls, | 1191 | client_connect_cb (void *cls, |
1189 | struct GNUNET_SERVICE_Client *client, | 1192 | struct GNUNET_SERVICE_Client *client, |
1190 | struct GNUNET_MQ_Handle *mq) | 1193 | struct GNUNET_MQ_Handle *mq) |
1191 | { | 1194 | { |
1192 | struct Line *line; | 1195 | struct Line *line; |
1193 | 1196 | ||
1194 | (void)cls; | 1197 | (void) cls; |
1195 | line = GNUNET_new(struct Line); | 1198 | line = GNUNET_new (struct Line); |
1196 | line->client = client; | 1199 | line->client = client; |
1197 | line->mq = mq; | 1200 | line->mq = mq; |
1198 | return line; | 1201 | return line; |
@@ -1207,28 +1210,28 @@ client_connect_cb(void *cls, | |||
1207 | * @param app_ctx our `struct Line *` for @a client | 1210 | * @param app_ctx our `struct Line *` for @a client |
1208 | */ | 1211 | */ |
1209 | static void | 1212 | static void |
1210 | client_disconnect_cb(void *cls, | 1213 | client_disconnect_cb (void *cls, |
1211 | struct GNUNET_SERVICE_Client *client, | 1214 | struct GNUNET_SERVICE_Client *client, |
1212 | void *app_ctx) | 1215 | void *app_ctx) |
1213 | { | 1216 | { |
1214 | struct Line *line = app_ctx; | 1217 | struct Line *line = app_ctx; |
1215 | struct Channel *chn; | 1218 | struct Channel *chn; |
1216 | 1219 | ||
1217 | (void)cls; | 1220 | (void) cls; |
1218 | (void)client; | 1221 | (void) client; |
1219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); | 1222 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); |
1220 | if (NULL != line->port) | 1223 | if (NULL != line->port) |
1221 | { | 1224 | { |
1222 | GNUNET_CADET_close_port(line->port); | 1225 | GNUNET_CADET_close_port (line->port); |
1223 | line->port = NULL; | 1226 | line->port = NULL; |
1224 | } | 1227 | } |
1225 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) | 1228 | for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn) |
1226 | { | 1229 | { |
1227 | chn = ch->next; | 1230 | chn = ch->next; |
1228 | ch->line = NULL; | 1231 | ch->line = NULL; |
1229 | destroy_line_cadet_channels(ch); | 1232 | destroy_line_cadet_channels (ch); |
1230 | } | 1233 | } |
1231 | GNUNET_free(line); | 1234 | GNUNET_free (line); |
1232 | } | 1235 | } |
1233 | 1236 | ||
1234 | 1237 | ||
@@ -1239,54 +1242,54 @@ client_disconnect_cb(void *cls, | |||
1239 | * @param msg the message from the client | 1242 | * @param msg the message from the client |
1240 | */ | 1243 | */ |
1241 | static void | 1244 | static void |
1242 | handle_client_register_message(void *cls, | 1245 | handle_client_register_message (void *cls, |
1243 | const struct ClientPhoneRegisterMessage *msg) | 1246 | const struct ClientPhoneRegisterMessage *msg) |
1244 | { | 1247 | { |
1245 | struct Line *line = cls; | 1248 | struct Line *line = cls; |
1246 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1249 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1247 | { GNUNET_MQ_hd_fixed_size(cadet_ring_message, | 1250 | { GNUNET_MQ_hd_fixed_size (cadet_ring_message, |
1248 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, | 1251 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, |
1249 | struct CadetPhoneRingMessage, | 1252 | struct CadetPhoneRingMessage, |
1250 | NULL), | 1253 | NULL), |
1251 | GNUNET_MQ_hd_fixed_size(cadet_hangup_message, | 1254 | GNUNET_MQ_hd_fixed_size (cadet_hangup_message, |
1252 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, | 1255 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, |
1253 | struct CadetPhoneHangupMessage, | 1256 | struct CadetPhoneHangupMessage, |
1254 | NULL), | 1257 | NULL), |
1255 | GNUNET_MQ_hd_fixed_size(cadet_pickup_message, | 1258 | GNUNET_MQ_hd_fixed_size (cadet_pickup_message, |
1256 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, | 1259 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, |
1257 | struct CadetPhonePickupMessage, | 1260 | struct CadetPhonePickupMessage, |
1258 | NULL), | 1261 | NULL), |
1259 | GNUNET_MQ_hd_fixed_size(cadet_suspend_message, | 1262 | GNUNET_MQ_hd_fixed_size (cadet_suspend_message, |
1260 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, | 1263 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, |
1261 | struct CadetPhoneSuspendMessage, | 1264 | struct CadetPhoneSuspendMessage, |
1262 | NULL), | 1265 | NULL), |
1263 | GNUNET_MQ_hd_fixed_size(cadet_resume_message, | 1266 | GNUNET_MQ_hd_fixed_size (cadet_resume_message, |
1264 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, | 1267 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, |
1265 | struct CadetPhoneResumeMessage, | 1268 | struct CadetPhoneResumeMessage, |
1266 | NULL), | 1269 | NULL), |
1267 | GNUNET_MQ_hd_var_size(cadet_audio_message, | 1270 | GNUNET_MQ_hd_var_size (cadet_audio_message, |
1268 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, | 1271 | GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, |
1269 | struct CadetAudioMessage, | 1272 | struct CadetAudioMessage, |
1270 | NULL), | 1273 | NULL), |
1271 | GNUNET_MQ_handler_end() }; | 1274 | GNUNET_MQ_handler_end () }; |
1272 | 1275 | ||
1273 | line->line_port = msg->line_port; | 1276 | line->line_port = msg->line_port; |
1274 | line->port = GNUNET_CADET_open_port(cadet, | 1277 | line->port = GNUNET_CADET_open_port (cadet, |
1275 | &msg->line_port, | 1278 | &msg->line_port, |
1276 | &inbound_channel, | 1279 | &inbound_channel, |
1277 | line, | 1280 | line, |
1278 | NULL, | 1281 | NULL, |
1279 | &inbound_end, | 1282 | &inbound_end, |
1280 | cadet_handlers); | 1283 | cadet_handlers); |
1281 | if (NULL == line->port) | 1284 | if (NULL == line->port) |
1282 | { | 1285 | { |
1283 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1284 | _("Could not open line, port %s already in use!\n"), | 1287 | _ ("Could not open line, port %s already in use!\n"), |
1285 | GNUNET_h2s(&msg->line_port)); | 1288 | GNUNET_h2s (&msg->line_port)); |
1286 | GNUNET_SERVICE_client_drop(line->client); | 1289 | GNUNET_SERVICE_client_drop (line->client); |
1287 | return; | 1290 | return; |
1288 | } | 1291 | } |
1289 | GNUNET_SERVICE_client_continue(line->client); | 1292 | GNUNET_SERVICE_client_continue (line->client); |
1290 | } | 1293 | } |
1291 | 1294 | ||
1292 | 1295 | ||
@@ -1296,14 +1299,14 @@ handle_client_register_message(void *cls, | |||
1296 | * @param cls closure, NULL | 1299 | * @param cls closure, NULL |
1297 | */ | 1300 | */ |
1298 | static void | 1301 | static void |
1299 | do_shutdown(void *cls) | 1302 | do_shutdown (void *cls) |
1300 | { | 1303 | { |
1301 | (void)cls; | 1304 | (void) cls; |
1302 | if (NULL != cadet) | 1305 | if (NULL != cadet) |
1303 | { | 1306 | { |
1304 | GNUNET_CADET_disconnect(cadet); | 1307 | GNUNET_CADET_disconnect (cadet); |
1305 | cadet = NULL; | 1308 | cadet = NULL; |
1306 | } | 1309 | } |
1307 | } | 1310 | } |
1308 | 1311 | ||
1309 | 1312 | ||
@@ -1315,65 +1318,65 @@ do_shutdown(void *cls) | |||
1315 | * @param service service handle | 1318 | * @param service service handle |
1316 | */ | 1319 | */ |
1317 | static void | 1320 | static void |
1318 | run(void *cls, | 1321 | run (void *cls, |
1319 | const struct GNUNET_CONFIGURATION_Handle *c, | 1322 | const struct GNUNET_CONFIGURATION_Handle *c, |
1320 | struct GNUNET_SERVICE_Handle *service) | 1323 | struct GNUNET_SERVICE_Handle *service) |
1321 | { | 1324 | { |
1322 | (void)cls; | 1325 | (void) cls; |
1323 | (void)service; | 1326 | (void) service; |
1324 | cfg = c; | 1327 | cfg = c; |
1325 | GNUNET_assert(GNUNET_OK == | 1328 | GNUNET_assert (GNUNET_OK == |
1326 | GNUNET_CRYPTO_get_peer_identity(cfg, &my_identity)); | 1329 | GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity)); |
1327 | cadet = GNUNET_CADET_connect(cfg); | 1330 | cadet = GNUNET_CADET_connect (cfg); |
1328 | if (NULL == cadet) | 1331 | if (NULL == cadet) |
1329 | { | 1332 | { |
1330 | GNUNET_break(0); | 1333 | GNUNET_break (0); |
1331 | GNUNET_SCHEDULER_shutdown(); | 1334 | GNUNET_SCHEDULER_shutdown (); |
1332 | return; | 1335 | return; |
1333 | } | 1336 | } |
1334 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 1337 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
1335 | } | 1338 | } |
1336 | 1339 | ||
1337 | 1340 | ||
1338 | /** | 1341 | /** |
1339 | * Define "main" method using service macro. | 1342 | * Define "main" method using service macro. |
1340 | */ | 1343 | */ |
1341 | GNUNET_SERVICE_MAIN( | 1344 | GNUNET_SERVICE_MAIN ( |
1342 | "conversation", | 1345 | "conversation", |
1343 | GNUNET_SERVICE_OPTION_NONE, | 1346 | GNUNET_SERVICE_OPTION_NONE, |
1344 | &run, | 1347 | &run, |
1345 | &client_connect_cb, | 1348 | &client_connect_cb, |
1346 | &client_disconnect_cb, | 1349 | &client_disconnect_cb, |
1347 | NULL, | 1350 | NULL, |
1348 | GNUNET_MQ_hd_fixed_size(client_register_message, | 1351 | GNUNET_MQ_hd_fixed_size (client_register_message, |
1349 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, | 1352 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, |
1350 | struct ClientPhoneRegisterMessage, | 1353 | struct ClientPhoneRegisterMessage, |
1351 | NULL), | 1354 | NULL), |
1352 | GNUNET_MQ_hd_fixed_size(client_pickup_message, | 1355 | GNUNET_MQ_hd_fixed_size (client_pickup_message, |
1353 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, | 1356 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, |
1354 | struct ClientPhonePickupMessage, | 1357 | struct ClientPhonePickupMessage, |
1355 | NULL), | 1358 | NULL), |
1356 | GNUNET_MQ_hd_fixed_size(client_suspend_message, | 1359 | GNUNET_MQ_hd_fixed_size (client_suspend_message, |
1357 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 1360 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
1358 | struct ClientPhoneSuspendMessage, | 1361 | struct ClientPhoneSuspendMessage, |
1359 | NULL), | 1362 | NULL), |
1360 | GNUNET_MQ_hd_fixed_size(client_resume_message, | 1363 | GNUNET_MQ_hd_fixed_size (client_resume_message, |
1361 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 1364 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
1362 | struct ClientPhoneResumeMessage, | 1365 | struct ClientPhoneResumeMessage, |
1363 | NULL), | 1366 | NULL), |
1364 | GNUNET_MQ_hd_fixed_size(client_hangup_message, | 1367 | GNUNET_MQ_hd_fixed_size (client_hangup_message, |
1365 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 1368 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
1366 | struct ClientPhoneHangupMessage, | 1369 | struct ClientPhoneHangupMessage, |
1367 | NULL), | 1370 | NULL), |
1368 | GNUNET_MQ_hd_fixed_size(client_call_message, | 1371 | GNUNET_MQ_hd_fixed_size (client_call_message, |
1369 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, | 1372 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, |
1370 | struct ClientCallMessage, | 1373 | struct ClientCallMessage, |
1371 | NULL), | 1374 | NULL), |
1372 | GNUNET_MQ_hd_var_size(client_audio_message, | 1375 | GNUNET_MQ_hd_var_size (client_audio_message, |
1373 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 1376 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
1374 | struct ClientAudioMessage, | 1377 | struct ClientAudioMessage, |
1375 | NULL), | 1378 | NULL), |
1376 | GNUNET_MQ_handler_end()); | 1379 | GNUNET_MQ_handler_end ()); |
1377 | 1380 | ||
1378 | 1381 | ||
1379 | /* end of gnunet-service-conversation.c */ | 1382 | /* end of gnunet-service-conversation.c */ |
diff --git a/src/conversation/gnunet_gst.c b/src/conversation/gnunet_gst.c index 5db0d350c..7703215bb 100644 --- a/src/conversation/gnunet_gst.c +++ b/src/conversation/gnunet_gst.c | |||
@@ -31,33 +31,33 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
31 | 31 | ||
32 | 32 | ||
33 | void | 33 | void |
34 | dump_buffer(unsigned n, const unsigned char* buf) | 34 | dump_buffer (unsigned n, const unsigned char*buf) |
35 | { | 35 | { |
36 | const unsigned char *p, *end; | 36 | const unsigned char *p, *end; |
37 | unsigned i, j; | 37 | unsigned i, j; |
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 | { | ||
43 | p = buf + i; | ||
44 | for (j = 0; j < 16; j++) | ||
42 | { | 45 | { |
43 | p = buf + i; | 46 | fprintf (stderr, "%02X ", p[j]); |
44 | for (j = 0; j < 16; j++) | 47 | if (p + j >= end) |
45 | { | 48 | goto BREAKOUT; |
46 | fprintf(stderr, "%02X ", p[j]); | 49 | } |
47 | if (p + j >= end) | 50 | fprintf (stderr, " "); |
48 | goto BREAKOUT; | 51 | p = buf + i; |
49 | } | 52 | for (j = 0; j < 16; j++) |
50 | fprintf(stderr, " "); | 53 | { |
51 | p = buf + i; | 54 | fprintf (stderr, "%c", isprint (p[j]) ? p[j] : |
52 | for (j = 0; j < 16; j++) | 55 | '.'); |
53 | { | 56 | if (p + j >= end) |
54 | fprintf(stderr, "%c", isprint(p[j]) ? p[j] : | 57 | goto BREAKOUT; |
55 | '.'); | ||
56 | if (p + j >= end) | ||
57 | goto BREAKOUT; | ||
58 | } | ||
59 | fprintf(stderr, "\n"); | ||
60 | } | 58 | } |
59 | fprintf (stderr, "\n"); | ||
60 | } | ||
61 | BREAKOUT: | 61 | BREAKOUT: |
62 | return; | 62 | return; |
63 | } | 63 | } |
@@ -66,102 +66,108 @@ BREAKOUT: | |||
66 | * load gnunet configuration | 66 | * load gnunet configuration |
67 | */ | 67 | */ |
68 | void | 68 | void |
69 | gg_load_configuration(GNUNET_gstData * d) | 69 | gg_load_configuration (GNUNET_gstData *d) |
70 | { | 70 | { |
71 | char *audiobackend_string; | 71 | char *audiobackend_string; |
72 | 72 | ||
73 | cfg = GNUNET_CONFIGURATION_create(); | 73 | cfg = GNUNET_CONFIGURATION_create (); |
74 | GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); | 74 | GNUNET_CONFIGURATION_load (cfg, "mediahelper.conf"); |
75 | 75 | ||
76 | 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", |
77 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_OUT", &d->jack_pp_out); | 77 | &d->jack_pp_in); |
78 | GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "JACK_PP_OUT", | ||
79 | &d->jack_pp_out); | ||
78 | 80 | ||
79 | GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); | 81 | GNUNET_CONFIGURATION_get_value_string (cfg, "MEDIAHELPER", "AUDIOBACKEND", |
82 | &audiobackend_string); | ||
80 | 83 | ||
81 | // printf("abstring: %s \n", audiobackend_string); | 84 | // printf("abstring: %s \n", audiobackend_string); |
82 | 85 | ||
83 | if (0 == strcasecmp(audiobackend_string, "AUTO")) | 86 | if (0 == strcasecmp (audiobackend_string, "AUTO")) |
84 | { | 87 | { |
85 | d->audiobackend = AUTO; | 88 | d->audiobackend = AUTO; |
86 | } | 89 | } |
87 | else if (0 == strcasecmp(audiobackend_string, "JACK")) | 90 | else if (0 == strcasecmp (audiobackend_string, "JACK")) |
88 | { | 91 | { |
89 | d->audiobackend = JACK; | 92 | d->audiobackend = JACK; |
90 | } | 93 | } |
91 | else if (0 == strcasecmp(audiobackend_string, "ALSA")) | 94 | else if (0 == strcasecmp (audiobackend_string, "ALSA")) |
92 | { | 95 | { |
93 | d->audiobackend = ALSA; | 96 | d->audiobackend = ALSA; |
94 | } | 97 | } |
95 | else if (0 == strcasecmp(audiobackend_string, "FAKE")) | 98 | else if (0 == strcasecmp (audiobackend_string, "FAKE")) |
96 | { | 99 | { |
97 | d->audiobackend = FAKE; | 100 | d->audiobackend = FAKE; |
98 | } | 101 | } |
99 | else if (0 == strcasecmp(audiobackend_string, "TEST")) | 102 | else if (0 == strcasecmp (audiobackend_string, "TEST")) |
100 | { | 103 | { |
101 | d->audiobackend = TEST; | 104 | d->audiobackend = TEST; |
102 | } | 105 | } |
103 | else | 106 | else |
104 | { | 107 | { |
105 | d->audiobackend = AUTO; | 108 | d->audiobackend = AUTO; |
106 | } | 109 | } |
107 | 110 | ||
108 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) | 111 | if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER", |
109 | { | 112 | "REMOVESILENCE") == GNUNET_YES) |
110 | d->dropsilence = TRUE; | 113 | { |
111 | } | 114 | d->dropsilence = TRUE; |
115 | } | ||
112 | else | 116 | else |
113 | { | 117 | { |
114 | d->dropsilence = FALSE; | 118 | d->dropsilence = FALSE; |
115 | } | 119 | } |
116 | 120 | ||
117 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) | 121 | if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER", |
118 | { | 122 | "NO_GN_HEADERS") == GNUNET_YES) |
119 | d->pure_ogg = TRUE; | 123 | { |
120 | } | 124 | d->pure_ogg = TRUE; |
125 | } | ||
121 | else | 126 | else |
122 | { | 127 | { |
123 | d->pure_ogg = FALSE; | 128 | d->pure_ogg = FALSE; |
124 | } | 129 | } |
125 | 130 | ||
126 | 131 | ||
127 | if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) | 132 | if (GNUNET_CONFIGURATION_get_value_yesno (cfg, "MEDIAHELPER", "USERTP") == |
128 | { | 133 | GNUNET_YES) |
129 | d->usertp = TRUE; | 134 | { |
130 | } | 135 | d->usertp = TRUE; |
136 | } | ||
131 | else | 137 | else |
132 | { | 138 | { |
133 | d->usertp = FALSE; | 139 | d->usertp = FALSE; |
134 | } | 140 | } |
135 | 141 | ||
136 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); | 142 | // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); |
137 | } | 143 | } |
138 | 144 | ||
139 | static void | 145 | static void |
140 | write_data(const char *ptr, size_t msg_size) | 146 | write_data (const char *ptr, size_t msg_size) |
141 | { | 147 | { |
142 | ssize_t ret; | 148 | ssize_t ret; |
143 | size_t off; | 149 | size_t off; |
144 | 150 | ||
145 | off = 0; | 151 | off = 0; |
146 | while (off < msg_size) | 152 | while (off < msg_size) |
153 | { | ||
154 | ret = write (1, &ptr[off], msg_size - off); | ||
155 | if (0 >= ret) | ||
147 | { | 156 | { |
148 | ret = write(1, &ptr[off], msg_size - off); | 157 | if (-1 == ret) |
149 | if (0 >= ret) | 158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "write"); |
150 | { | ||
151 | if (-1 == ret) | ||
152 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "write"); | ||
153 | // quit (2); | 159 | // quit (2); |
154 | } | ||
155 | off += ret; | ||
156 | } | 160 | } |
161 | off += ret; | ||
162 | } | ||
157 | } | 163 | } |
158 | 164 | ||
159 | 165 | ||
160 | 166 | ||
161 | extern GstFlowReturn | 167 | extern GstFlowReturn |
162 | on_appsink_new_sample(GstElement * element, GNUNET_gstData * d) | 168 | on_appsink_new_sample (GstElement *element, GNUNET_gstData *d) |
163 | { | 169 | { |
164 | //size of message including gnunet header | 170 | // size of message including gnunet header |
165 | size_t msg_size; | 171 | size_t msg_size; |
166 | 172 | ||
167 | GstSample *s; | 173 | GstSample *s; |
@@ -175,48 +181,48 @@ on_appsink_new_sample(GstElement * element, GNUNET_gstData * d) | |||
175 | char *caps_str; | 181 | char *caps_str; |
176 | */ | 182 | */ |
177 | 183 | ||
178 | if (gst_app_sink_is_eos(GST_APP_SINK(element))) | 184 | if (gst_app_sink_is_eos (GST_APP_SINK (element))) |
179 | return GST_FLOW_OK; | 185 | return GST_FLOW_OK; |
180 | 186 | ||
181 | //pull sample from appsink | 187 | // pull sample from appsink |
182 | s = gst_app_sink_pull_sample(GST_APP_SINK(element)); | 188 | s = gst_app_sink_pull_sample (GST_APP_SINK (element)); |
183 | 189 | ||
184 | if (s == NULL) | 190 | if (s == NULL) |
185 | return GST_FLOW_OK; | 191 | return GST_FLOW_OK; |
186 | 192 | ||
187 | if (!GST_IS_SAMPLE(s)) | 193 | if (! GST_IS_SAMPLE (s)) |
188 | return GST_FLOW_OK; | 194 | return GST_FLOW_OK; |
189 | 195 | ||
190 | b = gst_sample_get_buffer(s); | 196 | b = gst_sample_get_buffer (s); |
191 | 197 | ||
192 | GST_WARNING("caps are %" GST_PTR_FORMAT, gst_sample_get_caps(s)); | 198 | GST_WARNING ("caps are %" GST_PTR_FORMAT, gst_sample_get_caps (s)); |
193 | 199 | ||
194 | 200 | ||
195 | 201 | ||
196 | gst_buffer_map(b, &map, GST_MAP_READ); | 202 | gst_buffer_map (b, &map, GST_MAP_READ); |
197 | 203 | ||
198 | size_t len; | 204 | size_t len; |
199 | len = map.size; | 205 | len = map.size; |
200 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) | 206 | if (len > UINT16_MAX - sizeof(struct AudioMessage)) |
201 | { | 207 | { |
202 | // this should never happen? | 208 | // this should never happen? |
203 | printf("GSTREAMER sample too big! \n"); | 209 | printf ("GSTREAMER sample too big! \n"); |
204 | exit(20); | 210 | exit (20); |
205 | len = UINT16_MAX - sizeof(struct AudioMessage); | 211 | len = UINT16_MAX - sizeof(struct AudioMessage); |
206 | } | 212 | } |
207 | 213 | ||
208 | msg_size = sizeof(struct AudioMessage) + len; | 214 | msg_size = sizeof(struct AudioMessage) + len; |
209 | 215 | ||
210 | // copy the data into audio_message | 216 | // copy the data into audio_message |
211 | GNUNET_memcpy(((char *)&(d->audio_message)[1]), map.data, len); | 217 | GNUNET_memcpy (((char *) &(d->audio_message)[1]), map.data, len); |
212 | (d->audio_message)->header.size = htons((uint16_t)msg_size); | 218 | (d->audio_message)->header.size = htons ((uint16_t) msg_size); |
213 | if (d->pure_ogg) | 219 | if (d->pure_ogg) |
214 | // write the audio_message without the gnunet headers | 220 | // write the audio_message without the gnunet headers |
215 | write_data((const char *)&(d->audio_message)[1], len); | 221 | write_data ((const char *) &(d->audio_message)[1], len); |
216 | else | 222 | else |
217 | write_data((const char *)d->audio_message, msg_size); | 223 | write_data ((const char *) d->audio_message, msg_size); |
218 | 224 | ||
219 | gst_sample_unref(s); | 225 | gst_sample_unref (s); |
220 | return GST_FLOW_OK; | 226 | return GST_FLOW_OK; |
221 | } | 227 | } |
222 | 228 | ||
@@ -224,13 +230,17 @@ on_appsink_new_sample(GstElement * element, GNUNET_gstData * d) | |||
224 | * Dump a pipeline graph | 230 | * Dump a pipeline graph |
225 | */ | 231 | */ |
226 | extern void | 232 | extern void |
227 | pl_graph(GstElement * pipeline) | 233 | pl_graph (GstElement *pipeline) |
228 | { | 234 | { |
229 | #ifdef IS_SPEAKER | 235 | #ifdef IS_SPEAKER |
230 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "playback_helper.dot"); | 236 | gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline), |
237 | GST_DEBUG_GRAPH_SHOW_ALL, | ||
238 | "playback_helper.dot"); | ||
231 | #endif | 239 | #endif |
232 | #ifdef IS_MIC | 240 | #ifdef IS_MIC |
233 | gst_debug_bin_to_dot_file_with_ts(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "record_helper.dot"); | 241 | gst_debug_bin_to_dot_file_with_ts (GST_BIN (pipeline), |
242 | GST_DEBUG_GRAPH_SHOW_ALL, | ||
243 | "record_helper.dot"); | ||
234 | #endif | 244 | #endif |
235 | 245 | ||
236 | 246 | ||
@@ -240,121 +250,121 @@ pl_graph(GstElement * pipeline) | |||
240 | 250 | ||
241 | 251 | ||
242 | extern gboolean | 252 | extern gboolean |
243 | gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data) | 253 | gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data) |
244 | { | 254 | { |
245 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
246 | "Bus message\n"); | 256 | "Bus message\n"); |
247 | switch (GST_MESSAGE_TYPE(msg)) | 257 | switch (GST_MESSAGE_TYPE (msg)) |
248 | { | 258 | { |
249 | case GST_MESSAGE_EOS: | 259 | case GST_MESSAGE_EOS: |
250 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
251 | "End of stream\n"); | 261 | "End of stream\n"); |
252 | exit(10); | 262 | exit (10); |
253 | break; | 263 | break; |
254 | 264 | ||
255 | case GST_MESSAGE_ERROR: | 265 | case GST_MESSAGE_ERROR: |
256 | { | 266 | { |
257 | gchar *debug; | 267 | gchar *debug; |
258 | GError *error; | 268 | GError *error; |
259 | 269 | ||
260 | gst_message_parse_error(msg, &error, &debug); | 270 | gst_message_parse_error (msg, &error, &debug); |
261 | g_free(debug); | 271 | g_free (debug); |
262 | 272 | ||
263 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 273 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
264 | "Error: %s\n", | 274 | "Error: %s\n", |
265 | error->message); | 275 | error->message); |
266 | g_error_free(error); | 276 | g_error_free (error); |
267 | 277 | ||
268 | exit(10); | 278 | exit (10); |
269 | break; | 279 | break; |
270 | } | 280 | } |
271 | 281 | ||
272 | default: | 282 | default: |
273 | break; | 283 | break; |
274 | } | 284 | } |
275 | 285 | ||
276 | return TRUE; | 286 | return TRUE; |
277 | } | 287 | } |
278 | 288 | ||
279 | /* called when pipeline changes state */ | 289 | /* called when pipeline changes state */ |
280 | extern void | 290 | extern void |
281 | state_changed_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * d) | 291 | state_changed_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *d) |
282 | { | 292 | { |
283 | GstState old_state, new_state, pending_state; | 293 | GstState old_state, new_state, pending_state; |
284 | 294 | ||
285 | gst_message_parse_state_changed(msg, &old_state, &new_state, | 295 | gst_message_parse_state_changed (msg, &old_state, &new_state, |
286 | &pending_state); | 296 | &pending_state); |
287 | switch (new_state) | 297 | switch (new_state) |
288 | { | 298 | { |
289 | case GST_STATE_READY: | 299 | case GST_STATE_READY: |
290 | // printf("ready.... \n"); | 300 | // printf("ready.... \n"); |
291 | //pl_graph(GST_ELEMENT(d->pipeline)); | 301 | // pl_graph(GST_ELEMENT(d->pipeline)); |
292 | break; | 302 | break; |
293 | 303 | ||
294 | case GST_STATE_PLAYING: | 304 | case GST_STATE_PLAYING: |
295 | 305 | ||
296 | //GST_LOG ("caps are %" GST_PTR_FORMAT, caps); | 306 | // GST_LOG ("caps are %" GST_PTR_FORMAT, caps); |
297 | 307 | ||
298 | // printf("Playing.... \n"); | 308 | // printf("Playing.... \n"); |
299 | pl_graph(GST_ELEMENT(d->pipeline)); | 309 | pl_graph (GST_ELEMENT (d->pipeline)); |
300 | break; | 310 | break; |
301 | 311 | ||
302 | case GST_STATE_VOID_PENDING: | 312 | case GST_STATE_VOID_PENDING: |
303 | // printf("void_pending.... \n"); | 313 | // printf("void_pending.... \n"); |
304 | //pl_graph(GST_ELEMENT(d->pipeline)); | 314 | // pl_graph(GST_ELEMENT(d->pipeline)); |
305 | break; | 315 | break; |
306 | 316 | ||
307 | case GST_STATE_NULL: | 317 | case GST_STATE_NULL: |
308 | // printf("null.... \n"); | 318 | // printf("null.... \n"); |
309 | //pl_graph(GST_ELEMENT(d->pipeline)); | 319 | // pl_graph(GST_ELEMENT(d->pipeline)); |
310 | break; | 320 | break; |
311 | 321 | ||
312 | case GST_STATE_PAUSED: | 322 | case GST_STATE_PAUSED: |
313 | // printf("paused.... \n"); | 323 | // printf("paused.... \n"); |
314 | //pl_graph(GST_ELEMENT(d->pipeline)); | 324 | // pl_graph(GST_ELEMENT(d->pipeline)); |
315 | break; | 325 | break; |
316 | } | 326 | } |
317 | } | 327 | } |
318 | 328 | ||
319 | static void | 329 | static void |
320 | application_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 330 | application_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data) |
321 | { | 331 | { |
322 | // printf("application cb"); | 332 | // printf("application cb"); |
323 | return; | 333 | return; |
324 | } | 334 | } |
325 | 335 | ||
326 | static void | 336 | static void |
327 | error_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 337 | error_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data) |
328 | { | 338 | { |
329 | // printf("error cb"); | 339 | // printf("error cb"); |
330 | return; | 340 | return; |
331 | } | 341 | } |
332 | 342 | ||
333 | static void | 343 | static void |
334 | eos_cb(GstBus * bus, GstMessage * msg, GNUNET_gstData * data) | 344 | eos_cb (GstBus *bus, GstMessage *msg, GNUNET_gstData *data) |
335 | { | 345 | { |
336 | // printf("eos cb"); | 346 | // printf("eos cb"); |
337 | return; | 347 | return; |
338 | } | 348 | } |
339 | 349 | ||
340 | extern void | 350 | extern void |
341 | gg_setup_gst_bus(GNUNET_gstData * d) | 351 | gg_setup_gst_bus (GNUNET_gstData *d) |
342 | { | 352 | { |
343 | GstBus *bus; | 353 | GstBus *bus; |
344 | 354 | ||
345 | bus = gst_element_get_bus(GST_ELEMENT(d->pipeline)); | 355 | bus = gst_element_get_bus (GST_ELEMENT (d->pipeline)); |
346 | gst_bus_add_signal_watch(bus); | 356 | gst_bus_add_signal_watch (bus); |
347 | g_signal_connect(G_OBJECT(bus), "message::error", (GCallback)error_cb, | 357 | g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb, |
348 | d); | 358 | d); |
349 | g_signal_connect(G_OBJECT(bus), "message::eos", (GCallback)eos_cb, | 359 | g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, |
350 | d); | 360 | d); |
351 | g_signal_connect(G_OBJECT(bus), "message::state-changed", | 361 | g_signal_connect (G_OBJECT (bus), "message::state-changed", |
352 | (GCallback)state_changed_cb, d); | 362 | (GCallback) state_changed_cb, d); |
353 | g_signal_connect(G_OBJECT(bus), "message::application", | 363 | g_signal_connect (G_OBJECT (bus), "message::application", |
354 | (GCallback)application_cb, d); | 364 | (GCallback) application_cb, d); |
355 | g_signal_connect(G_OBJECT(bus), "message::about-to-finish", | 365 | g_signal_connect (G_OBJECT (bus), "message::about-to-finish", |
356 | (GCallback)application_cb, d); | 366 | (GCallback) application_cb, d); |
357 | gst_object_unref(bus); | 367 | gst_object_unref (bus); |
358 | } | 368 | } |
359 | 369 | ||
360 | /* | 370 | /* |
@@ -478,57 +488,57 @@ gg_setup_gst_bus(GNUNET_gstData * d) | |||
478 | 488 | ||
479 | 489 | ||
480 | extern int | 490 | extern int |
481 | feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData * d) | 491 | feed_buffer_to_gst (const char *audio, size_t b_len, GNUNET_gstData *d) |
482 | { | 492 | { |
483 | GstBuffer *b; | 493 | GstBuffer *b; |
484 | gchar *bufspace; | 494 | gchar *bufspace; |
485 | GstFlowReturn flow; | 495 | GstFlowReturn flow; |
486 | 496 | ||
487 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
488 | "Feeding %u bytes to GStreamer\n", | 498 | "Feeding %u bytes to GStreamer\n", |
489 | (unsigned int)b_len); | 499 | (unsigned int) b_len); |
490 | 500 | ||
491 | bufspace = g_memdup(audio, b_len); | 501 | bufspace = g_memdup (audio, b_len); |
492 | b = gst_buffer_new_wrapped(bufspace, b_len); | 502 | b = gst_buffer_new_wrapped (bufspace, b_len); |
493 | if (NULL == b) | 503 | if (NULL == b) |
494 | { | 504 | { |
495 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
496 | "Failed to wrap a buffer\n"); | 506 | "Failed to wrap a buffer\n"); |
497 | g_free(bufspace); | 507 | g_free (bufspace); |
498 | return GNUNET_SYSERR; | 508 | return GNUNET_SYSERR; |
499 | } | 509 | } |
500 | if (GST_APP_SRC(d->appsrc) == NULL) | 510 | if (GST_APP_SRC (d->appsrc) == NULL) |
501 | exit(10); | 511 | exit (10); |
502 | flow = gst_app_src_push_buffer(GST_APP_SRC(d->appsrc), b); | 512 | flow = gst_app_src_push_buffer (GST_APP_SRC (d->appsrc), b); |
503 | /* They all return GNUNET_OK, because currently player stops when | 513 | /* They all return GNUNET_OK, because currently player stops when |
504 | * data stops coming. This might need to be changed for the player | 514 | * data stops coming. This might need to be changed for the player |
505 | * to also stop when pipeline breaks. | 515 | * to also stop when pipeline breaks. |
506 | */ | 516 | */ |
507 | switch (flow) | 517 | switch (flow) |
508 | { | 518 | { |
509 | case GST_FLOW_OK: | 519 | case GST_FLOW_OK: |
510 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
511 | "Fed %u bytes to the pipeline\n", | 521 | "Fed %u bytes to the pipeline\n", |
512 | (unsigned int)b_len); | 522 | (unsigned int) b_len); |
513 | break; | 523 | break; |
514 | 524 | ||
515 | case GST_FLOW_FLUSHING: | 525 | case GST_FLOW_FLUSHING: |
516 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ | 526 | /* buffer was dropped, because pipeline state is not PAUSED or PLAYING */ |
517 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 527 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
518 | "Dropped a buffer\n"); | 528 | "Dropped a buffer\n"); |
519 | break; | 529 | break; |
520 | 530 | ||
521 | case GST_FLOW_EOS: | 531 | case GST_FLOW_EOS: |
522 | /* end of stream */ | 532 | /* end of stream */ |
523 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
524 | "EOS\n"); | 534 | "EOS\n"); |
525 | break; | 535 | break; |
526 | 536 | ||
527 | default: | 537 | default: |
528 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 538 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
529 | "Unexpected push result\n"); | 539 | "Unexpected push result\n"); |
530 | break; | 540 | break; |
531 | } | 541 | } |
532 | return GNUNET_OK; | 542 | return GNUNET_OK; |
533 | } | 543 | } |
534 | 544 | ||
@@ -538,22 +548,23 @@ feed_buffer_to_gst(const char *audio, size_t b_len, GNUNET_gstData * d) | |||
538 | * debug making elements | 548 | * debug making elements |
539 | */ | 549 | */ |
540 | extern GstElement * | 550 | extern GstElement * |
541 | gst_element_factory_make_debug(gchar *factoryname, gchar *name) | 551 | gst_element_factory_make_debug (gchar *factoryname, gchar *name) |
542 | { | 552 | { |
543 | GstElement *element; | 553 | GstElement *element; |
544 | 554 | ||
545 | element = gst_element_factory_make(factoryname, name); | 555 | element = gst_element_factory_make (factoryname, name); |
546 | 556 | ||
547 | if (element == NULL) | 557 | if (element == NULL) |
548 | { | 558 | { |
549 | printf("\n Failed to create element - type: %s name: %s \n", factoryname, name); | 559 | printf ("\n Failed to create element - type: %s name: %s \n", factoryname, |
550 | exit(10); | 560 | name); |
551 | return element; | 561 | exit (10); |
552 | } | 562 | return element; |
563 | } | ||
553 | else | 564 | else |
554 | { | 565 | { |
555 | return element; | 566 | return element; |
556 | } | 567 | } |
557 | } | 568 | } |
558 | 569 | ||
559 | /* | 570 | /* |
@@ -568,104 +579,106 @@ gst_element_factory_make_debug(gchar *factoryname, gchar *name) | |||
568 | gst_element_link_many_debug(__VA_ARGS__) | 579 | gst_element_link_many_debug(__VA_ARGS__) |
569 | */ | 580 | */ |
570 | extern void | 581 | extern void |
571 | lf(char * msg) | 582 | lf (char *msg) |
572 | { | 583 | { |
573 | printf("linking elements failed: %s", msg); | 584 | printf ("linking elements failed: %s", msg); |
574 | exit(10); | 585 | exit (10); |
575 | } | 586 | } |
576 | 587 | ||
577 | /*** | 588 | /*** |
578 | * used to set properties on autoaudiosink's chosen sink | 589 | * used to set properties on autoaudiosink's chosen sink |
579 | */ | 590 | */ |
580 | static void | 591 | static void |
581 | autoaudiosink_child_added(GstChildProxy *child_proxy, | 592 | autoaudiosink_child_added (GstChildProxy *child_proxy, |
582 | GObject *object, | 593 | GObject *object, |
583 | gchar *name, | 594 | gchar *name, |
584 | gpointer user_data) | 595 | gpointer user_data) |
585 | { | 596 | { |
586 | if (GST_IS_AUDIO_BASE_SRC(object)) | 597 | if (GST_IS_AUDIO_BASE_SRC (object)) |
587 | g_object_set(object, | 598 | g_object_set (object, |
588 | "buffer-time", (gint64)BUFFER_TIME, | 599 | "buffer-time", (gint64) BUFFER_TIME, |
589 | "latency-time", (gint64)LATENCY_TIME, | 600 | "latency-time", (gint64) LATENCY_TIME, |
590 | NULL); | 601 | NULL); |
591 | } | 602 | } |
592 | 603 | ||
593 | /*** | 604 | /*** |
594 | * used to set properties on autoaudiosource's chosen sink | 605 | * used to set properties on autoaudiosource's chosen sink |
595 | */ | 606 | */ |
596 | static void | 607 | static void |
597 | autoaudiosource_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data) | 608 | autoaudiosource_child_added (GstChildProxy *child_proxy, GObject *object, |
609 | gchar *name, gpointer user_data) | ||
598 | { | 610 | { |
599 | if (GST_IS_AUDIO_BASE_SRC(object)) | 611 | if (GST_IS_AUDIO_BASE_SRC (object)) |
600 | g_object_set(object, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); | 612 | g_object_set (object, "buffer-time", (gint64) BUFFER_TIME, "latency-time", |
613 | (gint64) LATENCY_TIME, NULL); | ||
601 | } | 614 | } |
602 | 615 | ||
603 | 616 | ||
604 | GstElement * | 617 | GstElement * |
605 | get_pipeline(GstElement *element) | 618 | get_pipeline (GstElement *element) |
606 | { | 619 | { |
607 | GstPipeline *p; | 620 | GstPipeline *p; |
608 | 621 | ||
609 | p = GST_PIPELINE(gst_object_get_parent(GST_OBJECT(element))); | 622 | p = GST_PIPELINE (gst_object_get_parent (GST_OBJECT (element))); |
610 | 623 | ||
611 | return GST_ELEMENT(p); | 624 | return GST_ELEMENT (p); |
612 | } | 625 | } |
613 | 626 | ||
614 | static void | 627 | static void |
615 | decoder_ogg_pad_added(GstElement *element, | 628 | decoder_ogg_pad_added (GstElement *element, |
616 | GstPad *pad, | 629 | GstPad *pad, |
617 | gpointer data) | 630 | gpointer data) |
618 | { | 631 | { |
619 | GstPad *sinkpad; | 632 | GstPad *sinkpad; |
620 | GstElement *decoder = (GstElement *)data; | 633 | GstElement *decoder = (GstElement *) data; |
621 | 634 | ||
622 | printf("==== ogg pad added callback \n"); | 635 | printf ("==== ogg pad added callback \n"); |
623 | /* We can now link this pad with the opus-decoder sink pad */ | 636 | /* We can now link this pad with the opus-decoder sink pad */ |
624 | // pl_graph(get_pipeline(element)); | 637 | // pl_graph(get_pipeline(element)); |
625 | sinkpad = gst_element_get_static_pad(decoder, "sink"); | 638 | sinkpad = gst_element_get_static_pad (decoder, "sink"); |
626 | 639 | ||
627 | gst_pad_link(pad, sinkpad); | 640 | gst_pad_link (pad, sinkpad); |
628 | gst_element_link_many(element, decoder, NULL); | 641 | gst_element_link_many (element, decoder, NULL); |
629 | gst_object_unref(sinkpad); | 642 | gst_object_unref (sinkpad); |
630 | } | 643 | } |
631 | 644 | ||
632 | 645 | ||
633 | int | 646 | int |
634 | gnunet_read(GNUNET_gstData * d) | 647 | gnunet_read (GNUNET_gstData *d) |
635 | { | 648 | { |
636 | char readbuf[MAXLINE]; | 649 | char readbuf[MAXLINE]; |
637 | int ret; | 650 | int ret; |
638 | 651 | ||
639 | printf("read \n"); | 652 | printf ("read \n"); |
640 | ret = read(0, readbuf, sizeof(readbuf)); | 653 | ret = read (0, readbuf, sizeof(readbuf)); |
641 | if (0 > ret) | 654 | if (0 > ret) |
642 | { | 655 | { |
643 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
644 | _("Read error from STDIN: %d %s\n"), | 657 | _ ("Read error from STDIN: %d %s\n"), |
645 | ret, strerror(errno)); | 658 | ret, strerror (errno)); |
646 | return FAIL; | 659 | return FAIL; |
647 | } | 660 | } |
648 | //toff += ret; | 661 | // toff += ret; |
649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
650 | "Received %d bytes of audio data\n", | 663 | "Received %d bytes of audio data\n", |
651 | (int)ret); | 664 | (int) ret); |
652 | if (0 == ret) | 665 | if (0 == ret) |
653 | return FAIL; | 666 | return FAIL; |
654 | //#ifdef DEBUG_READ_PURE_OGG | 667 | // #ifdef DEBUG_READ_PURE_OGG |
655 | 668 | ||
656 | if (d->pure_ogg) | 669 | if (d->pure_ogg) |
657 | { | 670 | { |
658 | feed_buffer_to_gst(readbuf, ret, d); | 671 | feed_buffer_to_gst (readbuf, ret, d); |
659 | } | 672 | } |
660 | else | 673 | else |
661 | { | 674 | { |
662 | //#endif | 675 | // #endif |
663 | GNUNET_MST_from_buffer(d->stdin_mst, | 676 | GNUNET_MST_from_buffer (d->stdin_mst, |
664 | readbuf, | 677 | readbuf, |
665 | ret, | 678 | ret, |
666 | GNUNET_NO, | 679 | GNUNET_NO, |
667 | GNUNET_NO); | 680 | GNUNET_NO); |
668 | } | 681 | } |
669 | return 0; | 682 | return 0; |
670 | } | 683 | } |
671 | 684 | ||
@@ -678,127 +691,130 @@ gnunet_read(GNUNET_gstData * d) | |||
678 | * #GNUNET_SYSERR to stop further processing due to error | 691 | * #GNUNET_SYSERR to stop further processing due to error |
679 | */ | 692 | */ |
680 | static int | 693 | static int |
681 | stdin_receiver(void *cls, | 694 | stdin_receiver (void *cls, |
682 | const struct GNUNET_MessageHeader *msg) | 695 | const struct GNUNET_MessageHeader *msg) |
683 | { | 696 | { |
684 | struct AudioMessage *audio; | 697 | struct AudioMessage *audio; |
685 | size_t b_len; | 698 | size_t b_len; |
686 | 699 | ||
687 | printf("stdin receiver \n "); | 700 | printf ("stdin receiver \n "); |
688 | dump_buffer(sizeof(msg), | 701 | dump_buffer (sizeof(msg), |
689 | (const unsigned char *)msg); | 702 | (const unsigned char *) msg); |
690 | 703 | ||
691 | switch (ntohs(msg->type)) | 704 | switch (ntohs (msg->type)) |
692 | { | 705 | { |
693 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: | 706 | case GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO: |
694 | audio = (struct AudioMessage *)msg; | 707 | audio = (struct AudioMessage *) msg; |
695 | 708 | ||
696 | b_len = ntohs(audio->header.size) - sizeof(struct AudioMessage); | 709 | b_len = ntohs (audio->header.size) - sizeof(struct AudioMessage); |
697 | printf("feeding buffer to gst \n "); | 710 | printf ("feeding buffer to gst \n "); |
698 | feed_buffer_to_gst((const char *)&audio[1], b_len, cls); | 711 | feed_buffer_to_gst ((const char *) &audio[1], b_len, cls); |
699 | break; | 712 | break; |
700 | 713 | ||
701 | default: | 714 | default: |
702 | printf("No audio message: %u \n ", ntohs(msg->type)); | 715 | printf ("No audio message: %u \n ", ntohs (msg->type)); |
703 | break; | 716 | break; |
704 | } | 717 | } |
705 | return GNUNET_OK; | 718 | return GNUNET_OK; |
706 | } | 719 | } |
707 | 720 | ||
708 | 721 | ||
709 | GstBin * | 722 | GstBin * |
710 | get_app(GNUNET_gstData *d, int type) | 723 | get_app (GNUNET_gstData *d, int type) |
711 | { | 724 | { |
712 | GstBin *bin; | 725 | GstBin *bin; |
713 | GstPad *pad, *ghostpad; | 726 | GstPad *pad, *ghostpad; |
714 | 727 | ||
715 | if (type == SOURCE) | 728 | if (type == SOURCE) |
716 | { | 729 | { |
717 | bin = GST_BIN(gst_bin_new("Gnunet appsrc")); | 730 | bin = GST_BIN (gst_bin_new ("Gnunet appsrc")); |
718 | 731 | ||
719 | 732 | ||
720 | GNUNET_assert(GNUNET_OK == | 733 | GNUNET_assert (GNUNET_OK == |
721 | GNUNET_log_setup("gnunet-helper-audio-playback", | 734 | GNUNET_log_setup ("gnunet-helper-audio-playback", |
722 | "WARNING", | 735 | "WARNING", |
723 | NULL)); | 736 | NULL)); |
724 | 737 | ||
725 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
726 | "Audio playback starts\n"); | 739 | "Audio playback starts\n"); |
727 | printf(" creating appsrc \n "); | 740 | printf (" creating appsrc \n "); |
728 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 741 | // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
729 | 742 | ||
730 | // d->audio_message = GNUNET_malloc (UINT16_MAX); | 743 | // d->audio_message = GNUNET_malloc (UINT16_MAX); |
731 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); | 744 | // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); |
732 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); | 745 | // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); |
733 | 746 | ||
734 | 747 | ||
735 | //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 748 | // d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
736 | 749 | ||
737 | 750 | ||
738 | d->stdin_mst = GNUNET_MST_create(&stdin_receiver, d); | 751 | d->stdin_mst = GNUNET_MST_create (&stdin_receiver, d); |
739 | 752 | ||
740 | if (d->stdin_mst == NULL) | 753 | if (d->stdin_mst == NULL) |
741 | printf("stdin_mst = NULL"); | 754 | printf ("stdin_mst = NULL"); |
742 | 755 | ||
743 | d->appsrc = gst_element_factory_make("appsrc", "appsrc"); | 756 | d->appsrc = gst_element_factory_make ("appsrc", "appsrc"); |
744 | 757 | ||
745 | gst_bin_add_many(bin, d->appsrc, NULL); | 758 | gst_bin_add_many (bin, d->appsrc, NULL); |
746 | // gst_element_link_many ( encoder, muxer, NULL); | 759 | // gst_element_link_many ( encoder, muxer, NULL); |
747 | 760 | ||
748 | pad = gst_element_get_static_pad(d->appsrc, "src"); | 761 | pad = gst_element_get_static_pad (d->appsrc, "src"); |
749 | ghostpad = gst_ghost_pad_new("src", pad); | 762 | ghostpad = gst_ghost_pad_new ("src", pad); |
750 | } | 763 | } |
751 | if (type == SINK) | 764 | if (type == SINK) |
752 | { | 765 | { |
753 | bin = GST_BIN(gst_bin_new("Gnunet appsink")); | 766 | bin = GST_BIN (gst_bin_new ("Gnunet appsink")); |
754 | 767 | ||
755 | 768 | ||
756 | GNUNET_assert(GNUNET_OK == | 769 | GNUNET_assert (GNUNET_OK == |
757 | GNUNET_log_setup("gnunet-helper-audio-record", | 770 | GNUNET_log_setup ("gnunet-helper-audio-record", |
758 | "WARNING", | 771 | "WARNING", |
759 | NULL)); | 772 | NULL)); |
760 | 773 | ||
761 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 774 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
762 | "Audio source starts\n"); | 775 | "Audio source starts\n"); |
763 | 776 | ||
764 | d->appsink = gst_element_factory_make("appsink", "appsink"); | 777 | d->appsink = gst_element_factory_make ("appsink", "appsink"); |
765 | 778 | ||
766 | // Move this out of here! | 779 | // Move this out of here! |
767 | d->audio_message = GNUNET_malloc(UINT16_MAX); | 780 | d->audio_message = GNUNET_malloc (UINT16_MAX); |
768 | (d->audio_message)->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 781 | (d->audio_message)->header.type = htons ( |
769 | g_object_set(G_OBJECT(d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); | 782 | GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
783 | g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, | ||
784 | NULL); | ||
770 | 785 | ||
771 | g_signal_connect(d->appsink, "new-sample", | 786 | g_signal_connect (d->appsink, "new-sample", |
772 | G_CALLBACK(on_appsink_new_sample), &d); | 787 | G_CALLBACK (on_appsink_new_sample), &d); |
773 | 788 | ||
774 | gst_bin_add_many(bin, d->appsink, NULL); | 789 | gst_bin_add_many (bin, d->appsink, NULL); |
775 | // gst_element_link_many ( encoder, muxer, NULL); | 790 | // gst_element_link_many ( encoder, muxer, NULL); |
776 | 791 | ||
777 | pad = gst_element_get_static_pad(d->appsink, "sink"); | 792 | pad = gst_element_get_static_pad (d->appsink, "sink"); |
778 | ghostpad = gst_ghost_pad_new("sink", pad); | 793 | ghostpad = gst_ghost_pad_new ("sink", pad); |
779 | } | 794 | } |
780 | 795 | ||
781 | /* set the bin pads */ | 796 | /* set the bin pads */ |
782 | gst_pad_set_active(ghostpad, TRUE); | 797 | gst_pad_set_active (ghostpad, TRUE); |
783 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); | 798 | gst_element_add_pad (GST_ELEMENT (bin), ghostpad); |
784 | 799 | ||
785 | gst_object_unref(pad); | 800 | gst_object_unref (pad); |
786 | 801 | ||
787 | return bin; | 802 | return bin; |
788 | } | 803 | } |
789 | 804 | ||
790 | extern GstBin * | 805 | extern GstBin * |
791 | get_coder(GNUNET_gstData *d, int type) | 806 | get_coder (GNUNET_gstData *d, int type) |
792 | { | 807 | { |
793 | GstBin *bin; | 808 | GstBin *bin; |
794 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; | 809 | GstPad *srcpad, *sinkpad, *srcghostpad, *sinkghostpad; |
795 | GstCaps *rtpcaps; | 810 | GstCaps *rtpcaps; |
796 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, *rtpcapsfilter; | 811 | GstElement *encoder, *muxer, *decoder, *demuxer, *jitterbuffer, |
812 | *rtpcapsfilter; | ||
797 | 813 | ||
798 | if (d->usertp == TRUE) | 814 | if (d->usertp == TRUE) |
799 | { | 815 | { |
800 | /* | 816 | /* |
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 */ | 817 | * 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 */ |
802 | /* | 818 | /* |
803 | rtpcaps = gst_caps_new_simple ("application/x-rtp", | 819 | rtpcaps = gst_caps_new_simple ("application/x-rtp", |
804 | "media", G_TYPE_STRING, "audio", | 820 | "media", G_TYPE_STRING, "audio", |
@@ -809,109 +825,112 @@ get_coder(GNUNET_gstData *d, int type) | |||
809 | "encoding-params", G_TYPE_STRING, "2", | 825 | "encoding-params", G_TYPE_STRING, "2", |
810 | NULL); | 826 | NULL); |
811 | */ | 827 | */ |
812 | rtpcaps = gst_caps_new_simple("application/x-rtp", | 828 | rtpcaps = gst_caps_new_simple ("application/x-rtp", |
813 | "media", G_TYPE_STRING, "audio", | 829 | "media", G_TYPE_STRING, "audio", |
814 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, | 830 | "clock-rate", G_TYPE_INT, SAMPLING_RATE, |
815 | "encoding-name", G_TYPE_STRING, "OPUS", | 831 | "encoding-name", G_TYPE_STRING, "OPUS", |
816 | "payload", G_TYPE_INT, 96, | 832 | "payload", G_TYPE_INT, 96, |
817 | "sprop-stereo", G_TYPE_STRING, "0", | 833 | "sprop-stereo", G_TYPE_STRING, "0", |
818 | "encoding-params", G_TYPE_STRING, "2", | 834 | "encoding-params", G_TYPE_STRING, "2", |
819 | NULL); | 835 | NULL); |
820 | |||
821 | |||
822 | rtpcapsfilter = gst_element_factory_make("capsfilter", "rtpcapsfilter"); | ||
823 | |||
824 | g_object_set(G_OBJECT(rtpcapsfilter), | ||
825 | "caps", rtpcaps, | ||
826 | NULL); | ||
827 | gst_caps_unref(rtpcaps); | ||
828 | } | ||
829 | 836 | ||
830 | 837 | ||
831 | if (type == ENCODER) | 838 | rtpcapsfilter = gst_element_factory_make ("capsfilter", "rtpcapsfilter"); |
832 | { | 839 | |
833 | bin = GST_BIN(gst_bin_new("Gnunet audioencoder")); | 840 | g_object_set (G_OBJECT (rtpcapsfilter), |
841 | "caps", rtpcaps, | ||
842 | NULL); | ||
843 | gst_caps_unref (rtpcaps); | ||
844 | } | ||
834 | 845 | ||
835 | encoder = gst_element_factory_make("opusenc", "opus-encoder"); | ||
836 | if (d->usertp == TRUE) | ||
837 | { | ||
838 | muxer = gst_element_factory_make("rtpopuspay", "rtp-payloader"); | ||
839 | } | ||
840 | else | ||
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 | } | ||
861 | 846 | ||
862 | gst_bin_add_many(bin, encoder, muxer, NULL); | 847 | if (type == ENCODER) |
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 audioencoder")); |
865 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); | ||
866 | 850 | ||
867 | srcpad = gst_element_get_static_pad(muxer, "src"); | 851 | encoder = gst_element_factory_make ("opusenc", "opus-encoder"); |
868 | srcghostpad = gst_ghost_pad_new("src", srcpad); | 852 | if (d->usertp == TRUE) |
853 | { | ||
854 | muxer = gst_element_factory_make ("rtpopuspay", "rtp-payloader"); | ||
869 | } | 855 | } |
870 | if (type == DECODER) | 856 | else |
857 | { | ||
858 | muxer = gst_element_factory_make ("oggmux", "ogg-muxer"); | ||
859 | } | ||
860 | g_object_set (G_OBJECT (encoder), | ||
861 | /* "bitrate", 64000, */ | ||
862 | /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ | ||
863 | "inband-fec", INBAND_FEC_MODE, | ||
864 | "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, | ||
865 | "max-payload-size", MAX_PAYLOAD_SIZE, | ||
866 | "audio", TRUE, /* VoIP, not audio */ | ||
867 | "frame-size", OPUS_FRAME_SIZE, | ||
868 | NULL); | ||
869 | |||
870 | if (d->usertp != TRUE) | ||
871 | { | 871 | { |
872 | bin = GST_BIN(gst_bin_new("Gnunet audiodecoder")); | 872 | g_object_set (G_OBJECT (muxer), |
873 | "max-delay", OGG_MAX_DELAY, | ||
874 | "max-page-delay", OGG_MAX_PAGE_DELAY, | ||
875 | NULL); | ||
876 | } | ||
873 | 877 | ||
874 | // decoder | 878 | gst_bin_add_many (bin, encoder, muxer, NULL); |
875 | if (d->usertp == TRUE) | 879 | gst_element_link_many (encoder, muxer, NULL); |
876 | { | 880 | sinkpad = gst_element_get_static_pad (encoder, "sink"); |
877 | demuxer = gst_element_factory_make("rtpopusdepay", "ogg-demuxer"); | 881 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); |
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"); | ||
885 | 882 | ||
886 | if (d->usertp == TRUE) | 883 | srcpad = gst_element_get_static_pad (muxer, "src"); |
887 | { | 884 | srcghostpad = gst_ghost_pad_new ("src", srcpad); |
888 | gst_bin_add_many(bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | 885 | } |
889 | gst_element_link_many(rtpcapsfilter, jitterbuffer, demuxer, decoder, NULL); | 886 | if (type == DECODER) |
890 | sinkpad = gst_element_get_static_pad(rtpcapsfilter, "sink"); | 887 | { |
891 | } | 888 | bin = GST_BIN (gst_bin_new ("Gnunet audiodecoder")); |
892 | else | ||
893 | { | ||
894 | gst_bin_add_many(bin, demuxer, decoder, NULL); | ||
895 | 889 | ||
896 | g_signal_connect(demuxer, | 890 | // decoder |
897 | "pad-added", | 891 | if (d->usertp == TRUE) |
898 | G_CALLBACK(decoder_ogg_pad_added), | 892 | { |
899 | decoder); | 893 | demuxer = gst_element_factory_make ("rtpopusdepay", "ogg-demuxer"); |
894 | jitterbuffer = gst_element_factory_make ("rtpjitterbuffer", | ||
895 | "rtpjitterbuffer"); | ||
896 | } | ||
897 | else | ||
898 | { | ||
899 | demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); | ||
900 | } | ||
901 | decoder = gst_element_factory_make ("opusdec", "opus-decoder"); | ||
900 | 902 | ||
901 | sinkpad = gst_element_get_static_pad(demuxer, "sink"); | 903 | if (d->usertp == TRUE) |
902 | } | 904 | { |
903 | sinkghostpad = gst_ghost_pad_new("sink", sinkpad); | 905 | gst_bin_add_many (bin, rtpcapsfilter, jitterbuffer, demuxer, decoder, |
906 | NULL); | ||
907 | gst_element_link_many (rtpcapsfilter, jitterbuffer, demuxer, decoder, | ||
908 | NULL); | ||
909 | sinkpad = gst_element_get_static_pad (rtpcapsfilter, "sink"); | ||
910 | } | ||
911 | else | ||
912 | { | ||
913 | gst_bin_add_many (bin, demuxer, decoder, NULL); | ||
914 | |||
915 | g_signal_connect (demuxer, | ||
916 | "pad-added", | ||
917 | G_CALLBACK (decoder_ogg_pad_added), | ||
918 | decoder); | ||
904 | 919 | ||
905 | srcpad = gst_element_get_static_pad(decoder, "src"); | 920 | sinkpad = gst_element_get_static_pad (demuxer, "sink"); |
906 | srcghostpad = gst_ghost_pad_new("src", srcpad); | ||
907 | } | 921 | } |
922 | sinkghostpad = gst_ghost_pad_new ("sink", sinkpad); | ||
923 | |||
924 | srcpad = gst_element_get_static_pad (decoder, "src"); | ||
925 | srcghostpad = gst_ghost_pad_new ("src", srcpad); | ||
926 | } | ||
908 | 927 | ||
909 | // add pads to the bin | 928 | // add pads to the bin |
910 | gst_pad_set_active(sinkghostpad, TRUE); | 929 | gst_pad_set_active (sinkghostpad, TRUE); |
911 | gst_element_add_pad(GST_ELEMENT(bin), sinkghostpad); | 930 | gst_element_add_pad (GST_ELEMENT (bin), sinkghostpad); |
912 | 931 | ||
913 | gst_pad_set_active(srcghostpad, TRUE); | 932 | gst_pad_set_active (srcghostpad, TRUE); |
914 | gst_element_add_pad(GST_ELEMENT(bin), srcghostpad); | 933 | gst_element_add_pad (GST_ELEMENT (bin), srcghostpad); |
915 | 934 | ||
916 | 935 | ||
917 | return bin; | 936 | return bin; |
@@ -919,7 +938,7 @@ get_coder(GNUNET_gstData *d, int type) | |||
919 | 938 | ||
920 | 939 | ||
921 | extern GstBin * | 940 | extern GstBin * |
922 | get_audiobin(GNUNET_gstData *d, int type) | 941 | get_audiobin (GNUNET_gstData *d, int type) |
923 | { | 942 | { |
924 | GstBin *bin; | 943 | GstBin *bin; |
925 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; | 944 | GstElement *sink, *source, *queue, *conv, *resampler, *removesilence, *filter; |
@@ -927,72 +946,74 @@ get_audiobin(GNUNET_gstData *d, int type) | |||
927 | GstCaps *caps; | 946 | GstCaps *caps; |
928 | 947 | ||
929 | if (type == SINK) | 948 | if (type == SINK) |
930 | { | 949 | { |
931 | bin = GST_BIN(gst_bin_new("Gnunet audiosink")); | 950 | bin = GST_BIN (gst_bin_new ("Gnunet audiosink")); |
932 | 951 | ||
933 | /* Create all the elements */ | 952 | /* Create all the elements */ |
934 | if (d->dropsilence == TRUE) | 953 | if (d->dropsilence == TRUE) |
935 | { | 954 | { |
936 | queue = gst_element_factory_make("queue", "queue"); | 955 | queue = gst_element_factory_make ("queue", "queue"); |
937 | removesilence = gst_element_factory_make("removesilence", "removesilence"); | 956 | removesilence = gst_element_factory_make ("removesilence", |
938 | } | 957 | "removesilence"); |
958 | } | ||
939 | 959 | ||
940 | conv = gst_element_factory_make("audioconvert", "converter"); | 960 | conv = gst_element_factory_make ("audioconvert", "converter"); |
941 | resampler = gst_element_factory_make("audioresample", "resampler"); | 961 | resampler = gst_element_factory_make ("audioresample", "resampler"); |
942 | 962 | ||
943 | if (d->audiobackend == AUTO) | 963 | if (d->audiobackend == AUTO) |
944 | { | 964 | { |
945 | sink = gst_element_factory_make("autoaudiosink", "audiosink"); | 965 | sink = gst_element_factory_make ("autoaudiosink", "audiosink"); |
946 | g_signal_connect(sink, "child-added", G_CALLBACK(autoaudiosink_child_added), NULL); | 966 | g_signal_connect (sink, "child-added", G_CALLBACK ( |
947 | } | 967 | autoaudiosink_child_added), NULL); |
968 | } | ||
948 | 969 | ||
949 | if (d->audiobackend == ALSA) | 970 | if (d->audiobackend == ALSA) |
950 | { | 971 | { |
951 | sink = gst_element_factory_make("alsaaudiosink", "audiosink"); | 972 | sink = gst_element_factory_make ("alsaaudiosink", "audiosink"); |
952 | } | 973 | } |
953 | 974 | ||
954 | if (d->audiobackend == JACK) | 975 | if (d->audiobackend == JACK) |
955 | { | 976 | { |
956 | sink = gst_element_factory_make("jackaudiosink", "audiosink"); | 977 | sink = gst_element_factory_make ("jackaudiosink", "audiosink"); |
957 | 978 | ||
958 | g_object_set(G_OBJECT(sink), "client-name", "gnunet", NULL); | 979 | g_object_set (G_OBJECT (sink), "client-name", "gnunet", NULL); |
959 | 980 | ||
960 | if (g_object_class_find_property | 981 | if (g_object_class_find_property |
961 | (G_OBJECT_GET_CLASS(sink), "port-pattern")) | 982 | (G_OBJECT_GET_CLASS (sink), "port-pattern")) |
962 | { | 983 | { |
963 | // char *portpattern = "system"; | 984 | // char *portpattern = "system"; |
964 | 985 | ||
965 | g_object_set(G_OBJECT(sink), "port-pattern", d->jack_pp_out, | 986 | g_object_set (G_OBJECT (sink), "port-pattern", d->jack_pp_out, |
966 | NULL); | 987 | NULL); |
967 | } | 988 | } |
968 | } | 989 | } |
969 | 990 | ||
970 | if (d->audiobackend == FAKE) | 991 | if (d->audiobackend == FAKE) |
971 | { | 992 | { |
972 | sink = gst_element_factory_make("fakesink", "audiosink"); | 993 | sink = gst_element_factory_make ("fakesink", "audiosink"); |
973 | } | 994 | } |
974 | 995 | ||
975 | g_object_set(sink, | 996 | g_object_set (sink, |
976 | "buffer-time", (gint64)BUFFER_TIME, | 997 | "buffer-time", (gint64) BUFFER_TIME, |
977 | "latency-time", (gint64)LATENCY_TIME, | 998 | "latency-time", (gint64) LATENCY_TIME, |
978 | NULL); | 999 | NULL); |
979 | 1000 | ||
980 | if (d->dropsilence == TRUE) | 1001 | if (d->dropsilence == TRUE) |
981 | { | 1002 | { |
982 | // Do not remove silence by default | 1003 | // Do not remove silence by default |
983 | g_object_set(removesilence, "remove", FALSE, NULL); | 1004 | g_object_set (removesilence, "remove", FALSE, NULL); |
984 | g_object_set(queue, "max-size-buffers", 12, NULL); | 1005 | g_object_set (queue, "max-size-buffers", 12, NULL); |
985 | /* | 1006 | /* |
986 | g_signal_connect (source, | 1007 | g_signal_connect (source, |
987 | "need-data", | 1008 | "need-data", |
988 | G_CALLBACK(appsrc_need_data), | 1009 | G_CALLBACK(appsrc_need_data), |
989 | NULL); | 1010 | NULL); |
990 | 1011 | ||
991 | g_signal_connect (source, | 1012 | g_signal_connect (source, |
992 | "enough-data", | 1013 | "enough-data", |
993 | G_CALLBACK(appsrc_enough_data), | 1014 | G_CALLBACK(appsrc_enough_data), |
994 | NULL); | 1015 | NULL); |
995 | */ | 1016 | */ |
996 | /* | 1017 | /* |
997 | g_signal_connect (queue, | 1018 | g_signal_connect (queue, |
998 | "notify::current-level-bytes", | 1019 | "notify::current-level-bytes", |
@@ -1019,109 +1040,111 @@ get_audiobin(GNUNET_gstData *d, int type) | |||
1019 | G_CALLBACK(queue_pushing), | 1040 | G_CALLBACK(queue_pushing), |
1020 | NULL); | 1041 | NULL); |
1021 | */ | 1042 | */ |
1022 | } | 1043 | } |
1023 | |||
1024 | 1044 | ||
1025 | 1045 | ||
1026 | 1046 | ||
1027 | 1047 | ||
1028 | gst_bin_add_many(bin, conv, resampler, sink, NULL); | ||
1029 | gst_element_link_many(conv, resampler, sink, NULL); | ||
1030 | 1048 | ||
1031 | if (d->dropsilence == TRUE) | 1049 | gst_bin_add_many (bin, conv, resampler, sink, NULL); |
1032 | { | 1050 | gst_element_link_many (conv, resampler, sink, NULL); |
1033 | gst_bin_add_many(bin, queue, removesilence, NULL); | ||
1034 | 1051 | ||
1035 | if (!gst_element_link_many(queue, removesilence, conv, NULL)) | 1052 | if (d->dropsilence == TRUE) |
1036 | lf("queue, removesilence, conv "); | 1053 | { |
1054 | gst_bin_add_many (bin, queue, removesilence, NULL); | ||
1037 | 1055 | ||
1038 | pad = gst_element_get_static_pad(queue, "sink"); | 1056 | if (! gst_element_link_many (queue, removesilence, conv, NULL)) |
1039 | } | 1057 | lf ("queue, removesilence, conv "); |
1040 | else | ||
1041 | { | ||
1042 | pad = gst_element_get_static_pad(conv, "sink"); | ||
1043 | } | ||
1044 | 1058 | ||
1045 | ghostpad = gst_ghost_pad_new("sink", pad); | 1059 | pad = gst_element_get_static_pad (queue, "sink"); |
1046 | } | 1060 | } |
1047 | else | 1061 | else |
1048 | { | 1062 | { |
1049 | // SOURCE | 1063 | pad = gst_element_get_static_pad (conv, "sink"); |
1064 | } | ||
1050 | 1065 | ||
1051 | bin = GST_BIN(gst_bin_new("Gnunet audiosource")); | 1066 | ghostpad = gst_ghost_pad_new ("sink", pad); |
1067 | } | ||
1068 | else | ||
1069 | { | ||
1070 | // SOURCE | ||
1052 | 1071 | ||
1053 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); | 1072 | bin = GST_BIN (gst_bin_new ("Gnunet audiosource")); |
1054 | 1073 | ||
1055 | if (d->audiobackend == AUTO) | 1074 | // source = gst_element_factory_make("audiotestsrc", "audiotestsrcbla"); |
1056 | { | ||
1057 | source = gst_element_factory_make("autoaudiosrc", "audiosource"); | ||
1058 | } | ||
1059 | if (d->audiobackend == ALSA) | ||
1060 | { | ||
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) | ||
1068 | { | ||
1069 | source = gst_element_factory_make("audiotestsrc", "audiosource"); | ||
1070 | } | ||
1071 | 1075 | ||
1072 | filter = gst_element_factory_make("capsfilter", "filter"); | 1076 | if (d->audiobackend == AUTO) |
1073 | conv = gst_element_factory_make("audioconvert", "converter"); | 1077 | { |
1074 | resampler = gst_element_factory_make("audioresample", "resampler"); | 1078 | source = gst_element_factory_make ("autoaudiosrc", "audiosource"); |
1079 | } | ||
1080 | if (d->audiobackend == ALSA) | ||
1081 | { | ||
1082 | source = gst_element_factory_make ("alsasrc", "audiosource"); | ||
1083 | } | ||
1084 | if (d->audiobackend == JACK) | ||
1085 | { | ||
1086 | source = gst_element_factory_make ("jackaudiosrc", "audiosource"); | ||
1087 | } | ||
1088 | if (d->audiobackend == TEST) | ||
1089 | { | ||
1090 | source = gst_element_factory_make ("audiotestsrc", "audiosource"); | ||
1091 | } | ||
1075 | 1092 | ||
1076 | if (d->audiobackend == AUTO) | 1093 | filter = gst_element_factory_make ("capsfilter", "filter"); |
1077 | { | 1094 | conv = gst_element_factory_make ("audioconvert", "converter"); |
1078 | g_signal_connect(source, "child-added", G_CALLBACK(autoaudiosource_child_added), NULL); | 1095 | resampler = gst_element_factory_make ("audioresample", "resampler"); |
1079 | } | 1096 | |
1080 | else | 1097 | if (d->audiobackend == AUTO) |
1098 | { | ||
1099 | g_signal_connect (source, "child-added", G_CALLBACK ( | ||
1100 | autoaudiosource_child_added), NULL); | ||
1101 | } | ||
1102 | else | ||
1103 | { | ||
1104 | if (GST_IS_AUDIO_BASE_SRC (source)) | ||
1105 | g_object_set (source, "buffer-time", (gint64) BUFFER_TIME, | ||
1106 | "latency-time", (gint64) LATENCY_TIME, NULL); | ||
1107 | if (d->audiobackend == JACK) | ||
1108 | { | ||
1109 | g_object_set (G_OBJECT (source), "client-name", "gnunet", NULL); | ||
1110 | if (g_object_class_find_property | ||
1111 | (G_OBJECT_GET_CLASS (source), "port-pattern")) | ||
1081 | { | 1112 | { |
1082 | if (GST_IS_AUDIO_BASE_SRC(source)) | 1113 | char *portpattern = "moc"; |
1083 | g_object_set(source, "buffer-time", (gint64)BUFFER_TIME, "latency-time", (gint64)LATENCY_TIME, NULL); | 1114 | |
1084 | if (d->audiobackend == JACK) | 1115 | g_object_set (G_OBJECT (source), "port-pattern", portpattern, |
1085 | { | 1116 | NULL); |
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 | } | ||
1096 | } | 1117 | } |
1118 | } | ||
1119 | } | ||
1097 | 1120 | ||
1098 | caps = gst_caps_new_simple("audio/x-raw", | 1121 | caps = gst_caps_new_simple ("audio/x-raw", |
1099 | /* "format", G_TYPE_STRING, "S16LE", */ | 1122 | /* "format", G_TYPE_STRING, "S16LE", */ |
1100 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ | 1123 | /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ |
1101 | "channels", G_TYPE_INT, OPUS_CHANNELS, | 1124 | "channels", G_TYPE_INT, OPUS_CHANNELS, |
1102 | /* "layout", G_TYPE_STRING, "interleaved",*/ | 1125 | /* "layout", G_TYPE_STRING, "interleaved",*/ |
1103 | NULL); | 1126 | NULL); |
1104 | 1127 | ||
1105 | g_object_set(G_OBJECT(filter), | 1128 | g_object_set (G_OBJECT (filter), |
1106 | "caps", caps, | 1129 | "caps", caps, |
1107 | NULL); | 1130 | NULL); |
1108 | gst_caps_unref(caps); | 1131 | gst_caps_unref (caps); |
1109 | 1132 | ||
1110 | gst_bin_add_many(bin, source, filter, conv, resampler, NULL); | 1133 | gst_bin_add_many (bin, source, filter, conv, resampler, NULL); |
1111 | gst_element_link_many(source, filter, conv, resampler, NULL); | 1134 | gst_element_link_many (source, filter, conv, resampler, NULL); |
1112 | 1135 | ||
1113 | pad = gst_element_get_static_pad(resampler, "src"); | 1136 | pad = gst_element_get_static_pad (resampler, "src"); |
1114 | 1137 | ||
1115 | 1138 | ||
1116 | /* pads */ | 1139 | /* pads */ |
1117 | ghostpad = gst_ghost_pad_new("src", pad); | 1140 | ghostpad = gst_ghost_pad_new ("src", pad); |
1118 | } | 1141 | } |
1119 | 1142 | ||
1120 | /* set the bin pads */ | 1143 | /* set the bin pads */ |
1121 | gst_pad_set_active(ghostpad, TRUE); | 1144 | gst_pad_set_active (ghostpad, TRUE); |
1122 | gst_element_add_pad(GST_ELEMENT(bin), ghostpad); | 1145 | gst_element_add_pad (GST_ELEMENT (bin), ghostpad); |
1123 | 1146 | ||
1124 | gst_object_unref(pad); | 1147 | gst_object_unref (pad); |
1125 | 1148 | ||
1126 | return bin; | 1149 | return bin; |
1127 | } | 1150 | } |
diff --git a/src/conversation/gnunet_gst.h b/src/conversation/gnunet_gst.h index 8667a823b..479ae14b3 100644 --- a/src/conversation/gnunet_gst.h +++ b/src/conversation/gnunet_gst.h | |||
@@ -33,29 +33,30 @@ | |||
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 ( \ |
37 | element, name); | ||
37 | 38 | ||
38 | extern void pl_graph(); | 39 | extern void pl_graph (); |
39 | 40 | ||
40 | 41 | ||
41 | extern GstElement * | 42 | extern GstElement * |
42 | gst_element_factory_make_debug(gchar *, gchar *); | 43 | gst_element_factory_make_debug (gchar *, gchar *); |
43 | 44 | ||
44 | extern GstBin * | 45 | extern GstBin * |
45 | get_audiobin(GNUNET_gstData *, int); | 46 | get_audiobin (GNUNET_gstData *, int); |
46 | 47 | ||
47 | extern GstBin * | 48 | extern GstBin * |
48 | get_coder(GNUNET_gstData *, int); | 49 | get_coder (GNUNET_gstData *, int); |
49 | 50 | ||
50 | 51 | ||
51 | extern gboolean | 52 | extern gboolean |
52 | gnunet_gst_bus_call(GstBus *bus, GstMessage *msg, gpointer data); | 53 | gnunet_gst_bus_call (GstBus *bus, GstMessage *msg, gpointer data); |
53 | 54 | ||
54 | extern void | 55 | extern void |
55 | gg_setup_gst_bus(GNUNET_gstData * d); | 56 | gg_setup_gst_bus (GNUNET_gstData *d); |
56 | 57 | ||
57 | extern void | 58 | extern void |
58 | gg_load_configuration(GNUNET_gstData * d); | 59 | gg_load_configuration (GNUNET_gstData *d); |
59 | 60 | ||
60 | extern GstFlowReturn | 61 | extern GstFlowReturn |
61 | on_appsink_new_sample(GstElement *, GNUNET_gstData *); | 62 | on_appsink_new_sample (GstElement *, GNUNET_gstData *); |
diff --git a/src/conversation/gnunet_gst_def.h b/src/conversation/gnunet_gst_def.h index 5f5910121..bbadc5f92 100644 --- a/src/conversation/gnunet_gst_def.h +++ b/src/conversation/gnunet_gst_def.h | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "platform.h" | 36 | #include "platform.h" |
37 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
38 | #include "gnunet_protocols.h" | 38 | #include "gnunet_protocols.h" |
39 | //#include "gnunet/conversation.h" doesn't get installed | 39 | // #include "gnunet/conversation.h" doesn't get installed |
40 | #include "conversation.h" | 40 | #include "conversation.h" |
41 | #include "gnunet_constants.h" | 41 | #include "gnunet_constants.h" |
42 | #include "gnunet_core_service.h" | 42 | #include "gnunet_core_service.h" |
@@ -76,18 +76,19 @@ | |||
76 | #include <fcntl.h> | 76 | #include <fcntl.h> |
77 | 77 | ||
78 | 78 | ||
79 | //glib stuff | 79 | // glib stuff |
80 | //#include <glib.h> | 80 | // #include <glib.h> |
81 | #include <glib-2.0/glib/gprintf.h> | 81 | #include <glib-2.0/glib/gprintf.h> |
82 | //#include <glib-unix.h> | 82 | // #include <glib-unix.h> |
83 | 83 | ||
84 | // static struct AudioMessage *audio_message; | 84 | // static struct AudioMessage *audio_message; |
85 | 85 | ||
86 | 86 | ||
87 | 87 | ||
88 | typedef struct GNUNET_gstData GNUNET_gstData; | 88 | typedef struct GNUNET_gstData GNUNET_gstData; |
89 | struct GNUNET_gstData { | 89 | struct GNUNET_gstData |
90 | //general | 90 | { |
91 | // general | ||
91 | GstPipeline *pipeline; | 92 | GstPipeline *pipeline; |
92 | 93 | ||
93 | // things | 94 | // things |
@@ -95,7 +96,7 @@ struct GNUNET_gstData { | |||
95 | struct GNUNET_MessageStreamTokenizer *stdin_mst; | 96 | struct GNUNET_MessageStreamTokenizer *stdin_mst; |
96 | GstElement *appsrc; | 97 | GstElement *appsrc; |
97 | GstElement *appsink; | 98 | GstElement *appsink; |
98 | //settings | 99 | // settings |
99 | int audiobackend; | 100 | int audiobackend; |
100 | int dropsilence; | 101 | int dropsilence; |
101 | int usertp; | 102 | int usertp; |
@@ -187,7 +188,8 @@ struct GNUNET_gstData { | |||
187 | 188 | ||
188 | #define SAMPLING_RATE 48000 | 189 | #define SAMPLING_RATE 48000 |
189 | 190 | ||
190 | enum { | 191 | enum |
192 | { | ||
191 | AUTO, | 193 | AUTO, |
192 | JACK, | 194 | JACK, |
193 | ALSA, | 195 | ALSA, |
@@ -195,22 +197,26 @@ enum { | |||
195 | TEST | 197 | TEST |
196 | }; | 198 | }; |
197 | 199 | ||
198 | enum { | 200 | enum |
201 | { | ||
199 | SOURCE, | 202 | SOURCE, |
200 | SINK | 203 | SINK |
201 | }; | 204 | }; |
202 | 205 | ||
203 | enum { | 206 | enum |
207 | { | ||
204 | ENCODER, | 208 | ENCODER, |
205 | DECODER | 209 | DECODER |
206 | }; | 210 | }; |
207 | 211 | ||
208 | enum { | 212 | enum |
213 | { | ||
209 | FAIL, | 214 | FAIL, |
210 | OK | 215 | OK |
211 | }; | 216 | }; |
212 | 217 | ||
213 | enum { | 218 | enum |
219 | { | ||
214 | SPEAKER, | 220 | SPEAKER, |
215 | MICROPHONE | 221 | MICROPHONE |
216 | }; | 222 | }; |
diff --git a/src/conversation/gnunet_gst_test.c b/src/conversation/gnunet_gst_test.c index 60e920f10..884b0fe83 100644 --- a/src/conversation/gnunet_gst_test.c +++ b/src/conversation/gnunet_gst_test.c | |||
@@ -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; |
@@ -36,80 +36,81 @@ main(int argc, char *argv[]) | |||
36 | 36 | ||
37 | 37 | ||
38 | // audio_message = GNUNET_malloc (UINT16_MAX); | 38 | // audio_message = GNUNET_malloc (UINT16_MAX); |
39 | //audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 39 | // audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
40 | 40 | ||
41 | 41 | ||
42 | //GstPipeline *pipeline; | 42 | // GstPipeline *pipeline; |
43 | 43 | ||
44 | gst = (GNUNET_gstData*)malloc(sizeof(struct GNUNET_gstData)); | 44 | gst = (GNUNET_gstData*) malloc (sizeof(struct GNUNET_gstData)); |
45 | 45 | ||
46 | //gst->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 46 | // gst->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
47 | 47 | ||
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; |
62 | printf("this is the speaker \n"); | 62 | printf ("this is the speaker \n"); |
63 | #endif | 63 | #endif |
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 | #endif | 67 | #endif |
68 | if (type == SPEAKER) | 68 | if (type == SPEAKER) |
69 | { | 69 | { |
70 | gnunetsrc = GST_ELEMENT(get_app(gst, SOURCE)); | 70 | gnunetsrc = GST_ELEMENT (get_app (gst, SOURCE)); |
71 | 71 | ||
72 | sink = GST_ELEMENT(get_audiobin(gst, SINK)); | 72 | sink = GST_ELEMENT (get_audiobin (gst, SINK)); |
73 | decoder = GST_ELEMENT(get_coder(gst, DECODER)); | 73 | decoder = GST_ELEMENT (get_coder (gst, DECODER)); |
74 | gst_bin_add_many(GST_BIN(gst->pipeline), gnunetsrc, decoder, sink, NULL); | 74 | gst_bin_add_many (GST_BIN (gst->pipeline), gnunetsrc, decoder, sink, NULL); |
75 | gst_element_link_many(gnunetsrc, decoder, sink, NULL); | 75 | gst_element_link_many (gnunetsrc, decoder, sink, NULL); |
76 | } | 76 | } |
77 | if (type == MICROPHONE) | 77 | if (type == MICROPHONE) |
78 | { | 78 | { |
79 | source = GST_ELEMENT(get_audiobin(gst, SOURCE)); | 79 | source = GST_ELEMENT (get_audiobin (gst, SOURCE)); |
80 | 80 | ||
81 | encoder = GST_ELEMENT(get_coder(gst, ENCODER)); | 81 | encoder = GST_ELEMENT (get_coder (gst, ENCODER)); |
82 | 82 | ||
83 | gnunetsink = GST_ELEMENT(get_app(gst, SINK)); | 83 | gnunetsink = GST_ELEMENT (get_app (gst, SINK)); |
84 | 84 | ||
85 | gst_bin_add_many(GST_BIN(gst->pipeline), source, encoder, gnunetsink, NULL); | 85 | gst_bin_add_many (GST_BIN (gst->pipeline), source, encoder, gnunetsink, |
86 | gst_element_link_many(source, encoder, gnunetsink, NULL); | 86 | NULL); |
87 | } | 87 | gst_element_link_many (source, encoder, gnunetsink, NULL); |
88 | } | ||
88 | /* | 89 | /* |
89 | gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL); | 90 | gst_bin_add_many( GST_BIN(gst->pipeline), appsource, appsink, source, encoder, decoder, sink, NULL); |
90 | gst_element_link_many( source, encoder, decoder, sink , NULL); | 91 | gst_element_link_many( source, encoder, decoder, sink , NULL); |
91 | */ | 92 | */ |
92 | pl_graph(gst->pipeline); | 93 | pl_graph (gst->pipeline); |
93 | /* Start playing */ | 94 | /* Start playing */ |
94 | gst_element_set_state(GST_ELEMENT(gst->pipeline), GST_STATE_PLAYING); | 95 | gst_element_set_state (GST_ELEMENT (gst->pipeline), GST_STATE_PLAYING); |
95 | 96 | ||
96 | //pl_graph(gst->pipeline); | 97 | // pl_graph(gst->pipeline); |
97 | 98 | ||
98 | /* Wait until error or EOS */ | 99 | /* Wait until error or EOS */ |
99 | //bus = gst_element_get_bus (GST_ELEMENT(gst->pipeline)); | 100 | // bus = gst_element_get_bus (GST_ELEMENT(gst->pipeline)); |
100 | //bus_watch_id = gst_bus_add_watch (bus, gnunet_gst_bus_call, pipeline); | 101 | // bus_watch_id = gst_bus_add_watch (bus, gnunet_gst_bus_call, pipeline); |
101 | 102 | ||
102 | gg_setup_gst_bus(gst); | 103 | gg_setup_gst_bus (gst); |
103 | // g_print ("Running...\n"); | 104 | // g_print ("Running...\n"); |
104 | 105 | ||
105 | 106 | ||
106 | // start pushing buffers | 107 | // start pushing buffers |
107 | if (type == MICROPHONE) | 108 | if (type == MICROPHONE) |
108 | { | 109 | { |
109 | GMainLoop *loop; | 110 | GMainLoop *loop; |
110 | loop = g_main_loop_new(NULL, FALSE); | 111 | loop = g_main_loop_new (NULL, FALSE); |
111 | 112 | ||
112 | g_main_loop_run(loop); | 113 | g_main_loop_run (loop); |
113 | 114 | ||
114 | /* | 115 | /* |
115 | while ( 1 ) | 116 | while ( 1 ) |
@@ -118,20 +119,20 @@ main(int argc, char *argv[]) | |||
118 | flow = on_appsink_new_sample (gst->appsink, gst); | 119 | flow = on_appsink_new_sample (gst->appsink, gst); |
119 | } | 120 | } |
120 | */ | 121 | */ |
121 | } | 122 | } |
122 | if (type == SPEAKER) | 123 | if (type == SPEAKER) |
124 | { | ||
125 | while (1) | ||
123 | { | 126 | { |
124 | while (1) | ||
125 | { | ||
126 | // printf("read.. \n"); | 127 | // printf("read.. \n"); |
127 | gnunet_read(gst); | 128 | gnunet_read (gst); |
128 | } | ||
129 | } | 129 | } |
130 | g_print("Returned, stopping playback\n"); | 130 | } |
131 | g_print ("Returned, stopping playback\n"); | ||
131 | 132 | ||
132 | // gst_object_unref (bus); | 133 | // gst_object_unref (bus); |
133 | gst_element_set_state(GST_ELEMENT(gst->pipeline), GST_STATE_NULL); | 134 | gst_element_set_state (GST_ELEMENT (gst->pipeline), GST_STATE_NULL); |
134 | gst_object_unref(gst->pipeline); | 135 | gst_object_unref (gst->pipeline); |
135 | 136 | ||
136 | return 0; | 137 | return 0; |
137 | } | 138 | } |
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c index 01f8adb1e..5ab115c1f 100644 --- a/src/conversation/microphone.c +++ b/src/conversation/microphone.c | |||
@@ -34,7 +34,8 @@ | |||
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 | { | ||
38 | /** | 39 | /** |
39 | * Our configuration. | 40 | * Our configuration. |
40 | */ | 41 | */ |
@@ -67,21 +68,21 @@ struct Microphone { | |||
67 | * #GNUNET_SYSERR to stop further processing with error | 68 | * #GNUNET_SYSERR to stop further processing with error |
68 | */ | 69 | */ |
69 | static int | 70 | static int |
70 | process_record_messages(void *cls, | 71 | process_record_messages (void *cls, |
71 | const struct GNUNET_MessageHeader *msg) | 72 | const struct GNUNET_MessageHeader *msg) |
72 | { | 73 | { |
73 | struct Microphone *mic = cls; | 74 | struct Microphone *mic = cls; |
74 | const struct AudioMessage *am; | 75 | const struct AudioMessage *am; |
75 | 76 | ||
76 | if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) | 77 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO) |
77 | { | 78 | { |
78 | GNUNET_break(0); | 79 | GNUNET_break (0); |
79 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
80 | } | 81 | } |
81 | am = (const struct AudioMessage *)msg; | 82 | am = (const struct AudioMessage *) msg; |
82 | mic->rdc(mic->rdc_cls, | 83 | mic->rdc (mic->rdc_cls, |
83 | ntohs(msg->size) - sizeof(struct AudioMessage), | 84 | ntohs (msg->size) - sizeof(struct AudioMessage), |
84 | &am[1]); | 85 | &am[1]); |
85 | return GNUNET_OK; | 86 | return GNUNET_OK; |
86 | } | 87 | } |
87 | 88 | ||
@@ -94,30 +95,29 @@ process_record_messages(void *cls, | |||
94 | * @param rdc_cls closure for @a dc | 95 | * @param rdc_cls closure for @a dc |
95 | */ | 96 | */ |
96 | static int | 97 | static int |
97 | enable(void *cls, | 98 | enable (void *cls, |
98 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 99 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
99 | void *rdc_cls) | 100 | void *rdc_cls) |
100 | { | 101 | { |
101 | struct Microphone *mic = cls; | 102 | struct Microphone *mic = cls; |
102 | static char * const record_helper_argv[] = | 103 | static char *const record_helper_argv[] = { |
103 | { | ||
104 | "gnunet-helper-audio-record", | 104 | "gnunet-helper-audio-record", |
105 | NULL | 105 | NULL |
106 | }; | 106 | }; |
107 | 107 | ||
108 | mic->rdc = rdc; | 108 | mic->rdc = rdc; |
109 | mic->rdc_cls = rdc_cls; | 109 | mic->rdc_cls = rdc_cls; |
110 | mic->record_helper = GNUNET_HELPER_start(GNUNET_NO, | 110 | mic->record_helper = GNUNET_HELPER_start (GNUNET_NO, |
111 | "gnunet-helper-audio-record", | 111 | "gnunet-helper-audio-record", |
112 | record_helper_argv, | 112 | record_helper_argv, |
113 | &process_record_messages, | 113 | &process_record_messages, |
114 | NULL, mic); | 114 | NULL, mic); |
115 | if (NULL == mic->record_helper) | 115 | if (NULL == mic->record_helper) |
116 | { | 116 | { |
117 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
118 | _("Could not start record audio helper\n")); | 118 | _ ("Could not start record audio helper\n")); |
119 | return GNUNET_SYSERR; | 119 | return GNUNET_SYSERR; |
120 | } | 120 | } |
121 | return GNUNET_OK; | 121 | return GNUNET_OK; |
122 | } | 122 | } |
123 | 123 | ||
@@ -128,18 +128,18 @@ enable(void *cls, | |||
128 | * @param cls clsoure | 128 | * @param cls clsoure |
129 | */ | 129 | */ |
130 | static void | 130 | static void |
131 | disable(void *cls) | 131 | disable (void *cls) |
132 | { | 132 | { |
133 | struct Microphone *mic = cls; | 133 | struct Microphone *mic = cls; |
134 | 134 | ||
135 | if (NULL == mic->record_helper) | 135 | if (NULL == mic->record_helper) |
136 | { | 136 | { |
137 | GNUNET_break(0); | 137 | GNUNET_break (0); |
138 | return; | 138 | return; |
139 | } | 139 | } |
140 | GNUNET_break(GNUNET_OK == | 140 | GNUNET_break (GNUNET_OK == |
141 | GNUNET_HELPER_kill(mic->record_helper, GNUNET_NO)); | 141 | GNUNET_HELPER_kill (mic->record_helper, GNUNET_NO)); |
142 | GNUNET_HELPER_destroy(mic->record_helper); | 142 | GNUNET_HELPER_destroy (mic->record_helper); |
143 | mic->record_helper = NULL; | 143 | mic->record_helper = NULL; |
144 | } | 144 | } |
145 | 145 | ||
@@ -150,12 +150,12 @@ disable(void *cls) | |||
150 | * @param cls clsoure | 150 | * @param cls clsoure |
151 | */ | 151 | */ |
152 | static void | 152 | static void |
153 | destroy(void *cls) | 153 | destroy (void *cls) |
154 | { | 154 | { |
155 | struct Microphone *mic = cls; | 155 | struct Microphone *mic = cls; |
156 | 156 | ||
157 | if (NULL != mic->record_helper) | 157 | if (NULL != mic->record_helper) |
158 | disable(mic); | 158 | disable (mic); |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
@@ -167,14 +167,15 @@ destroy(void *cls) | |||
167 | * @return NULL on error | 167 | * @return NULL on error |
168 | */ | 168 | */ |
169 | struct GNUNET_MICROPHONE_Handle * | 169 | struct GNUNET_MICROPHONE_Handle * |
170 | GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | GNUNET_MICROPHONE_create_from_hardware (const struct |
171 | GNUNET_CONFIGURATION_Handle *cfg) | ||
171 | { | 172 | { |
172 | struct GNUNET_MICROPHONE_Handle *microphone; | 173 | struct GNUNET_MICROPHONE_Handle *microphone; |
173 | struct Microphone *mic; | 174 | struct Microphone *mic; |
174 | 175 | ||
175 | mic = GNUNET_new(struct Microphone); | 176 | mic = GNUNET_new (struct Microphone); |
176 | mic->cfg = cfg; | 177 | mic->cfg = cfg; |
177 | microphone = GNUNET_new(struct GNUNET_MICROPHONE_Handle); | 178 | microphone = GNUNET_new (struct GNUNET_MICROPHONE_Handle); |
178 | microphone->cls = mic; | 179 | microphone->cls = mic; |
179 | microphone->enable_microphone = &enable; | 180 | microphone->enable_microphone = &enable; |
180 | microphone->disable_microphone = &disable; | 181 | microphone->disable_microphone = &disable; |
@@ -189,10 +190,10 @@ GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle | |||
189 | * @param microphone microphone to destroy | 190 | * @param microphone microphone to destroy |
190 | */ | 191 | */ |
191 | void | 192 | void |
192 | GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone) | 193 | GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone) |
193 | { | 194 | { |
194 | microphone->destroy_microphone(microphone->cls); | 195 | microphone->destroy_microphone (microphone->cls); |
195 | GNUNET_free(microphone); | 196 | GNUNET_free (microphone); |
196 | } | 197 | } |
197 | 198 | ||
198 | /* end of microphone.c */ | 199 | /* end of microphone.c */ |
diff --git a/src/conversation/plugin_gnsrecord_conversation.c b/src/conversation/plugin_gnsrecord_conversation.c index adf397333..9f7299c15 100644 --- a/src/conversation/plugin_gnsrecord_conversation.c +++ b/src/conversation/plugin_gnsrecord_conversation.c | |||
@@ -44,51 +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 | 88 | ||
89 | default: | 89 | default: |
90 | return NULL; | 90 | return NULL; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
@@ -104,63 +104,63 @@ conversation_value_to_string(void *cls, | |||
104 | * @return #GNUNET_OK on success | 104 | * @return #GNUNET_OK on success |
105 | */ | 105 | */ |
106 | static int | 106 | static int |
107 | conversation_string_to_value(void *cls, | 107 | conversation_string_to_value (void *cls, |
108 | uint32_t type, | 108 | uint32_t type, |
109 | const char *s, | 109 | const char *s, |
110 | void **data, | 110 | void **data, |
111 | size_t *data_size) | 111 | size_t *data_size) |
112 | { | 112 | { |
113 | (void)cls; | 113 | (void) cls; |
114 | if (NULL == s) | 114 | if (NULL == s) |
115 | { | 115 | { |
116 | GNUNET_break(0); | 116 | GNUNET_break (0); |
117 | return GNUNET_SYSERR; | 117 | return GNUNET_SYSERR; |
118 | } | 118 | } |
119 | switch (type) | 119 | switch (type) |
120 | { | 120 | { |
121 | case GNUNET_GNSRECORD_TYPE_PHONE: | 121 | case GNUNET_GNSRECORD_TYPE_PHONE: |
122 | { | 122 | { |
123 | struct GNUNET_CONVERSATION_PhoneRecord *pr; | 123 | struct GNUNET_CONVERSATION_PhoneRecord *pr; |
124 | char line_port[103]; | 124 | char line_port[103]; |
125 | const char *dash; | 125 | const char *dash; |
126 | struct GNUNET_PeerIdentity peer; | 126 | struct GNUNET_PeerIdentity peer; |
127 | 127 | ||
128 | if ((NULL == (dash = strchr(s, '-'))) || | 128 | if ((NULL == (dash = strchr (s, '-'))) || |
129 | (1 != sscanf(s, "%103s-", line_port)) || | 129 | (1 != sscanf (s, "%103s-", line_port)) || |
130 | (GNUNET_OK != | 130 | (GNUNET_OK != |
131 | GNUNET_CRYPTO_eddsa_public_key_from_string(dash + 1, | 131 | GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, |
132 | strlen(dash + 1), | 132 | strlen (dash + 1), |
133 | &peer.public_key))) | 133 | &peer.public_key))) |
134 | { | 134 | { |
135 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
136 | _("Unable to parse PHONE record `%s'\n"), | 136 | _ ("Unable to parse PHONE record `%s'\n"), |
137 | s); | 137 | s); |
138 | return GNUNET_SYSERR; | 138 | return GNUNET_SYSERR; |
139 | } | 139 | } |
140 | pr = GNUNET_new(struct GNUNET_CONVERSATION_PhoneRecord); | 140 | pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord); |
141 | pr->version = htonl(1); | 141 | pr->version = htonl (1); |
142 | pr->reserved = htonl(0); | 142 | pr->reserved = htonl (0); |
143 | if (GNUNET_OK != | 143 | if (GNUNET_OK != |
144 | GNUNET_STRINGS_string_to_data(line_port, | 144 | GNUNET_STRINGS_string_to_data (line_port, |
145 | strlen(line_port), | 145 | strlen (line_port), |
146 | &pr->line_port, | 146 | &pr->line_port, |
147 | sizeof(struct GNUNET_HashCode))) | 147 | sizeof(struct GNUNET_HashCode))) |
148 | { | 148 | { |
149 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
150 | _("Unable to parse PHONE record `%s'\n"), | 150 | _ ("Unable to parse PHONE record `%s'\n"), |
151 | s); | 151 | s); |
152 | GNUNET_free(pr); | 152 | GNUNET_free (pr); |
153 | return GNUNET_SYSERR; | 153 | return GNUNET_SYSERR; |
154 | } | 154 | } |
155 | pr->peer = peer; | 155 | pr->peer = peer; |
156 | *data = pr; | 156 | *data = pr; |
157 | *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord); | 157 | *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord); |
158 | return GNUNET_OK; | 158 | return GNUNET_OK; |
159 | } | 159 | } |
160 | 160 | ||
161 | default: | 161 | default: |
162 | return GNUNET_SYSERR; | 162 | return GNUNET_SYSERR; |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
@@ -168,7 +168,8 @@ conversation_string_to_value(void *cls, | |||
168 | * Mapping of record type numbers to human-readable | 168 | * Mapping of record type numbers to human-readable |
169 | * record type names. | 169 | * record type names. |
170 | */ | 170 | */ |
171 | static struct { | 171 | static struct |
172 | { | ||
172 | const char *name; | 173 | const char *name; |
173 | uint32_t number; | 174 | uint32_t number; |
174 | } name_map[] = { | 175 | } name_map[] = { |
@@ -185,15 +186,15 @@ static struct { | |||
185 | * @return corresponding number, UINT32_MAX on error | 186 | * @return corresponding number, UINT32_MAX on error |
186 | */ | 187 | */ |
187 | static uint32_t | 188 | static uint32_t |
188 | conversation_typename_to_number(void *cls, | 189 | conversation_typename_to_number (void *cls, |
189 | const char *gns_typename) | 190 | const char *gns_typename) |
190 | { | 191 | { |
191 | unsigned int i; | 192 | unsigned int i; |
192 | 193 | ||
193 | (void)cls; | 194 | (void) cls; |
194 | i = 0; | 195 | i = 0; |
195 | while ((name_map[i].name != NULL) && | 196 | while ((name_map[i].name != NULL) && |
196 | (0 != strcasecmp(gns_typename, name_map[i].name))) | 197 | (0 != strcasecmp (gns_typename, name_map[i].name))) |
197 | i++; | 198 | i++; |
198 | return name_map[i].number; | 199 | return name_map[i].number; |
199 | } | 200 | } |
@@ -207,12 +208,12 @@ conversation_typename_to_number(void *cls, | |||
207 | * @return corresponding typestring, NULL on error | 208 | * @return corresponding typestring, NULL on error |
208 | */ | 209 | */ |
209 | static const char * | 210 | static const char * |
210 | conversation_number_to_typename(void *cls, | 211 | conversation_number_to_typename (void *cls, |
211 | uint32_t type) | 212 | uint32_t type) |
212 | { | 213 | { |
213 | unsigned int i; | 214 | unsigned int i; |
214 | 215 | ||
215 | (void)cls; | 216 | (void) cls; |
216 | i = 0; | 217 | i = 0; |
217 | while ((name_map[i].name != NULL) && | 218 | while ((name_map[i].name != NULL) && |
218 | (type != name_map[i].number)) | 219 | (type != name_map[i].number)) |
@@ -228,12 +229,12 @@ conversation_number_to_typename(void *cls, | |||
228 | * @return the exported block API | 229 | * @return the exported block API |
229 | */ | 230 | */ |
230 | void * | 231 | void * |
231 | libgnunet_plugin_gnsrecord_conversation_init(void *cls) | 232 | libgnunet_plugin_gnsrecord_conversation_init (void *cls) |
232 | { | 233 | { |
233 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 234 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
234 | 235 | ||
235 | (void)cls; | 236 | (void) cls; |
236 | api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); | 237 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); |
237 | api->value_to_string = &conversation_value_to_string; | 238 | api->value_to_string = &conversation_value_to_string; |
238 | api->string_to_value = &conversation_string_to_value; | 239 | api->string_to_value = &conversation_string_to_value; |
239 | api->typename_to_number = &conversation_typename_to_number; | 240 | api->typename_to_number = &conversation_typename_to_number; |
@@ -249,11 +250,11 @@ libgnunet_plugin_gnsrecord_conversation_init(void *cls) | |||
249 | * @return NULL | 250 | * @return NULL |
250 | */ | 251 | */ |
251 | void * | 252 | void * |
252 | libgnunet_plugin_gnsrecord_conversation_done(void *cls) | 253 | libgnunet_plugin_gnsrecord_conversation_done (void *cls) |
253 | { | 254 | { |
254 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 255 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
255 | 256 | ||
256 | GNUNET_free(api); | 257 | GNUNET_free (api); |
257 | return NULL; | 258 | return NULL; |
258 | } | 259 | } |
259 | 260 | ||
diff --git a/src/conversation/speaker.c b/src/conversation/speaker.c index 96fd42b8d..8703f269d 100644 --- a/src/conversation/speaker.c +++ b/src/conversation/speaker.c | |||
@@ -33,7 +33,8 @@ | |||
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 | { | ||
37 | /** | 38 | /** |
38 | * Our configuration. | 39 | * Our configuration. |
39 | */ | 40 | */ |
@@ -53,26 +54,25 @@ struct Speaker { | |||
53 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 54 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
54 | */ | 55 | */ |
55 | static int | 56 | static int |
56 | enable(void *cls) | 57 | enable (void *cls) |
57 | { | 58 | { |
58 | struct Speaker *spe = cls; | 59 | struct Speaker *spe = cls; |
59 | static char *playback_helper_argv[] = | 60 | static char *playback_helper_argv[] = { |
60 | { | ||
61 | "gnunet-helper-audio-playback", | 61 | "gnunet-helper-audio-playback", |
62 | NULL | 62 | NULL |
63 | }; | 63 | }; |
64 | 64 | ||
65 | spe->playback_helper = GNUNET_HELPER_start(GNUNET_NO, | 65 | spe->playback_helper = GNUNET_HELPER_start (GNUNET_NO, |
66 | "gnunet-helper-audio-playback", | 66 | "gnunet-helper-audio-playback", |
67 | playback_helper_argv, | 67 | playback_helper_argv, |
68 | NULL, | 68 | NULL, |
69 | NULL, spe); | 69 | NULL, spe); |
70 | if (NULL == spe->playback_helper) | 70 | if (NULL == spe->playback_helper) |
71 | { | 71 | { |
72 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
73 | _("Could not start playback audio helper.\n")); | 73 | _ ("Could not start playback audio helper.\n")); |
74 | return GNUNET_SYSERR; | 74 | return GNUNET_SYSERR; |
75 | } | 75 | } |
76 | return GNUNET_OK; | 76 | return GNUNET_OK; |
77 | } | 77 | } |
78 | 78 | ||
@@ -83,18 +83,18 @@ enable(void *cls) | |||
83 | * @param cls closure with the `struct Speaker` | 83 | * @param cls closure with the `struct Speaker` |
84 | */ | 84 | */ |
85 | static void | 85 | static void |
86 | disable(void *cls) | 86 | disable (void *cls) |
87 | { | 87 | { |
88 | struct Speaker *spe = cls; | 88 | struct Speaker *spe = cls; |
89 | 89 | ||
90 | if (NULL == spe->playback_helper) | 90 | if (NULL == spe->playback_helper) |
91 | { | 91 | { |
92 | GNUNET_break(0); | 92 | GNUNET_break (0); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | GNUNET_break(GNUNET_OK == | 95 | GNUNET_break (GNUNET_OK == |
96 | GNUNET_HELPER_kill(spe->playback_helper, GNUNET_NO)); | 96 | GNUNET_HELPER_kill (spe->playback_helper, GNUNET_NO)); |
97 | GNUNET_HELPER_destroy(spe->playback_helper); | 97 | GNUNET_HELPER_destroy (spe->playback_helper); |
98 | spe->playback_helper = NULL; | 98 | spe->playback_helper = NULL; |
99 | } | 99 | } |
100 | 100 | ||
@@ -105,12 +105,12 @@ disable(void *cls) | |||
105 | * @param cls closure with the `struct Speaker` | 105 | * @param cls closure with the `struct Speaker` |
106 | */ | 106 | */ |
107 | static void | 107 | static void |
108 | destroy(void *cls) | 108 | destroy (void *cls) |
109 | { | 109 | { |
110 | struct Speaker *spe = cls; | 110 | struct Speaker *spe = cls; |
111 | 111 | ||
112 | if (NULL != spe->playback_helper) | 112 | if (NULL != spe->playback_helper) |
113 | disable(spe); | 113 | disable (spe); |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
@@ -123,27 +123,27 @@ destroy(void *cls) | |||
123 | * opaque to the API but should be OPUS. | 123 | * opaque to the API but should be OPUS. |
124 | */ | 124 | */ |
125 | static void | 125 | static void |
126 | play(void *cls, | 126 | play (void *cls, |
127 | size_t data_size, | 127 | size_t data_size, |
128 | const void *data) | 128 | const void *data) |
129 | { | 129 | { |
130 | struct Speaker *spe = cls; | 130 | struct Speaker *spe = cls; |
131 | char buf[sizeof(struct AudioMessage) + data_size]; | 131 | char buf[sizeof(struct AudioMessage) + data_size]; |
132 | struct AudioMessage *am; | 132 | struct AudioMessage *am; |
133 | 133 | ||
134 | if (NULL == spe->playback_helper) | 134 | if (NULL == spe->playback_helper) |
135 | { | 135 | { |
136 | GNUNET_break(0); | 136 | GNUNET_break (0); |
137 | return; | 137 | return; |
138 | } | 138 | } |
139 | am = (struct AudioMessage *)buf; | 139 | am = (struct AudioMessage *) buf; |
140 | am->header.size = htons(sizeof(struct AudioMessage) + data_size); | 140 | am->header.size = htons (sizeof(struct AudioMessage) + data_size); |
141 | am->header.type = htons(GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); | 141 | am->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); |
142 | GNUNET_memcpy(&am[1], data, data_size); | 142 | GNUNET_memcpy (&am[1], data, data_size); |
143 | (void)GNUNET_HELPER_send(spe->playback_helper, | 143 | (void) GNUNET_HELPER_send (spe->playback_helper, |
144 | &am->header, | 144 | &am->header, |
145 | GNUNET_NO, | 145 | GNUNET_NO, |
146 | NULL, NULL); | 146 | NULL, NULL); |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
@@ -155,14 +155,15 @@ play(void *cls, | |||
155 | * @return NULL on error | 155 | * @return NULL on error |
156 | */ | 156 | */ |
157 | struct GNUNET_SPEAKER_Handle * | 157 | struct GNUNET_SPEAKER_Handle * |
158 | GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | GNUNET_SPEAKER_create_from_hardware (const struct |
159 | GNUNET_CONFIGURATION_Handle *cfg) | ||
159 | { | 160 | { |
160 | struct GNUNET_SPEAKER_Handle *speaker; | 161 | struct GNUNET_SPEAKER_Handle *speaker; |
161 | struct Speaker *spe; | 162 | struct Speaker *spe; |
162 | 163 | ||
163 | spe = GNUNET_new(struct Speaker); | 164 | spe = GNUNET_new (struct Speaker); |
164 | spe->cfg = cfg; | 165 | spe->cfg = cfg; |
165 | speaker = GNUNET_new(struct GNUNET_SPEAKER_Handle); | 166 | speaker = GNUNET_new (struct GNUNET_SPEAKER_Handle); |
166 | speaker->cls = spe; | 167 | speaker->cls = spe; |
167 | speaker->enable_speaker = &enable; | 168 | speaker->enable_speaker = &enable; |
168 | speaker->play = &play; | 169 | speaker->play = &play; |
@@ -178,10 +179,10 @@ GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cf | |||
178 | * @param speaker speaker to destroy | 179 | * @param speaker speaker to destroy |
179 | */ | 180 | */ |
180 | void | 181 | void |
181 | GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker) | 182 | GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker) |
182 | { | 183 | { |
183 | speaker->destroy_speaker(speaker->cls); | 184 | speaker->destroy_speaker (speaker->cls); |
184 | GNUNET_free(speaker); | 185 | GNUNET_free (speaker); |
185 | } | 186 | } |
186 | 187 | ||
187 | /* end of speaker.c */ | 188 | /* end of speaker.c */ |
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c index e58f89e7a..66b800304 100644 --- a/src/conversation/test_conversation_api.c +++ b/src/conversation/test_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,91 +73,91 @@ 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 | ||
@@ -176,58 +176,58 @@ static struct GNUNET_SPEAKER_Handle phone_speaker = { &enable_speaker, | |||
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 | ||
@@ -249,254 +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 | 327 | ||
328 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | 328 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: |
329 | GNUNET_break(caller == active_caller); | 329 | GNUNET_break (caller == active_caller); |
330 | active_caller = NULL; | 330 | active_caller = NULL; |
331 | if (1 == ok) | 331 | if (1 == ok) |
332 | ok = 0; | 332 | ok = 0; |
333 | GNUNET_SCHEDULER_shutdown(); | 333 | GNUNET_SCHEDULER_shutdown (); |
334 | break; | 334 | break; |
335 | 335 | ||
336 | default: | 336 | default: |
337 | fprintf(stderr, "Unexpected phone code: %d\n", code); | 337 | fprintf (stderr, "Unexpected phone code: %d\n", code); |
338 | break; | 338 | break; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | static void | 343 | static void |
344 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 344 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
345 | { | 345 | { |
346 | static enum GNUNET_CONVERSATION_CallEventCode expect = | 346 | static enum GNUNET_CONVERSATION_CallEventCode expect = |
347 | GNUNET_CONVERSATION_EC_CALL_RINGING; | 347 | GNUNET_CONVERSATION_EC_CALL_RINGING; |
348 | 348 | ||
349 | (void)cls; | 349 | (void) cls; |
350 | GNUNET_break(code == expect); | 350 | GNUNET_break (code == expect); |
351 | switch (code) | 351 | switch (code) |
352 | { | 352 | { |
353 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 353 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
354 | expect = GNUNET_CONVERSATION_EC_CALL_PICKED_UP; | 354 | expect = GNUNET_CONVERSATION_EC_CALL_PICKED_UP; |
355 | break; | 355 | break; |
356 | 356 | ||
357 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 357 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
358 | expect = -1; | 358 | expect = -1; |
359 | break; | 359 | break; |
360 | 360 | ||
361 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 361 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
362 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 362 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
363 | call = NULL; | 363 | call = NULL; |
364 | ok = 2; | 364 | ok = 2; |
365 | GNUNET_break(0); | 365 | GNUNET_break (0); |
366 | fprintf(stderr, "Unexpected call code: %d\n", code); | 366 | fprintf (stderr, "Unexpected call code: %d\n", code); |
367 | break; | 367 | break; |
368 | 368 | ||
369 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 369 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
370 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 370 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
371 | GNUNET_break(0); | 371 | GNUNET_break (0); |
372 | fprintf(stderr, "Unexpected call code: %d\n", code); | 372 | fprintf (stderr, "Unexpected call code: %d\n", code); |
373 | ok = 2; | 373 | ok = 2; |
374 | break; | 374 | break; |
375 | 375 | ||
376 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 376 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
377 | GNUNET_break(0); | 377 | GNUNET_break (0); |
378 | fprintf(stderr, "Unexpected call code: %d\n", code); | 378 | fprintf (stderr, "Unexpected call code: %d\n", code); |
379 | call = NULL; | 379 | call = NULL; |
380 | ok = 2; | 380 | ok = 2; |
381 | break; | 381 | break; |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | 385 | ||
386 | static void | 386 | static void |
387 | caller_ego_create_cont(void *cls, | 387 | caller_ego_create_cont (void *cls, |
388 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 388 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
389 | const char *emsg) | 389 | const char *emsg) |
390 | { | 390 | { |
391 | (void)cls; | 391 | (void) cls; |
392 | op = NULL; | 392 | op = NULL; |
393 | GNUNET_assert(NULL == emsg); | 393 | GNUNET_assert (NULL == emsg); |
394 | } | 394 | } |
395 | 395 | ||
396 | 396 | ||
397 | static void | 397 | static void |
398 | namestore_put_cont(void *cls, int32_t success, const char *emsg) | 398 | namestore_put_cont (void *cls, int32_t success, const char *emsg) |
399 | { | 399 | { |
400 | (void)cls; | 400 | (void) cls; |
401 | qe = NULL; | 401 | qe = NULL; |
402 | GNUNET_assert(GNUNET_YES == success); | 402 | GNUNET_assert (GNUNET_YES == success); |
403 | GNUNET_assert(NULL == emsg); | 403 | GNUNET_assert (NULL == emsg); |
404 | GNUNET_assert(NULL == op); | 404 | GNUNET_assert (NULL == op); |
405 | 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); |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 | ||
409 | static void | 409 | static void |
410 | identity_cb(void *cls, | 410 | identity_cb (void *cls, |
411 | struct GNUNET_IDENTITY_Ego *ego, | 411 | struct GNUNET_IDENTITY_Ego *ego, |
412 | void **ctx, | 412 | void **ctx, |
413 | const char *name) | 413 | const char *name) |
414 | { | 414 | { |
415 | struct GNUNET_GNSRECORD_Data rd; | 415 | struct GNUNET_GNSRECORD_Data rd; |
416 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 416 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
417 | 417 | ||
418 | (void)cls; | 418 | (void) cls; |
419 | (void)ctx; | 419 | (void) ctx; |
420 | if (NULL == name) | 420 | if (NULL == name) |
421 | return; | 421 | return; |
422 | if (NULL == ego) | 422 | if (NULL == ego) |
423 | return; | 423 | return; |
424 | if (0 == strcmp(name, "phone-ego")) | 424 | if (0 == strcmp (name, "phone-ego")) |
425 | { | 425 | { |
426 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 426 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
427 | GNUNET_asprintf(&gns_name, | 427 | GNUNET_asprintf (&gns_name, |
428 | "phone.%s", | 428 | "phone.%s", |
429 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 429 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
430 | phone = | 430 | phone = |
431 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); | 431 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); |
432 | GNUNET_assert(NULL != phone); | 432 | GNUNET_assert (NULL != phone); |
433 | memset(&rd, 0, sizeof(rd)); | 433 | memset (&rd, 0, sizeof(rd)); |
434 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); | 434 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); |
435 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 435 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
436 | rd.expiration_time = UINT64_MAX; | 436 | rd.expiration_time = UINT64_MAX; |
437 | qe = | 437 | qe = |
438 | GNUNET_NAMESTORE_records_store(ns, | 438 | GNUNET_NAMESTORE_records_store (ns, |
439 | GNUNET_IDENTITY_ego_get_private_key(ego), | 439 | GNUNET_IDENTITY_ego_get_private_key (ego), |
440 | "phone" /* GNS label */, | 440 | "phone" /* GNS label */, |
441 | 1, | 441 | 1, |
442 | &rd, | 442 | &rd, |
443 | &namestore_put_cont, | 443 | &namestore_put_cont, |
444 | NULL); | 444 | NULL); |
445 | return; | 445 | return; |
446 | } | 446 | } |
447 | if (0 == strcmp(name, "caller-ego")) | 447 | if (0 == strcmp (name, "caller-ego")) |
448 | { | 448 | { |
449 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 449 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
450 | GNUNET_asprintf(&gns_caller_id, | 450 | GNUNET_asprintf (&gns_caller_id, |
451 | "%s", | 451 | "%s", |
452 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 452 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
453 | call = GNUNET_CONVERSATION_call_start(cfg, | 453 | call = GNUNET_CONVERSATION_call_start (cfg, |
454 | ego, | 454 | ego, |
455 | gns_name, | 455 | gns_name, |
456 | &call_speaker, | 456 | &call_speaker, |
457 | &call_mic, | 457 | &call_mic, |
458 | &call_event_handler, | 458 | &call_event_handler, |
459 | NULL); | 459 | NULL); |
460 | return; | 460 | return; |
461 | } | 461 | } |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | static void | 465 | static void |
466 | phone_ego_create_cont(void *cls, | 466 | phone_ego_create_cont (void *cls, |
467 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 467 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
468 | const char *emsg) | 468 | const char *emsg) |
469 | { | 469 | { |
470 | (void)cls; | 470 | (void) cls; |
471 | op = NULL; | 471 | op = NULL; |
472 | GNUNET_assert(NULL == emsg); | 472 | GNUNET_assert (NULL == emsg); |
473 | } | 473 | } |
474 | 474 | ||
475 | 475 | ||
476 | static void | 476 | static void |
477 | run(void *cls, | 477 | run (void *cls, |
478 | const struct GNUNET_CONFIGURATION_Handle *c, | 478 | const struct GNUNET_CONFIGURATION_Handle *c, |
479 | struct GNUNET_TESTING_Peer *peer) | 479 | struct GNUNET_TESTING_Peer *peer) |
480 | { | 480 | { |
481 | (void)cls; | 481 | (void) cls; |
482 | (void)peer; | 482 | (void) peer; |
483 | cfg = c; | 483 | cfg = c; |
484 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); | 484 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
485 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); | 485 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
486 | 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); |
487 | ns = GNUNET_NAMESTORE_connect(cfg); | 487 | ns = GNUNET_NAMESTORE_connect (cfg); |
488 | } | 488 | } |
489 | 489 | ||
490 | 490 | ||
491 | int | 491 | int |
492 | main(int argc, char *argv[]) | 492 | main (int argc, char *argv[]) |
493 | { | 493 | { |
494 | (void)argc; | 494 | (void) argc; |
495 | (void)argv; | 495 | (void) argv; |
496 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api", | 496 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", |
497 | "test_conversation.conf", | 497 | "test_conversation.conf", |
498 | &run, | 498 | &run, |
499 | NULL)) | 499 | NULL)) |
500 | return 1; | 500 | return 1; |
501 | return ok; | 501 | return ok; |
502 | } | 502 | } |
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c index 2d7a56e3d..53f700890 100644 --- a/src/conversation/test_conversation_api_reject.c +++ b/src/conversation/test_conversation_api_reject.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,36 +57,36 @@ 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 | ||
@@ -98,30 +98,30 @@ static struct GNUNET_SPEAKER_Handle call_speaker = { &enable_speaker, | |||
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 | ||
@@ -137,219 +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 | 195 | ||
196 | default: | 196 | default: |
197 | fprintf(stderr, "Unexpected phone code: %d\n", code); | 197 | fprintf (stderr, "Unexpected phone code: %d\n", code); |
198 | break; | 198 | break; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | static void | 203 | static void |
204 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 204 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
205 | { | 205 | { |
206 | static enum GNUNET_CONVERSATION_CallEventCode expect = | 206 | static enum GNUNET_CONVERSATION_CallEventCode expect = |
207 | GNUNET_CONVERSATION_EC_CALL_RINGING; | 207 | GNUNET_CONVERSATION_EC_CALL_RINGING; |
208 | 208 | ||
209 | (void)cls; | 209 | (void) cls; |
210 | GNUNET_break(code == expect); | 210 | GNUNET_break (code == expect); |
211 | switch (code) | 211 | switch (code) |
212 | { | 212 | { |
213 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 213 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
214 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; | 214 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; |
215 | break; | 215 | break; |
216 | 216 | ||
217 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 217 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
218 | call = NULL; | 218 | call = NULL; |
219 | ok = 0; | 219 | ok = 0; |
220 | GNUNET_SCHEDULER_shutdown(); | 220 | GNUNET_SCHEDULER_shutdown (); |
221 | expect = -1; | 221 | expect = -1; |
222 | break; | 222 | break; |
223 | 223 | ||
224 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 224 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
225 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 225 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
226 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 226 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
227 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 227 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
228 | fprintf(stderr, "Unexpected call code: %d\n", code); | 228 | fprintf (stderr, "Unexpected call code: %d\n", code); |
229 | break; | 229 | break; |
230 | 230 | ||
231 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 231 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
232 | fprintf(stderr, "Unexpected call code: %d\n", code); | 232 | fprintf (stderr, "Unexpected call code: %d\n", code); |
233 | call = NULL; | 233 | call = NULL; |
234 | break; | 234 | break; |
235 | } | 235 | } |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | static void | 239 | static void |
240 | caller_ego_create_cont(void *cls, | 240 | caller_ego_create_cont (void *cls, |
241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
242 | const char *emsg) | 242 | const char *emsg) |
243 | { | 243 | { |
244 | (void)cls; | 244 | (void) cls; |
245 | op = NULL; | 245 | op = NULL; |
246 | GNUNET_assert(NULL == emsg); | 246 | GNUNET_assert (NULL == emsg); |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | static void | 250 | static void |
251 | namestore_put_cont(void *cls, int32_t success, const char *emsg) | 251 | namestore_put_cont (void *cls, int32_t success, const char *emsg) |
252 | { | 252 | { |
253 | (void)cls; | 253 | (void) cls; |
254 | qe = NULL; | 254 | qe = NULL; |
255 | GNUNET_assert(GNUNET_YES == success); | 255 | GNUNET_assert (GNUNET_YES == success); |
256 | GNUNET_assert(NULL == emsg); | 256 | GNUNET_assert (NULL == emsg); |
257 | GNUNET_assert(NULL == op); | 257 | GNUNET_assert (NULL == op); |
258 | 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); |
259 | } | 259 | } |
260 | 260 | ||
261 | 261 | ||
262 | static void | 262 | static void |
263 | identity_cb(void *cls, | 263 | identity_cb (void *cls, |
264 | struct GNUNET_IDENTITY_Ego *ego, | 264 | struct GNUNET_IDENTITY_Ego *ego, |
265 | void **ctx, | 265 | void **ctx, |
266 | const char *name) | 266 | const char *name) |
267 | { | 267 | { |
268 | struct GNUNET_GNSRECORD_Data rd; | 268 | struct GNUNET_GNSRECORD_Data rd; |
269 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 269 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
270 | 270 | ||
271 | (void)cls; | 271 | (void) cls; |
272 | (void)ctx; | 272 | (void) ctx; |
273 | if (NULL == name) | 273 | if (NULL == name) |
274 | return; | 274 | return; |
275 | if (NULL == ego) | 275 | if (NULL == ego) |
276 | return; | 276 | return; |
277 | if (0 == strcmp(name, "phone-ego")) | 277 | if (0 == strcmp (name, "phone-ego")) |
278 | { | 278 | { |
279 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 279 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
280 | GNUNET_asprintf(&gns_name, | 280 | GNUNET_asprintf (&gns_name, |
281 | "phone.%s", | 281 | "phone.%s", |
282 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 282 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
283 | phone = | 283 | phone = |
284 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); | 284 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); |
285 | GNUNET_assert(NULL != phone); | 285 | GNUNET_assert (NULL != phone); |
286 | memset(&rd, 0, sizeof(rd)); | 286 | memset (&rd, 0, sizeof(rd)); |
287 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); | 287 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); |
288 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 288 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
289 | rd.expiration_time = UINT64_MAX; | 289 | rd.expiration_time = UINT64_MAX; |
290 | qe = | 290 | qe = |
291 | GNUNET_NAMESTORE_records_store(ns, | 291 | GNUNET_NAMESTORE_records_store (ns, |
292 | GNUNET_IDENTITY_ego_get_private_key(ego), | 292 | GNUNET_IDENTITY_ego_get_private_key (ego), |
293 | "phone" /* GNS label */, | 293 | "phone" /* GNS label */, |
294 | 1, | 294 | 1, |
295 | &rd, | 295 | &rd, |
296 | &namestore_put_cont, | 296 | &namestore_put_cont, |
297 | NULL); | 297 | NULL); |
298 | return; | 298 | return; |
299 | } | 299 | } |
300 | if (0 == strcmp(name, "caller-ego")) | 300 | if (0 == strcmp (name, "caller-ego")) |
301 | { | 301 | { |
302 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 302 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
303 | GNUNET_asprintf(&gns_caller_id, | 303 | GNUNET_asprintf (&gns_caller_id, |
304 | "%s", | 304 | "%s", |
305 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 305 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
306 | call = GNUNET_CONVERSATION_call_start(cfg, | 306 | call = GNUNET_CONVERSATION_call_start (cfg, |
307 | ego, | 307 | ego, |
308 | gns_name, | 308 | gns_name, |
309 | &call_speaker, | 309 | &call_speaker, |
310 | &call_mic, | 310 | &call_mic, |
311 | &call_event_handler, | 311 | &call_event_handler, |
312 | NULL); | 312 | NULL); |
313 | return; | 313 | return; |
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | 317 | ||
318 | static void | 318 | static void |
319 | phone_ego_create_cont(void *cls, | 319 | phone_ego_create_cont (void *cls, |
320 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 320 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
321 | const char *emsg) | 321 | const char *emsg) |
322 | { | 322 | { |
323 | (void)cls; | 323 | (void) cls; |
324 | op = NULL; | 324 | op = NULL; |
325 | GNUNET_assert(NULL == emsg); | 325 | GNUNET_assert (NULL == emsg); |
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | static void | 329 | static void |
330 | run(void *cls, | 330 | run (void *cls, |
331 | const struct GNUNET_CONFIGURATION_Handle *c, | 331 | const struct GNUNET_CONFIGURATION_Handle *c, |
332 | struct GNUNET_TESTING_Peer *peer) | 332 | struct GNUNET_TESTING_Peer *peer) |
333 | { | 333 | { |
334 | (void)cls; | 334 | (void) cls; |
335 | (void)peer; | 335 | (void) peer; |
336 | cfg = c; | 336 | cfg = c; |
337 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); | 337 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
338 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); | 338 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
339 | 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); |
340 | ns = GNUNET_NAMESTORE_connect(cfg); | 340 | ns = GNUNET_NAMESTORE_connect (cfg); |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
344 | int | 344 | int |
345 | main(int argc, char *argv[]) | 345 | main (int argc, char *argv[]) |
346 | { | 346 | { |
347 | (void)argc; | 347 | (void) argc; |
348 | (void)argv; | 348 | (void) argv; |
349 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api", | 349 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", |
350 | "test_conversation.conf", | 350 | "test_conversation.conf", |
351 | &run, | 351 | &run, |
352 | NULL)) | 352 | NULL)) |
353 | return 1; | 353 | return 1; |
354 | return ok; | 354 | return ok; |
355 | } | 355 | } |
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c index 797563d7a..71f97b1d7 100644 --- a/src/conversation/test_conversation_api_twocalls.c +++ b/src/conversation/test_conversation_api_twocalls.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,7 +108,8 @@ 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 | { | ||
112 | GNUNET_MICROPHONE_RecordedDataCallback rdc; | 113 | GNUNET_MICROPHONE_RecordedDataCallback rdc; |
113 | 114 | ||
114 | void *rdc_cls; | 115 | void *rdc_cls; |
@@ -118,104 +119,104 @@ struct MicContext { | |||
118 | 119 | ||
119 | static struct MicContext call1_mic_ctx; | 120 | static struct MicContext call1_mic_ctx; |
120 | static struct MicContext call2_mic_ctx; | 121 | static struct MicContext call2_mic_ctx; |
121 | //static struct MicContext phone_mic_ctx; | 122 | // static struct MicContext phone_mic_ctx; |
122 | 123 | ||
123 | 124 | ||
124 | static void | 125 | static void |
125 | phone_send(void *cls) | 126 | phone_send (void *cls) |
126 | { | 127 | { |
127 | char buf[32]; | 128 | char buf[32]; |
128 | 129 | ||
129 | (void)cls; | 130 | (void) cls; |
130 | GNUNET_assert(NULL != phone_rdc); | 131 | GNUNET_assert (NULL != phone_rdc); |
131 | GNUNET_snprintf(buf, sizeof(buf), "phone"); | 132 | GNUNET_snprintf (buf, sizeof(buf), "phone"); |
132 | phone_rdc(phone_rdc_cls, strlen(buf) + 1, buf); | 133 | phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); |
133 | phone_task = GNUNET_SCHEDULER_add_delayed(FREQ, &phone_send, NULL); | 134 | phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL); |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | static void | 138 | static void |
138 | call_send(void *cls) | 139 | call_send (void *cls) |
139 | { | 140 | { |
140 | struct MicContext *mc = cls; | 141 | struct MicContext *mc = cls; |
141 | char buf[32]; | 142 | char buf[32]; |
142 | 143 | ||
143 | (void)cls; | 144 | (void) cls; |
144 | GNUNET_assert(NULL != mc->rdc); | 145 | GNUNET_assert (NULL != mc->rdc); |
145 | GNUNET_snprintf(buf, sizeof(buf), "call"); | 146 | GNUNET_snprintf (buf, sizeof(buf), "call"); |
146 | mc->rdc(mc->rdc_cls, strlen(buf) + 1, buf); | 147 | mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf); |
147 | mc->call_task = GNUNET_SCHEDULER_add_delayed(FREQ, &call_send, mc); | 148 | mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, mc); |
148 | } | 149 | } |
149 | 150 | ||
150 | 151 | ||
151 | static int | 152 | static int |
152 | enable_speaker(void *cls) | 153 | enable_speaker (void *cls) |
153 | { | 154 | { |
154 | const char *origin = CLS_STR(cls); | 155 | const char *origin = CLS_STR (cls); |
155 | 156 | ||
156 | (void)cls; | 157 | (void) cls; |
157 | LOG_DEBUG("Speaker %s enabled\n", origin); | 158 | LOG_DEBUG ("Speaker %s enabled\n", origin); |
158 | return GNUNET_OK; | 159 | return GNUNET_OK; |
159 | } | 160 | } |
160 | 161 | ||
161 | 162 | ||
162 | static void | 163 | static void |
163 | disable_speaker(void *cls) | 164 | disable_speaker (void *cls) |
164 | { | 165 | { |
165 | const char *origin = CLS_STR(cls); | 166 | const char *origin = CLS_STR (cls); |
166 | 167 | ||
167 | (void)cls; | 168 | (void) cls; |
168 | LOG_DEBUG("Speaker %s disabled\n", origin); | 169 | LOG_DEBUG ("Speaker %s disabled\n", origin); |
169 | } | 170 | } |
170 | 171 | ||
171 | 172 | ||
172 | static void | 173 | static void |
173 | play(void *cls, size_t data_size, const void *data) | 174 | play (void *cls, size_t data_size, const void *data) |
174 | { | 175 | { |
175 | static unsigned int phone_i; | 176 | static unsigned int phone_i; |
176 | static unsigned int call_i; | 177 | static unsigned int call_i; |
177 | 178 | ||
178 | (void)cls; | 179 | (void) cls; |
179 | if (0 == strncmp("call", data, data_size)) | 180 | if (0 == strncmp ("call", data, data_size)) |
180 | call_i++; | 181 | call_i++; |
181 | else if (0 == strncmp("phone", data, data_size)) | 182 | else if (0 == strncmp ("phone", data, data_size)) |
182 | phone_i++; | 183 | phone_i++; |
183 | else | 184 | else |
184 | { | 185 | { |
185 | LOG_DEBUG("Received %u bytes of unexpected data `%.*s'\n", | 186 | LOG_DEBUG ("Received %u bytes of unexpected data `%.*s'\n", |
186 | (unsigned int)data_size, | 187 | (unsigned int) data_size, |
187 | (int)data_size, | 188 | (int) data_size, |
188 | (const char *)data); | 189 | (const char *) data); |
189 | } | 190 | } |
190 | 191 | ||
191 | if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls)) | 192 | if ((20 < call_i) && (20 < phone_i) && (CALLER2 == cls)) |
192 | { | 193 | { |
193 | /* time to hang up ... */ | 194 | /* time to hang up ... */ |
194 | GNUNET_CONVERSATION_call_stop(call2); | 195 | GNUNET_CONVERSATION_call_stop (call2); |
195 | call2 = NULL; | 196 | call2 = NULL; |
196 | /* reset counters */ | 197 | /* reset counters */ |
197 | call_i = 0; | 198 | call_i = 0; |
198 | phone_i = 0; | 199 | phone_i = 0; |
199 | call2_finished = GNUNET_YES; | 200 | call2_finished = GNUNET_YES; |
200 | } | 201 | } |
201 | if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls)) | 202 | if ((20 < call_i) && (20 < phone_i) && (CALLER1 == cls)) |
202 | { | 203 | { |
203 | /* time to hang up ... */ | 204 | /* time to hang up ... */ |
204 | GNUNET_CONVERSATION_call_stop(call1); | 205 | GNUNET_CONVERSATION_call_stop (call1); |
205 | call1 = NULL; | 206 | call1 = NULL; |
206 | call_i = 0; | 207 | call_i = 0; |
207 | phone_i = 0; | 208 | phone_i = 0; |
208 | call1_finished = GNUNET_YES; | 209 | call1_finished = GNUNET_YES; |
209 | } | 210 | } |
210 | } | 211 | } |
211 | 212 | ||
212 | 213 | ||
213 | static void | 214 | static void |
214 | destroy_speaker(void *cls) | 215 | destroy_speaker (void *cls) |
215 | { | 216 | { |
216 | const char *origin = CLS_STR(cls); | 217 | const char *origin = CLS_STR (cls); |
217 | 218 | ||
218 | LOG_DEBUG("Speaker %s destroyed\n", origin); | 219 | LOG_DEBUG ("Speaker %s destroyed\n", origin); |
219 | } | 220 | } |
220 | 221 | ||
221 | 222 | ||
@@ -241,60 +242,60 @@ static struct GNUNET_SPEAKER_Handle phone_speaker = { &enable_speaker, | |||
241 | 242 | ||
242 | 243 | ||
243 | static int | 244 | static int |
244 | enable_mic(void *cls, | 245 | enable_mic (void *cls, |
245 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | 246 | GNUNET_MICROPHONE_RecordedDataCallback rdc, |
246 | void *rdc_cls) | 247 | void *rdc_cls) |
247 | { | 248 | { |
248 | const char *origin = CLS_STR(cls); | 249 | const char *origin = CLS_STR (cls); |
249 | struct MicContext *mc; | 250 | struct MicContext *mc; |
250 | 251 | ||
251 | LOG_DEBUG("Mic %s enabled\n", origin); | 252 | LOG_DEBUG ("Mic %s enabled\n", origin); |
252 | if (PHONE0 == cls) | 253 | if (PHONE0 == cls) |
253 | { | 254 | { |
254 | phone_rdc = rdc; | 255 | phone_rdc = rdc; |
255 | phone_rdc_cls = rdc_cls; | 256 | phone_rdc_cls = rdc_cls; |
256 | GNUNET_break(NULL == phone_task); | 257 | GNUNET_break (NULL == phone_task); |
257 | phone_task = GNUNET_SCHEDULER_add_now(&phone_send, NULL); | 258 | phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL); |
258 | return GNUNET_OK; | 259 | return GNUNET_OK; |
259 | } | 260 | } |
260 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; | 261 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; |
261 | mc->rdc = rdc; | 262 | mc->rdc = rdc; |
262 | mc->rdc_cls = rdc_cls; | 263 | mc->rdc_cls = rdc_cls; |
263 | GNUNET_break(NULL == mc->call_task); | 264 | GNUNET_break (NULL == mc->call_task); |
264 | mc->call_task = GNUNET_SCHEDULER_add_now(&call_send, mc); | 265 | mc->call_task = GNUNET_SCHEDULER_add_now (&call_send, mc); |
265 | return GNUNET_OK; | 266 | return GNUNET_OK; |
266 | } | 267 | } |
267 | 268 | ||
268 | 269 | ||
269 | static void | 270 | static void |
270 | disable_mic(void *cls) | 271 | disable_mic (void *cls) |
271 | { | 272 | { |
272 | const char *origin = CLS_STR(cls); | 273 | const char *origin = CLS_STR (cls); |
273 | struct MicContext *mc; | 274 | struct MicContext *mc; |
274 | 275 | ||
275 | LOG_DEBUG("Mic %s disabled\n", origin); | 276 | LOG_DEBUG ("Mic %s disabled\n", origin); |
276 | if (PHONE0 == cls) | 277 | if (PHONE0 == cls) |
277 | { | 278 | { |
278 | phone_rdc = NULL; | 279 | phone_rdc = NULL; |
279 | phone_rdc_cls = NULL; | 280 | phone_rdc_cls = NULL; |
280 | GNUNET_SCHEDULER_cancel(phone_task); | 281 | GNUNET_SCHEDULER_cancel (phone_task); |
281 | phone_task = NULL; | 282 | phone_task = NULL; |
282 | return; | 283 | return; |
283 | } | 284 | } |
284 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; | 285 | mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; |
285 | mc->rdc = NULL; | 286 | mc->rdc = NULL; |
286 | mc->rdc_cls = NULL; | 287 | mc->rdc_cls = NULL; |
287 | GNUNET_SCHEDULER_cancel(mc->call_task); | 288 | GNUNET_SCHEDULER_cancel (mc->call_task); |
288 | mc->call_task = NULL; | 289 | mc->call_task = NULL; |
289 | } | 290 | } |
290 | 291 | ||
291 | 292 | ||
292 | static void | 293 | static void |
293 | destroy_mic(void *cls) | 294 | destroy_mic (void *cls) |
294 | { | 295 | { |
295 | const char *origin = CLS_STR(cls); | 296 | const char *origin = CLS_STR (cls); |
296 | 297 | ||
297 | LOG_DEBUG("Mic %s destroyed\n", origin); | 298 | LOG_DEBUG ("Mic %s destroyed\n", origin); |
298 | } | 299 | } |
299 | 300 | ||
300 | 301 | ||
@@ -322,12 +323,12 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = { &enable_mic, | |||
322 | * @param cls closure | 323 | * @param cls closure |
323 | */ | 324 | */ |
324 | static void | 325 | static void |
325 | end_test(void *cls) | 326 | end_test (void *cls) |
326 | { | 327 | { |
327 | (void)cls; | 328 | (void) cls; |
328 | timeout_task = NULL; | 329 | timeout_task = NULL; |
329 | fprintf(stderr, "Timeout!\n"); | 330 | fprintf (stderr, "Timeout!\n"); |
330 | GNUNET_SCHEDULER_shutdown(); | 331 | GNUNET_SCHEDULER_shutdown (); |
331 | } | 332 | } |
332 | 333 | ||
333 | 334 | ||
@@ -337,295 +338,295 @@ end_test(void *cls) | |||
337 | * @param cls closure | 338 | * @param cls closure |
338 | */ | 339 | */ |
339 | static void | 340 | static void |
340 | do_shutdown(void *cls) | 341 | do_shutdown (void *cls) |
341 | { | 342 | { |
342 | (void)cls; | 343 | (void) cls; |
343 | if (NULL != timeout_task) | 344 | if (NULL != timeout_task) |
344 | { | 345 | { |
345 | GNUNET_SCHEDULER_cancel(timeout_task); | 346 | GNUNET_SCHEDULER_cancel (timeout_task); |
346 | timeout_task = NULL; | 347 | timeout_task = NULL; |
347 | } | 348 | } |
348 | if (NULL != op) | 349 | if (NULL != op) |
349 | { | 350 | { |
350 | GNUNET_IDENTITY_cancel(op); | 351 | GNUNET_IDENTITY_cancel (op); |
351 | op = NULL; | 352 | op = NULL; |
352 | } | 353 | } |
353 | if (NULL != call1) | 354 | if (NULL != call1) |
354 | { | 355 | { |
355 | GNUNET_CONVERSATION_call_stop(call1); | 356 | GNUNET_CONVERSATION_call_stop (call1); |
356 | call1 = NULL; | 357 | call1 = NULL; |
357 | } | 358 | } |
358 | if (NULL != call2) | 359 | if (NULL != call2) |
359 | { | 360 | { |
360 | GNUNET_CONVERSATION_call_stop(call2); | 361 | GNUNET_CONVERSATION_call_stop (call2); |
361 | call2 = NULL; | 362 | call2 = NULL; |
362 | } | 363 | } |
363 | if (NULL != phone) | 364 | if (NULL != phone) |
364 | { | 365 | { |
365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | 366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); |
366 | GNUNET_CONVERSATION_phone_destroy(phone); | 367 | GNUNET_CONVERSATION_phone_destroy (phone); |
367 | phone = NULL; | 368 | phone = NULL; |
368 | } | 369 | } |
369 | if (NULL != id) | 370 | if (NULL != id) |
370 | { | 371 | { |
371 | GNUNET_IDENTITY_disconnect(id); | 372 | GNUNET_IDENTITY_disconnect (id); |
372 | id = NULL; | 373 | id = NULL; |
373 | } | 374 | } |
374 | if (NULL != qe) | 375 | if (NULL != qe) |
375 | { | 376 | { |
376 | GNUNET_NAMESTORE_cancel(qe); | 377 | GNUNET_NAMESTORE_cancel (qe); |
377 | qe = NULL; | 378 | qe = NULL; |
378 | } | 379 | } |
379 | if (NULL != ns) | 380 | if (NULL != ns) |
380 | { | 381 | { |
381 | GNUNET_NAMESTORE_disconnect(ns); | 382 | GNUNET_NAMESTORE_disconnect (ns); |
382 | ns = NULL; | 383 | ns = NULL; |
383 | } | 384 | } |
384 | } | 385 | } |
385 | 386 | ||
386 | 387 | ||
387 | static void | 388 | static void |
388 | caller_event_handler(void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) | 389 | caller_event_handler (void *cls, enum GNUNET_CONVERSATION_CallerEventCode code) |
389 | { | 390 | { |
390 | (void)cls; | 391 | (void) cls; |
391 | switch (code) | 392 | switch (code) |
392 | { | 393 | { |
393 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: | 394 | case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: |
394 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: | 395 | case GNUNET_CONVERSATION_EC_CALLER_RESUME: |
395 | LOG(GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code); | 396 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code); |
396 | break; | 397 | break; |
397 | } | 398 | } |
398 | } | 399 | } |
399 | 400 | ||
400 | 401 | ||
401 | static void | 402 | static void |
402 | phone_event_handler(void *cls, | 403 | phone_event_handler (void *cls, |
403 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 404 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
404 | struct GNUNET_CONVERSATION_Caller *caller, | 405 | struct GNUNET_CONVERSATION_Caller *caller, |
405 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 406 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) |
406 | { | 407 | { |
407 | const char *cid; | 408 | const char *cid; |
408 | 409 | ||
409 | (void)cls; | 410 | (void) cls; |
410 | (void)caller_id; | 411 | (void) caller_id; |
411 | 412 | ||
412 | switch (code) | 413 | switch (code) |
414 | { | ||
415 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
416 | if (NULL == active_caller1) | ||
417 | { | ||
418 | active_caller1 = caller; | ||
419 | cid = "caller1"; | ||
420 | GNUNET_CONVERSATION_caller_pick_up (caller, | ||
421 | &caller_event_handler, | ||
422 | (void *) cid, | ||
423 | &phone_speaker, | ||
424 | &phone_mic); | ||
425 | } | ||
426 | else | ||
427 | { | ||
428 | GNUNET_CONVERSATION_caller_suspend (active_caller1); | ||
429 | active_caller2 = caller; | ||
430 | cid = "caller2"; | ||
431 | GNUNET_CONVERSATION_caller_pick_up (caller, | ||
432 | &caller_event_handler, | ||
433 | (void *) cid, | ||
434 | &phone_speaker, | ||
435 | &phone_mic); | ||
436 | } | ||
437 | break; | ||
438 | |||
439 | case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP: | ||
440 | if (caller == active_caller2) | ||
441 | { | ||
442 | active_caller2 = NULL; | ||
443 | GNUNET_CONVERSATION_caller_resume (active_caller1, | ||
444 | &phone_speaker, | ||
445 | &phone_mic); | ||
446 | } | ||
447 | else if (caller == active_caller1) | ||
413 | { | 448 | { |
414 | case GNUNET_CONVERSATION_EC_PHONE_RING: | 449 | active_caller1 = NULL; |
415 | if (NULL == active_caller1) | 450 | GNUNET_break (NULL == active_caller2); |
416 | { | 451 | GNUNET_SCHEDULER_shutdown (); |
417 | active_caller1 = caller; | ||
418 | cid = "caller1"; | ||
419 | GNUNET_CONVERSATION_caller_pick_up(caller, | ||
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; | ||
457 | } | 452 | } |
453 | break; | ||
454 | |||
455 | default: | ||
456 | LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code); | ||
457 | break; | ||
458 | } | ||
458 | } | 459 | } |
459 | 460 | ||
460 | 461 | ||
461 | static void | 462 | static void |
462 | call_event_handler(void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | 463 | call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) |
463 | { | 464 | { |
464 | const char *cid = cls; | 465 | const char *cid = cls; |
465 | 466 | ||
466 | switch (code) | 467 | switch (code) |
467 | { | 468 | { |
468 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | 469 | case GNUNET_CONVERSATION_EC_CALL_RINGING: |
469 | break; | 470 | break; |
470 | 471 | ||
471 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | 472 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: |
472 | LOG_DEBUG("Call %s picked\n", cid); | 473 | LOG_DEBUG ("Call %s picked\n", cid); |
473 | break; | 474 | break; |
474 | 475 | ||
475 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | 476 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: |
476 | LOG_DEBUG("Call %s GNS lookup failed \n", cid); | 477 | LOG_DEBUG ("Call %s GNS lookup failed \n", cid); |
477 | break; | 478 | break; |
478 | 479 | ||
479 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | 480 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: |
480 | LOG_DEBUG("Call %s hungup\n", cid); | 481 | LOG_DEBUG ("Call %s hungup\n", cid); |
481 | if (0 == strcmp(cid, "call1")) | 482 | if (0 == strcmp (cid, "call1")) |
482 | call1 = NULL; | 483 | call1 = NULL; |
483 | else | 484 | else |
484 | call2 = NULL; | 485 | call2 = NULL; |
485 | break; | 486 | break; |
486 | 487 | ||
487 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | 488 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: |
488 | LOG_DEBUG("Call %s suspended\n", cid); | 489 | LOG_DEBUG ("Call %s suspended\n", cid); |
489 | break; | 490 | break; |
490 | 491 | ||
491 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | 492 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: |
492 | LOG_DEBUG("Call %s resumed\n", cid); | 493 | LOG_DEBUG ("Call %s resumed\n", cid); |
493 | break; | 494 | break; |
494 | 495 | ||
495 | case GNUNET_CONVERSATION_EC_CALL_ERROR: | 496 | case GNUNET_CONVERSATION_EC_CALL_ERROR: |
496 | GNUNET_break(0); | 497 | GNUNET_break (0); |
497 | if (0 == strcmp(cid, "call1")) | 498 | if (0 == strcmp (cid, "call1")) |
498 | call1 = NULL; | 499 | call1 = NULL; |
499 | else | 500 | else |
500 | call2 = NULL; | 501 | call2 = NULL; |
501 | GNUNET_SCHEDULER_shutdown(); | 502 | GNUNET_SCHEDULER_shutdown (); |
502 | break; | 503 | break; |
503 | } | 504 | } |
504 | } | 505 | } |
505 | 506 | ||
506 | 507 | ||
507 | static void | 508 | static void |
508 | caller_ego_create_cont(void *cls, | 509 | caller_ego_create_cont (void *cls, |
509 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 510 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
510 | const char *emsg) | 511 | const char *emsg) |
511 | { | 512 | { |
512 | (void)cls; | 513 | (void) cls; |
513 | op = NULL; | 514 | op = NULL; |
514 | GNUNET_assert(NULL == emsg); | 515 | GNUNET_assert (NULL == emsg); |
515 | } | 516 | } |
516 | 517 | ||
517 | 518 | ||
518 | static void | 519 | static void |
519 | namestore_put_cont(void *cls, int32_t success, const char *emsg) | 520 | namestore_put_cont (void *cls, int32_t success, const char *emsg) |
520 | { | 521 | { |
521 | (void)cls; | 522 | (void) cls; |
522 | qe = NULL; | 523 | qe = NULL; |
523 | GNUNET_assert(GNUNET_YES == success); | 524 | GNUNET_assert (GNUNET_YES == success); |
524 | GNUNET_assert(NULL == emsg); | 525 | GNUNET_assert (NULL == emsg); |
525 | GNUNET_assert(NULL == op); | 526 | GNUNET_assert (NULL == op); |
526 | op = GNUNET_IDENTITY_create(id, "caller-ego", &caller_ego_create_cont, NULL); | 527 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); |
527 | } | 528 | } |
528 | 529 | ||
529 | 530 | ||
530 | static void | 531 | static void |
531 | identity_cb(void *cls, | 532 | identity_cb (void *cls, |
532 | struct GNUNET_IDENTITY_Ego *ego, | 533 | struct GNUNET_IDENTITY_Ego *ego, |
533 | void **ctx, | 534 | void **ctx, |
534 | const char *name) | 535 | const char *name) |
535 | { | 536 | { |
536 | struct GNUNET_GNSRECORD_Data rd; | 537 | struct GNUNET_GNSRECORD_Data rd; |
537 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 538 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
538 | 539 | ||
539 | (void)cls; | 540 | (void) cls; |
540 | (void)ctx; | 541 | (void) ctx; |
541 | if (NULL == name) | 542 | if (NULL == name) |
542 | return; | 543 | return; |
543 | if (NULL == ego) | 544 | if (NULL == ego) |
544 | return; | 545 | return; |
545 | if (0 == strcmp(name, "phone-ego")) | 546 | if (0 == strcmp (name, "phone-ego")) |
546 | { | 547 | { |
547 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 548 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
548 | GNUNET_asprintf(&gns_name, | 549 | GNUNET_asprintf (&gns_name, |
549 | "phone.%s", | 550 | "phone.%s", |
550 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 551 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
551 | phone = | 552 | phone = |
552 | GNUNET_CONVERSATION_phone_create(cfg, ego, &phone_event_handler, NULL); | 553 | GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); |
553 | GNUNET_assert(NULL != phone); | 554 | GNUNET_assert (NULL != phone); |
554 | memset(&rd, 0, sizeof(rd)); | 555 | memset (&rd, 0, sizeof(rd)); |
555 | GNUNET_CONVERSATION_phone_get_record(phone, &rd); | 556 | GNUNET_CONVERSATION_phone_get_record (phone, &rd); |
556 | GNUNET_assert(rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | 557 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); |
557 | rd.expiration_time = UINT64_MAX; | 558 | rd.expiration_time = UINT64_MAX; |
558 | qe = | 559 | qe = |
559 | GNUNET_NAMESTORE_records_store(ns, | 560 | GNUNET_NAMESTORE_records_store (ns, |
560 | GNUNET_IDENTITY_ego_get_private_key(ego), | 561 | GNUNET_IDENTITY_ego_get_private_key (ego), |
561 | "phone" /* GNS label */, | 562 | "phone" /* GNS label */, |
562 | 1, | 563 | 1, |
563 | &rd, | 564 | &rd, |
564 | &namestore_put_cont, | 565 | &namestore_put_cont, |
565 | NULL); | 566 | NULL); |
566 | return; | 567 | return; |
567 | } | 568 | } |
568 | if (0 == strcmp(name, "caller-ego")) | 569 | if (0 == strcmp (name, "caller-ego")) |
569 | { | 570 | { |
570 | GNUNET_IDENTITY_ego_get_public_key(ego, &pub); | 571 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); |
571 | GNUNET_asprintf(&gns_caller_id, | 572 | GNUNET_asprintf (&gns_caller_id, |
572 | "%s", | 573 | "%s", |
573 | GNUNET_GNSRECORD_pkey_to_zkey(&pub)); | 574 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); |
574 | call1 = GNUNET_CONVERSATION_call_start(cfg, | 575 | call1 = GNUNET_CONVERSATION_call_start (cfg, |
575 | ego, | 576 | ego, |
576 | gns_name, | 577 | gns_name, |
577 | &call1_speaker, | 578 | &call1_speaker, |
578 | &call1_mic, | 579 | &call1_mic, |
579 | &call_event_handler, | 580 | &call_event_handler, |
580 | (void *)"call1"); | 581 | (void *) "call1"); |
581 | call2 = GNUNET_CONVERSATION_call_start(cfg, | 582 | call2 = GNUNET_CONVERSATION_call_start (cfg, |
582 | ego, | 583 | ego, |
583 | gns_name, | 584 | gns_name, |
584 | &call2_speaker, | 585 | &call2_speaker, |
585 | &call2_mic, | 586 | &call2_mic, |
586 | &call_event_handler, | 587 | &call_event_handler, |
587 | (void *)"call2"); | 588 | (void *) "call2"); |
588 | return; | 589 | return; |
589 | } | 590 | } |
590 | } | 591 | } |
591 | 592 | ||
592 | 593 | ||
593 | static void | 594 | static void |
594 | phone_ego_create_cont(void *cls, | 595 | phone_ego_create_cont (void *cls, |
595 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 596 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
596 | const char *emsg) | 597 | const char *emsg) |
597 | { | 598 | { |
598 | (void)cls; | 599 | (void) cls; |
599 | op = NULL; | 600 | op = NULL; |
600 | GNUNET_assert(NULL == emsg); | 601 | GNUNET_assert (NULL == emsg); |
601 | } | 602 | } |
602 | 603 | ||
603 | 604 | ||
604 | static void | 605 | static void |
605 | run(void *cls, | 606 | run (void *cls, |
606 | const struct GNUNET_CONFIGURATION_Handle *c, | 607 | const struct GNUNET_CONFIGURATION_Handle *c, |
607 | struct GNUNET_TESTING_Peer *peer) | 608 | struct GNUNET_TESTING_Peer *peer) |
608 | { | 609 | { |
609 | (void)cls; | 610 | (void) cls; |
610 | (void)peer; | 611 | (void) peer; |
611 | cfg = c; | 612 | cfg = c; |
612 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_test, NULL); | 613 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, NULL); |
613 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 614 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
614 | id = GNUNET_IDENTITY_connect(cfg, &identity_cb, NULL); | 615 | id = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); |
615 | op = GNUNET_IDENTITY_create(id, "phone-ego", &phone_ego_create_cont, NULL); | 616 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); |
616 | ns = GNUNET_NAMESTORE_connect(cfg); | 617 | ns = GNUNET_NAMESTORE_connect (cfg); |
617 | } | 618 | } |
618 | 619 | ||
619 | 620 | ||
620 | int | 621 | int |
621 | main(int argc, char *argv[]) | 622 | main (int argc, char *argv[]) |
622 | { | 623 | { |
623 | (void)argc; | 624 | (void) argc; |
624 | (void)argv; | 625 | (void) argv; |
625 | if (0 != GNUNET_TESTING_peer_run("test_conversation_api_twocalls", | 626 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls", |
626 | "test_conversation.conf", | 627 | "test_conversation.conf", |
627 | &run, | 628 | &run, |
628 | NULL)) | 629 | NULL)) |
629 | return 1; | 630 | return 1; |
630 | if (call1_finished && call2_finished) | 631 | if (call1_finished && call2_finished) |
631 | return 0; | 632 | return 0; |