diff options
-rwxr-xr-x | toxav/phone.c | 15 | ||||
-rw-r--r-- | toxav/toxmedia.c | 2 | ||||
-rwxr-xr-x | toxav/toxmsi.c | 31 | ||||
-rwxr-xr-x | toxav/toxrtp.c | 28 | ||||
-rwxr-xr-x | toxav/toxrtp.h | 2 | ||||
-rwxr-xr-x | toxcore/event.c | 8 |
6 files changed, 49 insertions, 37 deletions
diff --git a/toxav/phone.c b/toxav/phone.c index 6e746bc5..d8318ff9 100755 --- a/toxav/phone.c +++ b/toxav/phone.c | |||
@@ -153,7 +153,7 @@ void INFO (const char* _format, ...) | |||
153 | unsigned char *hex_string_to_bin(char hex_string[]) | 153 | unsigned char *hex_string_to_bin(char hex_string[]) |
154 | { | 154 | { |
155 | size_t i, len = strlen(hex_string); | 155 | size_t i, len = strlen(hex_string); |
156 | unsigned char *val = calloc(sizeof(char), len); | 156 | unsigned char *val = calloc(sizeof(unsigned char), len); |
157 | char *pos = hex_string; | 157 | char *pos = hex_string; |
158 | 158 | ||
159 | for (i = 0; i < len; ++i, pos += 2) | 159 | for (i = 0; i < len; ++i, pos += 2) |
@@ -463,7 +463,7 @@ void *encode_audio_thread(void *arg) | |||
463 | 463 | ||
464 | void *decode_video_thread(void *arg) | 464 | void *decode_video_thread(void *arg) |
465 | { | 465 | { |
466 | INFO("Started decode audio thread!"); | 466 | INFO("Started decode video thread!"); |
467 | av_session_t* _phone = arg; | 467 | av_session_t* _phone = arg; |
468 | 468 | ||
469 | codec_state *cs = _phone->cs; | 469 | codec_state *cs = _phone->cs; |
@@ -489,7 +489,7 @@ void *decode_video_thread(void *arg) | |||
489 | if (cs->video_decoder_ctx->width != width || cs->video_decoder_ctx->height != height) { | 489 | if (cs->video_decoder_ctx->width != width || cs->video_decoder_ctx->height != height) { |
490 | width = cs->video_decoder_ctx->width; | 490 | width = cs->video_decoder_ctx->width; |
491 | height = cs->video_decoder_ctx->height; | 491 | height = cs->video_decoder_ctx->height; |
492 | printf("w: %d h%d \n", width, height); | 492 | printf("w: %d h: %d \n", width, height); |
493 | video_decoder_refresh(_phone, width, height); | 493 | video_decoder_refresh(_phone, width, height); |
494 | } | 494 | } |
495 | 495 | ||
@@ -505,7 +505,6 @@ void *decode_video_thread(void *arg) | |||
505 | usleep(1000); | 505 | usleep(1000); |
506 | } | 506 | } |
507 | 507 | ||
508 | printf("vend\n"); | ||
509 | /* clean up codecs */ | 508 | /* clean up codecs */ |
510 | pthread_mutex_lock(&cs->ctrl_mutex); | 509 | pthread_mutex_lock(&cs->ctrl_mutex); |
511 | av_free(r_video_frame); | 510 | av_free(r_video_frame); |
@@ -667,7 +666,7 @@ int phone_startmedia_loop ( av_session_t* _phone ) | |||
667 | _phone->_msi->call->nonce_local | 666 | _phone->_msi->call->nonce_local |
668 | ); | 667 | ); |
669 | 668 | ||
670 | _phone->_rtp_audio = rtp_init_session ( | 669 | _phone->_rtp_video = rtp_init_session ( |
671 | type_video, | 670 | type_video, |
672 | _phone->_messenger, | 671 | _phone->_messenger, |
673 | _phone->_msi->call->peers[0], | 672 | _phone->_msi->call->peers[0], |
@@ -891,11 +890,7 @@ av_session_t* av_init_session() | |||
891 | printf("Could not start capture device! %d\n", alcGetError((ALCdevice*)_retu->audio_capture_device)); | 890 | printf("Could not start capture device! %d\n", alcGetError((ALCdevice*)_retu->audio_capture_device)); |
892 | return 0; | 891 | return 0; |
893 | } | 892 | } |
894 | 893 | ||
895 | |||
896 | init_encoder(_retu->cs); | ||
897 | init_decoder(_retu->cs); | ||
898 | |||
899 | 894 | ||
900 | uint8_t _byte_address[TOX_FRIEND_ADDRESS_SIZE]; | 895 | uint8_t _byte_address[TOX_FRIEND_ADDRESS_SIZE]; |
901 | tox_get_address(_retu->_messenger, _byte_address ); | 896 | tox_get_address(_retu->_messenger, _byte_address ); |
diff --git a/toxav/toxmedia.c b/toxav/toxmedia.c index bb4e7210..a31b9ab0 100644 --- a/toxav/toxmedia.c +++ b/toxav/toxmedia.c | |||
@@ -142,7 +142,7 @@ int empty_queue(struct jitter_buffer *q) | |||
142 | while (q->size > 0) { | 142 | while (q->size > 0) { |
143 | q->size--; | 143 | q->size--; |
144 | /* FIXME: */ | 144 | /* FIXME: */ |
145 | /* rtp_free_msg(cs->_rtp_video, q->queue[q->front]); */ | 145 | rtp_free_msg(NULL, q->queue[q->front]); |
146 | q->front++; | 146 | q->front++; |
147 | 147 | ||
148 | if (q->front == q->capacity) | 148 | if (q->front == q->capacity) |
diff --git a/toxav/toxmsi.c b/toxav/toxmsi.c index db9ae2d2..d5c35730 100755 --- a/toxav/toxmsi.c +++ b/toxav/toxmsi.c | |||
@@ -47,7 +47,7 @@ | |||
47 | #define TYPE_REQUEST 1 | 47 | #define TYPE_REQUEST 1 |
48 | #define TYPE_RESPONSE 2 | 48 | #define TYPE_RESPONSE 2 |
49 | 49 | ||
50 | #define VERSION_STRING "0.3.1" | 50 | unsigned char* VERSION_STRING = (unsigned char*)"0.3.1"; |
51 | #define VERSION_STRLEN 5 | 51 | #define VERSION_STRLEN 5 |
52 | 52 | ||
53 | #define CT_AUDIO_HEADER_VALUE "AUDIO" | 53 | #define CT_AUDIO_HEADER_VALUE "AUDIO" |
@@ -220,18 +220,26 @@ static inline const uint8_t *stringify_response ( MSIResponse response ) { | |||
220 | * @retval -1 Error occured. | 220 | * @retval -1 Error occured. |
221 | * @retval 0 Success. | 221 | * @retval 0 Success. |
222 | */ | 222 | */ |
223 | int parse_raw_data ( MSIMessage* msg, const uint8_t* data ) { | 223 | int parse_raw_data ( MSIMessage* msg, const uint8_t* data, uint16_t length ) { |
224 | assert ( msg ); | 224 | assert ( msg ); |
225 | 225 | ||
226 | if ( data[length - 1] ) /* End byte must have value 0 */ | ||
227 | return -1; | ||
228 | |||
226 | const uint8_t* _it = data; | 229 | const uint8_t* _it = data; |
227 | 230 | ||
228 | while ( *_it ) {/* until end_byte is hit */ | 231 | while ( *_it ) {/* until end_byte is hit */ |
229 | 232 | ||
230 | if ( *_it == field_byte ) { | 233 | uint16_t itedlen = (_it - data) + 2; |
234 | |||
235 | if ( *_it == field_byte && itedlen < length ) { | ||
236 | |||
231 | uint16_t _size = ( uint16_t ) * ( _it + 1 ) << 8 | | 237 | uint16_t _size = ( uint16_t ) * ( _it + 1 ) << 8 | |
232 | ( uint16_t ) * ( _it + 2 ); | 238 | ( uint16_t ) * ( _it + 2 ); |
233 | 239 | ||
234 | _it += 3; /*place it at the field value beginning*/ | 240 | if ( itedlen + _size > length ) return -1; |
241 | |||
242 | _it += 3; /* place it at the field value beginning */ | ||
235 | 243 | ||
236 | switch ( _size ) { /* Compare the size of the hardcoded values ( vary fast and convenient ) */ | 244 | switch ( _size ) { /* Compare the size of the hardcoded values ( vary fast and convenient ) */ |
237 | 245 | ||
@@ -340,7 +348,7 @@ MSIMessage* msi_new_message ( uint8_t type, const uint8_t* type_id ) { | |||
340 | return NULL; | 348 | return NULL; |
341 | } | 349 | } |
342 | 350 | ||
343 | ALLOCATE_HEADER ( _retu->version, VERSION_STRING, strlen ( VERSION_STRING ) ) | 351 | ALLOCATE_HEADER ( _retu->version, VERSION_STRING, strlen ( (const char*)VERSION_STRING ) ) |
344 | 352 | ||
345 | return _retu; | 353 | return _retu; |
346 | } | 354 | } |
@@ -353,7 +361,7 @@ MSIMessage* msi_new_message ( uint8_t type, const uint8_t* type_id ) { | |||
353 | * @return MSIMessage* Parsed message. | 361 | * @return MSIMessage* Parsed message. |
354 | * @retval NULL Error occured. | 362 | * @retval NULL Error occured. |
355 | */ | 363 | */ |
356 | MSIMessage* parse_message ( const uint8_t* data ) { | 364 | MSIMessage* parse_message ( const uint8_t* data, uint16_t length ) { |
357 | assert ( data ); | 365 | assert ( data ); |
358 | 366 | ||
359 | MSIMessage* _retu = calloc ( sizeof ( MSIMessage ), 1 ); | 367 | MSIMessage* _retu = calloc ( sizeof ( MSIMessage ), 1 ); |
@@ -361,7 +369,7 @@ MSIMessage* parse_message ( const uint8_t* data ) { | |||
361 | 369 | ||
362 | memset ( _retu, 0, sizeof ( MSIMessage ) ); | 370 | memset ( _retu, 0, sizeof ( MSIMessage ) ); |
363 | 371 | ||
364 | if ( parse_raw_data ( _retu, data ) == -1 ) { | 372 | if ( parse_raw_data ( _retu, data, length ) == -1 ) { |
365 | 373 | ||
366 | free_message ( _retu ); | 374 | free_message ( _retu ); |
367 | return NULL; | 375 | return NULL; |
@@ -1014,12 +1022,13 @@ void msi_handle_packet ( Messenger* messenger, int source, uint8_t* data, uint16 | |||
1014 | { | 1022 | { |
1015 | /* Unused */ | 1023 | /* Unused */ |
1016 | (void)messenger; | 1024 | (void)messenger; |
1017 | (void)&length; | ||
1018 | 1025 | ||
1019 | MSISession* _session = object; | 1026 | MSISession* _session = object; |
1020 | MSIMessage* _msg; | 1027 | MSIMessage* _msg; |
1021 | 1028 | ||
1022 | _msg = parse_message ( data ); | 1029 | if ( !length ) return; |
1030 | |||
1031 | _msg = parse_message ( data, length ); | ||
1023 | 1032 | ||
1024 | if ( !_msg ) return; | 1033 | if ( !_msg ) return; |
1025 | 1034 | ||
@@ -1227,7 +1236,7 @@ int msi_invite ( MSISession* session, MSICallType call_type, uint32_t rngsec, ui | |||
1227 | int msi_hangup ( MSISession* session ) { | 1236 | int msi_hangup ( MSISession* session ) { |
1228 | assert ( session ); | 1237 | assert ( session ); |
1229 | 1238 | ||
1230 | if ( !session->call && session->call->state != call_active ) | 1239 | if ( !session->call || session->call->state != call_active ) |
1231 | return -1; | 1240 | return -1; |
1232 | 1241 | ||
1233 | MSIMessage* _msg_ending = msi_new_message ( TYPE_REQUEST, stringify_request ( end ) ); | 1242 | MSIMessage* _msg_ending = msi_new_message ( TYPE_REQUEST, stringify_request ( end ) ); |
diff --git a/toxav/toxrtp.c b/toxav/toxrtp.c index f8bdee2f..d573d403 100755 --- a/toxav/toxrtp.c +++ b/toxav/toxrtp.c | |||
@@ -310,6 +310,7 @@ RTPExtHeader* extract_ext_header ( const uint8_t* payload, size_t length ) | |||
310 | 310 | ||
311 | 311 | ||
312 | if ( length < ( _ext_length * sizeof(uint32_t) ) ) { | 312 | if ( length < ( _ext_length * sizeof(uint32_t) ) ) { |
313 | free(_retu); | ||
313 | return NULL; | 314 | return NULL; |
314 | } | 315 | } |
315 | 316 | ||
@@ -351,9 +352,11 @@ uint8_t* add_header ( RTPHeader* header, uint8_t* payload ) | |||
351 | U32_to_bytes( _it, header->timestamp); _it+=4; | 352 | U32_to_bytes( _it, header->timestamp); _it+=4; |
352 | U32_to_bytes( _it, header->ssrc); | 353 | U32_to_bytes( _it, header->ssrc); |
353 | 354 | ||
354 | uint8_t _x; | 355 | if ( header->csrc ) { |
355 | for ( _x = 0; _x < _cc; _x++ ) { | 356 | uint8_t _x; |
356 | _it+=4; U32_to_bytes( _it, header->csrc[_x]); | 357 | for ( _x = 0; _x < _cc; _x++ ) { |
358 | _it+=4; U32_to_bytes( _it, header->csrc[_x]); | ||
359 | } | ||
357 | } | 360 | } |
358 | 361 | ||
359 | return _it + 4; | 362 | return _it + 4; |
@@ -373,9 +376,11 @@ uint8_t* add_ext_header ( RTPExtHeader* header, uint8_t* payload ) | |||
373 | U16_to_bytes(_it, header->length); _it+=2; | 376 | U16_to_bytes(_it, header->length); _it+=2; |
374 | U16_to_bytes(_it, header->type); _it-=2; /* Return to 0 position */ | 377 | U16_to_bytes(_it, header->type); _it-=2; /* Return to 0 position */ |
375 | 378 | ||
376 | uint16_t _x; | 379 | if ( header->table ) { |
377 | for ( _x = 0; _x < header->length; _x++ ) { | 380 | uint16_t _x; |
378 | _it+=4; U32_to_bytes(_it, header->table[_x]); | 381 | for ( _x = 0; _x < header->length; _x++ ) { |
382 | _it+=4; U32_to_bytes(_it, header->table[_x]); | ||
383 | } | ||
379 | } | 384 | } |
380 | 385 | ||
381 | return _it + 4; | 386 | return _it + 4; |
@@ -465,8 +470,13 @@ RTPMessage* msg_parse ( uint16_t sequnum, const uint8_t* data, int length ) | |||
465 | } else { | 470 | } else { |
466 | _retu->ext_header = NULL; | 471 | _retu->ext_header = NULL; |
467 | } | 472 | } |
468 | 473 | ||
469 | memcpy ( _retu->data, data + _from_pos, length - _from_pos ); | 474 | if ( length - _from_pos <= MAX_RTP_SIZE ) |
475 | memcpy ( _retu->data, data + _from_pos, length - _from_pos ); | ||
476 | else { | ||
477 | rtp_free_msg(NULL, _retu); | ||
478 | return NULL; | ||
479 | } | ||
470 | _retu->next = NULL; | 480 | _retu->next = NULL; |
471 | 481 | ||
472 | return _retu; | 482 | return _retu; |
@@ -488,7 +498,7 @@ int rtp_handle_packet ( void* object, IP_Port ip_port, uint8_t* data, uint32_t l | |||
488 | RTPSession* _session = object; | 498 | RTPSession* _session = object; |
489 | RTPMessage* _msg; | 499 | RTPMessage* _msg; |
490 | 500 | ||
491 | if ( !_session ) | 501 | if ( !_session || length < 13 ) /* 12 is the minimum length for rtp + desc. byte */ |
492 | return -1; | 502 | return -1; |
493 | 503 | ||
494 | uint8_t _plain[MAX_UDP_PACKET_SIZE]; | 504 | uint8_t _plain[MAX_UDP_PACKET_SIZE]; |
diff --git a/toxav/toxrtp.h b/toxav/toxrtp.h index 9f8ae5ee..4b0d681f 100755 --- a/toxav/toxrtp.h +++ b/toxav/toxrtp.h | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "../toxcore/tox.h" | 31 | #include "../toxcore/tox.h" |
32 | 32 | ||
33 | #define MAX_SEQU_NUM 65535 | 33 | #define MAX_SEQU_NUM 65535 |
34 | #define MAX_RTP_SIZE 1400 | 34 | #define MAX_RTP_SIZE 10400 |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * @brief Standard rtp header | 37 | * @brief Standard rtp header |
diff --git a/toxcore/event.c b/toxcore/event.c index 81f8172f..05e2a03c 100755 --- a/toxcore/event.c +++ b/toxcore/event.c | |||
@@ -360,16 +360,14 @@ void __attribute__((constructor)) init_event_poll () | |||
360 | RUN_IN_THREAD(event_poll, &event_handler); | 360 | RUN_IN_THREAD(event_poll, &event_handler); |
361 | } | 361 | } |
362 | 362 | ||
363 | /* NOTE: Do we need this? */ | ||
363 | void __attribute__((destructor)) terminate_event_poll() | 364 | void __attribute__((destructor)) terminate_event_poll() |
364 | { | 365 | { |
365 | /* Exit thread */ | 366 | /* Exit thread */ |
366 | event_handler.running = 0; | 367 | event_handler.running = 0; |
367 | 368 | ||
368 | /* Keep the global until thread exits */ | 369 | /* Give it enought time to exit */ |
369 | while (event_handler.running > -1) { | 370 | usleep(FREQUENCY*2); |
370 | (void)event_handler.running; | ||
371 | usleep(FREQUENCY*2); | ||
372 | } | ||
373 | 371 | ||
374 | pthread_mutex_destroy( &event_handler.mutex ); | 372 | pthread_mutex_destroy( &event_handler.mutex ); |
375 | } \ No newline at end of file | 373 | } \ No newline at end of file |