summaryrefslogtreecommitdiff
path: root/toxmsi/phone.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-10-17 08:09:06 -0400
committerirungentoo <irungentoo@gmail.com>2013-10-17 08:09:06 -0400
commitbdbf4a367318d4e6b37975627fe86c7e79449ee4 (patch)
tree81eb1cfae9c3fb44b49a53c25b747ed92b044403 /toxmsi/phone.c
parent6391208ab33b75d324201eb567e7a4ae2e28b838 (diff)
Fixed building on windows.
Diffstat (limited to 'toxmsi/phone.c')
-rw-r--r--toxmsi/phone.c375
1 files changed, 199 insertions, 176 deletions
diff --git a/toxmsi/phone.c b/toxmsi/phone.c
index 010f26aa..f14d0323 100644
--- a/toxmsi/phone.c
+++ b/toxmsi/phone.c
@@ -14,13 +14,13 @@
14#include <stdio.h> 14#include <stdio.h>
15#include <string.h> 15#include <string.h>
16#include <stdlib.h> 16#include <stdlib.h>
17#include <termios.h> 17/* #include <termios.h> Can this be removed? */
18#include <pthread.h> 18#include <pthread.h>
19#include "AV_codec.h" 19#include "AV_codec.h"
20 20
21 21
22 22
23void INFO (const char* _format, ...) 23void INFO (const char *_format, ...)
24{ 24{
25 printf("\r[!] "); 25 printf("\r[!] ");
26 va_list _arg; 26 va_list _arg;
@@ -31,13 +31,13 @@ void INFO (const char* _format, ...)
31 fflush(stdout); 31 fflush(stdout);
32} 32}
33 33
34int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) 34int rtp_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
35{ 35{
36 phone_t* _phone = _object; 36 phone_t *_phone = _object;
37 rtp_msg_t* _msg; 37 rtp_msg_t *_msg;
38 uint8_t _payload_id; 38 uint8_t _payload_id;
39 39
40 if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ){ 40 if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ) {
41 41
42 _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */ 42 _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */
43 43
@@ -55,10 +55,10 @@ int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
55 55
56 return SUCCESS; 56 return SUCCESS;
57} 57}
58int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) 58int msi_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
59{ 59{
60 msi_session_t* _session = _object; 60 msi_session_t *_session = _object;
61 msi_msg_t* _msg; 61 msi_msg_t *_msg;
62 62
63 _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */ 63 _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */
64 64
@@ -75,9 +75,9 @@ int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
75 return SUCCESS; 75 return SUCCESS;
76} 76}
77 77
78void* phone_receivepacket ( void* _phone_p ) 78void *phone_receivepacket ( void *_phone_p )
79{ 79{
80 phone_t* _phone = _phone_p; 80 phone_t *_phone = _phone_p;
81 81
82 82
83 networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi); 83 networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi);
@@ -94,31 +94,31 @@ void* phone_receivepacket ( void* _phone_p )
94 94
95/* Media transport callback */ 95/* Media transport callback */
96typedef struct hmtc_args_s { 96typedef struct hmtc_args_s {
97 rtp_session_t** _rtp_audio; 97 rtp_session_t **_rtp_audio;
98 rtp_session_t** _rtp_video; 98 rtp_session_t **_rtp_video;
99 call_type* _local_type_call; 99 call_type *_local_type_call;
100 call_state* _this_call; 100 call_state *_this_call;
101 void *_core_handler; 101 void *_core_handler;
102} hmtc_args_t; 102} hmtc_args_t;
103 103
104void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) 104void *phone_handle_media_transport_poll ( void *_hmtc_args_p )
105{ 105{
106 rtp_msg_t* _audio_msg, * _video_msg; 106 rtp_msg_t *_audio_msg, * _video_msg;
107 107
108 hmtc_args_t* _hmtc_args = _hmtc_args_p; 108 hmtc_args_t *_hmtc_args = _hmtc_args_p;
109 109
110 rtp_session_t* _rtp_audio = *_hmtc_args->_rtp_audio; 110 rtp_session_t *_rtp_audio = *_hmtc_args->_rtp_audio;
111 rtp_session_t* _rtp_video = *_hmtc_args->_rtp_video; 111 rtp_session_t *_rtp_video = *_hmtc_args->_rtp_video;
112 112
113 call_type* _type = _hmtc_args->_local_type_call; 113 call_type *_type = _hmtc_args->_local_type_call;
114 void* _core_handler = _hmtc_args->_core_handler; 114 void *_core_handler = _hmtc_args->_core_handler;
115 115
116 116
117 call_state* _this_call = _hmtc_args->_this_call; 117 call_state *_this_call = _hmtc_args->_this_call;
118 118
119 while ( *_this_call == call_active ) { 119 while ( *_this_call == call_active ) {
120 120
121 // THREADLOCK() 121 // THREADLOCK()
122 122
123 _audio_msg = rtp_recv_msg ( _rtp_audio ); 123 _audio_msg = rtp_recv_msg ( _rtp_audio );
124 _video_msg = rtp_recv_msg ( _rtp_video ); 124 _video_msg = rtp_recv_msg ( _rtp_video );
@@ -139,14 +139,15 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
139 rtp_free_msg ( _rtp_video, _video_msg ); 139 rtp_free_msg ( _rtp_video, _video_msg );
140 _video_msg = NULL; 140 _video_msg = NULL;
141 } 141 }
142
142 /* -------------------- */ 143 /* -------------------- */
143 144
144 _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t*)"audio\0", 6 ) ; 145 _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t *)"audio\0", 6 ) ;
145 rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler ); 146 rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler );
146 _audio_msg = NULL; 147 _audio_msg = NULL;
147 148
148 if ( *_type == type_video ){ /* if local call send video */ 149 if ( *_type == type_video ) { /* if local call send video */
149 _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t*)"video\0", 6 ) ; 150 _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t *)"video\0", 6 ) ;
150 rtp_send_msg ( _rtp_video, _video_msg, _core_handler ); 151 rtp_send_msg ( _rtp_video, _video_msg, _core_handler );
151 _video_msg = NULL; 152 _video_msg = NULL;
152 } 153 }
@@ -159,7 +160,7 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
159 160
160 //THREADLOCK() 161 //THREADLOCK()
161 162
162 if ( _audio_msg ){ 163 if ( _audio_msg ) {
163 rtp_free_msg(_rtp_audio, _audio_msg); 164 rtp_free_msg(_rtp_audio, _audio_msg);
164 } 165 }
165 166
@@ -185,9 +186,9 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
185 pthread_exit ( NULL ); 186 pthread_exit ( NULL );
186} 187}
187 188
188pthread_t phone_startmedia_loop ( phone_t* _phone ) 189pthread_t phone_startmedia_loop ( phone_t *_phone )
189{ 190{
190 if ( !_phone ){ 191 if ( !_phone ) {
191 return 0; 192 return 0;
192 } 193 }
193 194
@@ -207,10 +208,10 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
207 rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 ); 208 rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 );
208 rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id ); 209 rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id );
209 rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8); 210 rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8);
210
211
212 211
213 hmtc_args_t* rtp_targs = calloc(sizeof(hmtc_args_t),1); 212
213
214 hmtc_args_t *rtp_targs = calloc(sizeof(hmtc_args_t), 1);
214 215
215 216
216 rtp_targs->_rtp_audio = &_phone->_rtp_audio; 217 rtp_targs->_rtp_audio = &_phone->_rtp_audio;
@@ -220,26 +221,29 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
220 rtp_targs->_core_handler = _phone->_networking; 221 rtp_targs->_core_handler = _phone->_networking;
221 222
222 codec_state *cs; 223 codec_state *cs;
223 cs=_phone->cs; 224 cs = _phone->cs;
224 //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs ); 225 //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs );
225 cs->_rtp_audio=_phone->_rtp_audio; 226 cs->_rtp_audio = _phone->_rtp_audio;
226 cs->_rtp_video=_phone->_rtp_video; 227 cs->_rtp_video = _phone->_rtp_video;
227 cs->_networking=_phone->_networking; 228 cs->_networking = _phone->_networking;
228 cs->socket=_phone->_tox_sock; 229 cs->socket = _phone->_tox_sock;
229 cs->quit = 0; 230 cs->quit = 0;
230 231
231 printf("support: %d %d\n",cs->support_send_audio,cs->support_send_video); 232 printf("support: %d %d\n", cs->support_send_audio, cs->support_send_video);
232 233
233 if(cs->support_send_audio&&cs->support_send_video) /* quick fix */ 234 if (cs->support_send_audio && cs->support_send_video) /* quick fix */
234 pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs); 235 pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs);
235 if(cs->support_receive_audio) 236
236 pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs); 237 if (cs->support_receive_audio)
237 238 pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs);
238 if(cs->support_send_video) 239
239 pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs); 240 if (cs->support_send_video)
240 if(cs->support_receive_video) 241 pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs);
241 pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs); 242
242// 243 if (cs->support_receive_video)
244 pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs);
245
246//
243 return 1; 247 return 1;
244 248
245 249
@@ -252,20 +256,21 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
252 256
253MCBTYPE callback_recv_invite ( MCBARGS ) 257MCBTYPE callback_recv_invite ( MCBARGS )
254{ 258{
255 const char* _call_type; 259 const char *_call_type;
256 260
257 msi_session_t* _msi = _arg; 261 msi_session_t *_msi = _arg;
258 262
259 /* Get the last one */ 263 /* Get the last one */
260 call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1]; 264 call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1];
261 265
262 switch ( _type ){ 266 switch ( _type ) {
263 case type_audio: 267 case type_audio:
264 _call_type = "audio"; 268 _call_type = "audio";
265 break; 269 break;
266 case type_video: 270
267 _call_type = "video"; 271 case type_video:
268 break; 272 _call_type = "video";
273 break;
269 } 274 }
270 275
271 INFO( "Incoming %s call!", _call_type ); 276 INFO( "Incoming %s call!", _call_type );
@@ -281,8 +286,9 @@ MCBTYPE callback_recv_ringing ( MCBARGS )
281} 286}
282MCBTYPE callback_recv_starting ( MCBARGS ) 287MCBTYPE callback_recv_starting ( MCBARGS )
283{ 288{
284 msi_session_t* _session = _arg; 289 msi_session_t *_session = _arg;
285 if ( !phone_startmedia_loop(_session->_agent_handler) ){ 290
291 if ( !phone_startmedia_loop(_session->_agent_handler) ) {
286 INFO("Starting call failed!"); 292 INFO("Starting call failed!");
287 } else { 293 } else {
288 INFO ("Call started! ( press h to hangup )"); 294 INFO ("Call started! ( press h to hangup )");
@@ -290,34 +296,40 @@ MCBTYPE callback_recv_starting ( MCBARGS )
290} 296}
291MCBTYPE callback_recv_ending ( MCBARGS ) 297MCBTYPE callback_recv_ending ( MCBARGS )
292{ 298{
293 msi_session_t* _session = _arg; 299 msi_session_t *_session = _arg;
294 phone_t * _phone = _session->_agent_handler; 300 phone_t *_phone = _session->_agent_handler;
295 _phone->cs->quit=1; 301 _phone->cs->quit = 1;
296 if(_phone->cs->encode_video_thread) 302
297 pthread_join(_phone->cs->encode_video_thread,NULL); 303 if (_phone->cs->encode_video_thread)
298 if(_phone->cs->encode_audio_thread) 304 pthread_join(_phone->cs->encode_video_thread, NULL);
299 pthread_join(_phone->cs->encode_audio_thread,NULL); 305
300 if(_phone->cs->decode_audio_thread) 306 if (_phone->cs->encode_audio_thread)
301 pthread_join(_phone->cs->decode_audio_thread,NULL); 307 pthread_join(_phone->cs->encode_audio_thread, NULL);
302 if(_phone->cs->decode_video_thread) 308
303 pthread_join(_phone->cs->decode_video_thread,NULL); 309 if (_phone->cs->decode_audio_thread)
310 pthread_join(_phone->cs->decode_audio_thread, NULL);
311
312 if (_phone->cs->decode_video_thread)
313 pthread_join(_phone->cs->decode_video_thread, NULL);
314
304 SDL_Quit(); 315 SDL_Quit();
305 printf("all A/V threads successfully shut down\n"); 316 printf("all A/V threads successfully shut down\n");
306 317
307 INFO ( "Call ended!" ); 318 INFO ( "Call ended!" );
308} 319}
309 320
310MCBTYPE callback_recv_error ( MCBARGS ) 321MCBTYPE callback_recv_error ( MCBARGS )
311{ 322{
312 msi_session_t* _session = _arg; 323 msi_session_t *_session = _arg;
313 324
314 INFO( "Error: %s", _session->_last_error_str ); 325 INFO( "Error: %s", _session->_last_error_str );
315} 326}
316 327
317MCBTYPE callback_call_started ( MCBARGS ) 328MCBTYPE callback_call_started ( MCBARGS )
318{ 329{
319 msi_session_t* _session = _arg; 330 msi_session_t *_session = _arg;
320 if ( !phone_startmedia_loop(_session->_agent_handler) ){ 331
332 if ( !phone_startmedia_loop(_session->_agent_handler) ) {
321 INFO("Starting call failed!"); 333 INFO("Starting call failed!");
322 } else { 334 } else {
323 INFO ("Call started! ( press h to hangup )"); 335 INFO ("Call started! ( press h to hangup )");
@@ -334,21 +346,26 @@ MCBTYPE callback_call_rejected ( MCBARGS )
334} 346}
335MCBTYPE callback_call_ended ( MCBARGS ) 347MCBTYPE callback_call_ended ( MCBARGS )
336{ 348{
337 349
338 msi_session_t* _session = _arg; 350 msi_session_t *_session = _arg;
339 phone_t * _phone = _session->_agent_handler; 351 phone_t *_phone = _session->_agent_handler;
340 _phone->cs->quit=1; 352 _phone->cs->quit = 1;
341 if(_phone->cs->encode_video_thread) 353
342 pthread_join(_phone->cs->encode_video_thread,NULL); 354 if (_phone->cs->encode_video_thread)
343 if(_phone->cs->encode_audio_thread) 355 pthread_join(_phone->cs->encode_video_thread, NULL);
344 pthread_join(_phone->cs->encode_audio_thread,NULL); 356
345 if(_phone->cs->decode_audio_thread) 357 if (_phone->cs->encode_audio_thread)
346 pthread_join(_phone->cs->decode_audio_thread,NULL); 358 pthread_join(_phone->cs->encode_audio_thread, NULL);
347 if(_phone->cs->decode_video_thread) 359
348 pthread_join(_phone->cs->decode_video_thread,NULL); 360 if (_phone->cs->decode_audio_thread)
361 pthread_join(_phone->cs->decode_audio_thread, NULL);
362
363 if (_phone->cs->decode_video_thread)
364 pthread_join(_phone->cs->decode_video_thread, NULL);
365
349 SDL_Quit(); 366 SDL_Quit();
350 printf("all A/V threads successfully shut down\n"); 367 printf("all A/V threads successfully shut down\n");
351 368
352 INFO ( "Call ended!" ); 369 INFO ( "Call ended!" );
353} 370}
354 371
@@ -358,10 +375,10 @@ MCBTYPE callback_requ_timeout ( MCBARGS )
358} 375}
359 376
360 377
361phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port) 378phone_t *initPhone(uint16_t _listen_port, uint16_t _send_port)
362{ 379{
363 phone_t* _retu = calloc(sizeof(phone_t),1); 380 phone_t *_retu = calloc(sizeof(phone_t), 1);
364 _retu->cs = av_calloc(sizeof(codec_state),1); 381 _retu->cs = av_calloc(sizeof(codec_state), 1);
365 382
366 /* Initialize our mutex */ 383 /* Initialize our mutex */
367 pthread_mutex_init ( &_mutex, NULL ); 384 pthread_mutex_init ( &_mutex, NULL );
@@ -388,13 +405,13 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
388 405
389 406
390 /* Initialize msi */ 407 /* Initialize msi */
391 _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t*)_USERAGENT ); 408 _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t *)_USERAGENT );
392 409
393 if ( !_retu->_msi ) { 410 if ( !_retu->_msi ) {
394 fprintf ( stderr, "msi_init_session() failed\n" ); 411 fprintf ( stderr, "msi_init_session() failed\n" );
395 return NULL; 412 return NULL;
396 } 413 }
397 414
398 /* Initiate codecs */ 415 /* Initiate codecs */
399 init_encoder(_retu->cs); 416 init_encoder(_retu->cs);
400 init_decoder(_retu->cs); 417 init_decoder(_retu->cs);
@@ -425,7 +442,7 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
425 return _retu; 442 return _retu;
426} 443}
427 444
428pthread_t phone_startmain_loop(phone_t* _phone) 445pthread_t phone_startmain_loop(phone_t *_phone)
429{ 446{
430 int _status; 447 int _status;
431 /* Start receive thread */ 448 /* Start receive thread */
@@ -461,9 +478,9 @@ pthread_t phone_startmain_loop(phone_t* _phone)
461 return _phone_loop_thread; 478 return _phone_loop_thread;
462} 479}
463 480
464void* phone_poll ( void* _p_phone ) 481void *phone_poll ( void *_p_phone )
465{ 482{
466 phone_t* _phone = _p_phone; 483 phone_t *_phone = _p_phone;
467 484
468 int _status = SUCCESS; 485 int _status = SUCCESS;
469 486
@@ -482,121 +499,127 @@ void* phone_poll ( void* _p_phone )
482 "r (reject incoming call)\n" 499 "r (reject incoming call)\n"
483 "q (quit)\n" 500 "q (quit)\n"
484 "================================================================================" 501 "================================================================================"
485 ); 502 );
486 503
487 while ( 1 ) 504 while ( 1 ) {
488 {
489 fgets(_line, sizeof(_line), stdin); 505 fgets(_line, sizeof(_line), stdin);
490 int i; 506 int i;
507
491 for (i = 0; i < 100; i++) { 508 for (i = 0; i < 100; i++) {
492 if (_line[i] == '\n') { 509 if (_line[i] == '\n') {
493 _line[i] = '\0'; 510 _line[i] = '\0';
494 } 511 }
495 } 512 }
513
496 _len = strlen(_line); 514 _len = strlen(_line);
497 515
498 if ( !_len ){ 516 if ( !_len ) {
499 printf(" >> "); fflush(stdout); 517 printf(" >> ");
518 fflush(stdout);
500 continue; 519 continue;
501 } 520 }
502 521
503 if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ){ 522 if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ) {
504 INFO("Invalid input!"); 523 INFO("Invalid input!");
505 continue; 524 continue;
506 } 525 }
507 526
508 switch (_line[0]){ 527 switch (_line[0]) {
509 528
510 case 'c': 529 case 'c': {
511 { 530 if ( _phone->_msi->_call ) {
512 if ( _phone->_msi->_call ){ 531 INFO("Already in a call");
513 INFO("Already in a call"); 532 break;
514 break; 533 }
515 }
516 534
517 call_type _ctype; 535 call_type _ctype;
518 if ( _len < 11 ){
519 INFO("Invalid input; usage: c a/v 0.0.0.0");
520 break;
521 }
522 else if ( _line[2] == 'a' || _line[2] != 'v' ){ /* default and audio */
523 _ctype = type_audio;
524 }
525 else { /* video */
526 _ctype = type_video;
527 }
528 536
529 strcpy(_dest, _line + 4 ); 537 if ( _len < 11 ) {
530 _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id)); 538 INFO("Invalid input; usage: c a/v 0.0.0.0");
539 break;
540 } else if ( _line[2] == 'a' || _line[2] != 'v' ) { /* default and audio */
541 _ctype = type_audio;
542 } else { /* video */
543 _ctype = type_video;
544 }
545
546 strcpy(_dest, _line + 4 );
547 _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id));
548
549 if ( _status < 0 ) {
550 INFO("Could not resolve address!");
551 } else {
552 /* Set timeout */
553 msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
554 INFO("Calling!");
555 }
556
557 t_memset((uint8_t *)_dest, '\0', 17);
531 558
532 if ( _status < 0 ){
533 INFO("Could not resolve address!");
534 } else {
535 /* Set timeout */
536 msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
537 INFO("Calling!");
538 } 559 }
560 break;
539 561
540 t_memset((uint8_t*)_dest, '\0', 17); 562 case 'h': {
563 if ( !_phone->_msi->_call ) {
564 break;
565 }
566
567 msi_hangup(_phone->_msi);
568
569 INFO("Hung up...");
541 570
542 } break;
543 case 'h':
544 {
545 if ( !_phone->_msi->_call ){
546 break;
547 } 571 }
572 break;
548 573
549 msi_hangup(_phone->_msi); 574 case 'a': {
575 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
576 break;
577 }
550 578
551 INFO("Hung up..."); 579 if ( _len > 1 && _line[2] == 'v' )
580 msi_answer(_phone->_msi, type_video);
581 else
582 msi_answer(_phone->_msi, type_audio);
552 583
553 } break;
554 case 'a':
555 {
556 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
557 break;
558 } 584 }
585 break;
586
587 case 'r': {
588 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
589 break;
590 }
559 591
560 if ( _len > 1 && _line[2] == 'v' ) 592 msi_reject(_phone->_msi);
561 msi_answer(_phone->_msi, type_video); 593
562 else 594 INFO("Call Rejected...");
563 msi_answer(_phone->_msi, type_audio);
564 595
565 } break;
566 case 'r':
567 {
568 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ){
569 break;
570 } 596 }
597 break;
571 598
572 msi_reject(_phone->_msi); 599 case 'q': {
600 INFO("Quitting!");
601 pthread_exit(NULL);
602 }
573 603
574 INFO("Call Rejected..."); 604 default: {
605 INFO("Invalid command!");
606 }
607 break;
575 608
576 } break;
577 case 'q':
578 {
579 INFO("Quitting!");
580 pthread_exit(NULL);
581 } 609 }
582 default:
583 {
584 INFO("Invalid command!");
585 } break;
586 610
587 } 611 usleep(1000);
588 usleep(1000);
589 } 612 }
590 613
591 pthread_exit(NULL); 614 pthread_exit(NULL);
592} 615}
593 616
594int quitPhone(phone_t* _phone) 617int quitPhone(phone_t *_phone)
595{ 618{
596 if ( _phone->_msi->_call ){ 619 if ( _phone->_msi->_call ) {
597 msi_hangup(_phone->_msi); /* Hangup the phone first */ 620 msi_hangup(_phone->_msi); /* Hangup the phone first */
598 } 621 }
599 622
600 msi_terminate_session(_phone->_msi); 623 msi_terminate_session(_phone->_msi);
601 pthread_mutex_destroy ( &_mutex ); 624 pthread_mutex_destroy ( &_mutex );
602 625
@@ -606,17 +629,17 @@ int quitPhone(phone_t* _phone)
606 629
607/* ---------------------- */ 630/* ---------------------- */
608 631
609int print_help ( const char* _name ) 632int print_help ( const char *_name )
610{ 633{
611 printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name ); 634 printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name );
612 return FAILURE; 635 return FAILURE;
613} 636}
614 637
615int main ( int argc, char* argv [] ) 638int main ( int argc, char *argv [] )
616{ 639{
617 arg_t* _args = parse_args ( argc, argv ); 640 arg_t *_args = parse_args ( argc, argv );
618 641
619 const char* _mode = find_arg_duble ( _args, "-m" ); 642 const char *_mode = find_arg_duble ( _args, "-m" );
620 uint16_t _listen_port; 643 uint16_t _listen_port;
621 uint16_t _send_port; 644 uint16_t _send_port;
622 645
@@ -631,9 +654,9 @@ int main ( int argc, char* argv [] )
631 _listen_port = 31000; 654 _listen_port = 31000;
632 } else return print_help ( argv[0] ); 655 } else return print_help ( argv[0] );
633 656
634 phone_t* _phone = initPhone(_listen_port, _send_port); 657 phone_t *_phone = initPhone(_listen_port, _send_port);
635 658
636 if ( _phone ){ 659 if ( _phone ) {
637 phone_startmain_loop(_phone); 660 phone_startmain_loop(_phone);
638 661
639 quitPhone(_phone); 662 quitPhone(_phone);