diff options
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index e23fa132..80fcc630 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -30,10 +30,6 @@ | |||
30 | #include <assert.h> | 30 | #include <assert.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | 32 | ||
33 | #include "../toxcore/util.h" | ||
34 | #include "../toxcore/network.h" | ||
35 | #include "../toxcore/net_crypto.h" | ||
36 | #include "../toxcore/Messenger.h" | ||
37 | 33 | ||
38 | #define PAYLOAD_ID_VALUE_OPUS 1 | 34 | #define PAYLOAD_ID_VALUE_OPUS 1 |
39 | #define PAYLOAD_ID_VALUE_VP8 2 | 35 | #define PAYLOAD_ID_VALUE_VP8 2 |
@@ -241,8 +237,8 @@ RTPHeader* extract_header ( const uint8_t* payload, int length ) | |||
241 | 237 | ||
242 | _retu->flags = *_it; ++_it; | 238 | _retu->flags = *_it; ++_it; |
243 | 239 | ||
244 | /* This indicates if the first 2 bytes are valid. | 240 | /* This indicates if the first 2 bits are valid. |
245 | * Now it my happen that this is out of order but | 241 | * Now it may happen that this is out of order but |
246 | * it cuts down chances of parsing some invalid value | 242 | * it cuts down chances of parsing some invalid value |
247 | */ | 243 | */ |
248 | 244 | ||
@@ -299,7 +295,7 @@ RTPHeader* extract_header ( const uint8_t* payload, int length ) | |||
299 | * @return RTPExtHeader* Extracted extension header. | 295 | * @return RTPExtHeader* Extracted extension header. |
300 | * @retval NULL Error occurred while extracting extension header. | 296 | * @retval NULL Error occurred while extracting extension header. |
301 | */ | 297 | */ |
302 | RTPExtHeader* extract_ext_header ( const uint8_t* payload, size_t length ) | 298 | RTPExtHeader* extract_ext_header ( const uint8_t* payload, uint16_t length ) |
303 | { | 299 | { |
304 | const uint8_t* _it = payload; | 300 | const uint8_t* _it = payload; |
305 | 301 | ||
@@ -551,7 +547,7 @@ int rtp_handle_packet ( void* object, IP_Port ip_port, uint8_t* data, uint32_t l | |||
551 | /* Hopefully this goes well | 547 | /* Hopefully this goes well |
552 | * NOTE: Is this even used? | 548 | * NOTE: Is this even used? |
553 | */ | 549 | */ |
554 | memcpy(&_msg->from, &ip_port, sizeof(tox_IP_Port)); | 550 | memcpy(&_msg->from, &ip_port, sizeof(IP_Port)); |
555 | 551 | ||
556 | /* Check if message came in late */ | 552 | /* Check if message came in late */ |
557 | if ( check_late_message(_session, _msg) < 0 ) { /* Not late */ | 553 | if ( check_late_message(_session, _msg) < 0 ) { /* Not late */ |
@@ -689,7 +685,7 @@ int rtp_release_session_recv ( RTPSession* session ) | |||
689 | 685 | ||
690 | 686 | ||
691 | /** | 687 | /** |
692 | * @brief Get's oldes message in the list. | 688 | * @brief Gets oldest message in the list. |
693 | * | 689 | * |
694 | * @param session Where the list is. | 690 | * @param session Where the list is. |
695 | * @return RTPMessage* The message. You _must_ call rtp_msg_free() to free it. | 691 | * @return RTPMessage* The message. You _must_ call rtp_msg_free() to free it. |
@@ -727,7 +723,7 @@ RTPMessage* rtp_recv_msg ( RTPSession* session ) | |||
727 | * @retval -1 On error. | 723 | * @retval -1 On error. |
728 | * @retval 0 On success. | 724 | * @retval 0 On success. |
729 | */ | 725 | */ |
730 | int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uint16_t length ) | 726 | int rtp_send_msg ( RTPSession* session, Messenger* messenger, const uint8_t* data, uint16_t length ) |
731 | { | 727 | { |
732 | RTPMessage* msg = rtp_new_message (session, data, length); | 728 | RTPMessage* msg = rtp_new_message (session, data, length); |
733 | 729 | ||
@@ -743,8 +739,8 @@ int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uin | |||
743 | increase_nonce ( _calculated, msg->header->sequnum ); | 739 | increase_nonce ( _calculated, msg->header->sequnum ); |
744 | 740 | ||
745 | /* Need to skip 2 bytes that are for sequnum */ | 741 | /* Need to skip 2 bytes that are for sequnum */ |
746 | int encrypted_length = encrypt_data_symmetric( | 742 | int encrypted_length = encrypt_data_symmetric( /* TODO: msg->length - 2 (fix this properly)*/ |
747 | (uint8_t*) session->encrypt_key, _calculated, msg->data + 2, msg->length - 2, _send_data + 3 ); | 743 | (uint8_t*) session->encrypt_key, _calculated, msg->data + 2, msg->length, _send_data + 3 ); |
748 | 744 | ||
749 | int full_length = encrypted_length + 3; | 745 | int full_length = encrypted_length + 3; |
750 | 746 | ||
@@ -752,7 +748,8 @@ int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uin | |||
752 | _send_data[2] = msg->data[1]; | 748 | _send_data[2] = msg->data[1]; |
753 | 749 | ||
754 | 750 | ||
755 | if ( full_length != sendpacket ( ((Messenger*)messenger)->net, *((IP_Port*) &session->dest), _send_data, full_length) ) { | 751 | /*if ( full_length != sendpacket ( messenger->net, *((IP_Port*) &session->dest), _send_data, full_length) ) {*/ |
752 | if ( full_length != send_custom_user_packet(messenger, session->dest, _send_data, full_length) ) { | ||
756 | printf("Rtp error: %s\n", strerror(errno)); | 753 | printf("Rtp error: %s\n", strerror(errno)); |
757 | return -1; | 754 | return -1; |
758 | } | 755 | } |
@@ -816,30 +813,26 @@ void rtp_free_msg ( RTPSession* session, RTPMessage* msg ) | |||
816 | * @retval NULL Error occurred. | 813 | * @retval NULL Error occurred. |
817 | */ | 814 | */ |
818 | RTPSession* rtp_init_session ( int payload_type, | 815 | RTPSession* rtp_init_session ( int payload_type, |
819 | Tox* messenger, | 816 | Messenger* messenger, |
820 | int friend_num, | 817 | int friend_num, |
821 | const uint8_t* encrypt_key, | 818 | const uint8_t* encrypt_key, |
822 | const uint8_t* decrypt_key, | 819 | const uint8_t* decrypt_key, |
823 | const uint8_t* encrypt_nonce, | 820 | const uint8_t* encrypt_nonce, |
824 | const uint8_t* decrypt_nonce | 821 | const uint8_t* decrypt_nonce ) |
825 | ) | ||
826 | { | 822 | { |
827 | Messenger* _messenger_casted = (Messenger*) messenger; | ||
828 | |||
829 | IP_Port _dest = get_friend_ipport(_messenger_casted, friend_num ); | ||
830 | |||
831 | /* This should be enough eh? */ | ||
832 | if ( _dest.port == 0) { | ||
833 | return NULL; | ||
834 | } | ||
835 | |||
836 | RTPSession* _retu = calloc(1, sizeof(RTPSession)); | 823 | RTPSession* _retu = calloc(1, sizeof(RTPSession)); |
837 | assert(_retu); | 824 | assert(_retu); |
838 | 825 | ||
839 | networking_registerhandler(_messenger_casted->net, payload_type, rtp_handle_packet, _retu); | 826 | /*networking_registerhandler(messenger->net, payload_type, rtp_handle_packet, _retu);*/ |
827 | if ( -1 == custom_user_packet_registerhandler(messenger, friend_num, payload_type, rtp_handle_packet, _retu) ) | ||
828 | { | ||
829 | fprintf(stderr, "Error setting custom register handler for rtp session\n"); | ||
830 | free(_retu); | ||
831 | return NULL; | ||
832 | } | ||
840 | 833 | ||
841 | _retu->version = RTP_VERSION; /* It's always 2 */ | 834 | _retu->version = RTP_VERSION; /* It's always 2 */ |
842 | _retu->padding = 0; /* If some additional data is needed about the packet */ | 835 | _retu->padding = 0; /* If some additional data is needed about the packet */ |
843 | _retu->extension = 0; /* If extension to header is needed */ | 836 | _retu->extension = 0; /* If extension to header is needed */ |
844 | _retu->cc = 1; /* Amount of contributors */ | 837 | _retu->cc = 1; /* Amount of contributors */ |
845 | _retu->csrc = NULL; /* Container */ | 838 | _retu->csrc = NULL; /* Container */ |
@@ -847,7 +840,7 @@ RTPSession* rtp_init_session ( int payload_type, | |||
847 | _retu->marker = 0; | 840 | _retu->marker = 0; |
848 | _retu->payload_type = payload_table[payload_type]; | 841 | _retu->payload_type = payload_table[payload_type]; |
849 | 842 | ||
850 | _retu->dest = *((tox_IP_Port*)&_dest); | 843 | _retu->dest = friend_num; |
851 | 844 | ||
852 | _retu->rsequnum = _retu->sequnum = 1; | 845 | _retu->rsequnum = _retu->sequnum = 1; |
853 | 846 | ||
@@ -894,12 +887,12 @@ RTPSession* rtp_init_session ( int payload_type, | |||
894 | * @retval -1 Error occurred. | 887 | * @retval -1 Error occurred. |
895 | * @retval 0 Success. | 888 | * @retval 0 Success. |
896 | */ | 889 | */ |
897 | int rtp_terminate_session ( RTPSession* session, Tox* messenger ) | 890 | int rtp_terminate_session ( RTPSession* session, Messenger* messenger ) |
898 | { | 891 | { |
899 | if ( !session ) | 892 | if ( !session ) |
900 | return -1; | 893 | return -1; |
901 | 894 | ||
902 | networking_registerhandler(((Messenger*)messenger)->net, session->prefix, NULL, NULL); | 895 | custom_user_packet_registerhandler(messenger, session->dest, session->prefix, NULL, NULL); |
903 | 896 | ||
904 | free ( session->ext_header ); | 897 | free ( session->ext_header ); |
905 | free ( session->csrc ); | 898 | free ( session->csrc ); |