diff options
author | mannol <eniz_vukovic@hotmail.com> | 2015-04-22 02:09:37 +0200 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2015-04-22 02:09:37 +0200 |
commit | 1bfd93e64a2a6d3bf9c90a9aa89abd29f3d826a7 (patch) | |
tree | 094af1cad749bef83678071476075160d956bfeb /toxav/rtp.c | |
parent | 3fd0ee5f0873924b4881b0e33eb1c17ea877ab4a (diff) |
Finished refactoring
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index 9ef41b35..9657da67 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -68,12 +68,6 @@ typedef struct RTCPSession_s { | |||
68 | } RTCPSession; | 68 | } RTCPSession; |
69 | 69 | ||
70 | 70 | ||
71 | |||
72 | /* These are defined externally */ | ||
73 | void ac_queue_message(void *acp, RTPMessage *msg); | ||
74 | void vc_queue_message(void *vcp, RTPMessage *msg); | ||
75 | |||
76 | |||
77 | RTPHeader *parse_header_in ( const uint8_t *payload, int length ); | 71 | RTPHeader *parse_header_in ( const uint8_t *payload, int length ); |
78 | RTPExtHeader *parse_ext_header_in ( const uint8_t *payload, uint16_t length ); | 72 | RTPExtHeader *parse_ext_header_in ( const uint8_t *payload, uint16_t length ); |
79 | RTPMessage *msg_parse ( const uint8_t *data, int length ); | 73 | RTPMessage *msg_parse ( const uint8_t *data, int length ); |
@@ -100,7 +94,7 @@ RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num ) | |||
100 | 94 | ||
101 | retu->tstate = rtp_StateNormal; | 95 | retu->tstate = rtp_StateNormal; |
102 | retu->m = messenger; | 96 | retu->m = messenger; |
103 | retu->dest = friend_num; | 97 | retu->friend_id = friend_num; |
104 | 98 | ||
105 | if ( !(retu->csrc = calloc(1, sizeof(uint32_t))) ) { | 99 | if ( !(retu->csrc = calloc(1, sizeof(uint32_t))) ) { |
106 | LOGGER_WARNING("Alloc failed! Program might misbehave!"); | 100 | LOGGER_WARNING("Alloc failed! Program might misbehave!"); |
@@ -155,7 +149,7 @@ void rtp_do(RTPSession *session) | |||
155 | return; | 149 | return; |
156 | 150 | ||
157 | if (current_time_monotonic() - session->rtcp_session->last_sent_report_ts >= RTCP_REPORT_INTERVAL_MS) { | 151 | if (current_time_monotonic() - session->rtcp_session->last_sent_report_ts >= RTCP_REPORT_INTERVAL_MS) { |
158 | send_rtcp_report(session->rtcp_session, session->m, session->dest); | 152 | send_rtcp_report(session->rtcp_session, session->m, session->friend_id); |
159 | } | 153 | } |
160 | 154 | ||
161 | if (rb_full(session->rtcp_session->pl_stats)) { | 155 | if (rb_full(session->rtcp_session->pl_stats)) { |
@@ -202,15 +196,15 @@ int rtp_start_receiving(RTPSession* session) | |||
202 | if (session == NULL) | 196 | if (session == NULL) |
203 | return -1; | 197 | return -1; |
204 | 198 | ||
205 | if (m_callback_rtp_packet(session->m, session->dest, session->prefix, | 199 | if (m_callback_rtp_packet(session->m, session->friend_id, session->prefix, |
206 | handle_rtp_packet, session) == -1) { | 200 | handle_rtp_packet, session) == -1) { |
207 | LOGGER_WARNING("Failed to register rtp receive handler"); | 201 | LOGGER_WARNING("Failed to register rtp receive handler"); |
208 | return -1; | 202 | return -1; |
209 | } | 203 | } |
210 | if (m_callback_rtp_packet(session->m, session->dest, session->rtcp_session->prefix, | 204 | if (m_callback_rtp_packet(session->m, session->friend_id, session->rtcp_session->prefix, |
211 | handle_rtcp_packet, session->rtcp_session) == -1) { | 205 | handle_rtcp_packet, session->rtcp_session) == -1) { |
212 | LOGGER_WARNING("Failed to register rtcp receive handler"); | 206 | LOGGER_WARNING("Failed to register rtcp receive handler"); |
213 | m_callback_rtp_packet(session->m, session->dest, session->prefix, NULL, NULL); | 207 | m_callback_rtp_packet(session->m, session->friend_id, session->prefix, NULL, NULL); |
214 | return -1; | 208 | return -1; |
215 | } | 209 | } |
216 | 210 | ||
@@ -221,8 +215,8 @@ int rtp_stop_receiving(RTPSession* session) | |||
221 | if (session == NULL) | 215 | if (session == NULL) |
222 | return -1; | 216 | return -1; |
223 | 217 | ||
224 | m_callback_rtp_packet(session->m, session->dest, session->prefix, NULL, NULL); | 218 | m_callback_rtp_packet(session->m, session->friend_id, session->prefix, NULL, NULL); |
225 | m_callback_rtp_packet(session->m, session->dest, session->rtcp_session->prefix, NULL, NULL); /* RTCP */ | 219 | m_callback_rtp_packet(session->m, session->friend_id, session->rtcp_session->prefix, NULL, NULL); /* RTCP */ |
226 | 220 | ||
227 | return 0; | 221 | return 0; |
228 | } | 222 | } |
@@ -253,7 +247,7 @@ int rtp_send_msg ( RTPSession *session, const uint8_t *data, uint16_t length ) | |||
253 | memcpy ( it, data, length ); | 247 | memcpy ( it, data, length ); |
254 | 248 | ||
255 | 249 | ||
256 | if ( -1 == send_custom_lossy_packet(session->m, session->dest, parsed, parsed_len) ) { | 250 | if ( -1 == send_custom_lossy_packet(session->m, session->friend_id, parsed, parsed_len) ) { |
257 | LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno)); | 251 | LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno)); |
258 | return -1; | 252 | return -1; |
259 | } | 253 | } |
@@ -546,7 +540,6 @@ void send_rtcp_report(RTCPSession* session, Messenger* m, uint32_t friendnumber) | |||
546 | } | 540 | } |
547 | int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) | 541 | int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) |
548 | { | 542 | { |
549 | /* TODO on message callback */ | ||
550 | RTPSession *session = object; | 543 | RTPSession *session = object; |
551 | RTPMessage *msg; | 544 | RTPMessage *msg; |
552 | 545 | ||
@@ -578,20 +571,12 @@ int handle_rtp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data | |||
578 | 571 | ||
579 | session->rtcp_session->last_received_packets ++; | 572 | session->rtcp_session->last_received_packets ++; |
580 | 573 | ||
581 | /* Check if this session can handle the packet */ | 574 | if (session->mcb) |
582 | if (session->payload_type != session->prefix % 128) { | 575 | return session->mcb (session->cs, msg); |
583 | LOGGER_WARNING("Friend %d sent invalid payload type!", session->dest); | 576 | else { |
584 | rtp_free_msg(msg); | 577 | rtp_free_msg(session, msg); |
585 | return -1; | 578 | return 0; |
586 | } | 579 | } |
587 | |||
588 | /* Handle */ | ||
589 | if (session->payload_type == rtp_TypeAudio % 128) | ||
590 | ac_queue_message(session->cs, msg); | ||
591 | else /* It can only be video */ | ||
592 | vc_queue_message(session->cs, msg); | ||
593 | |||
594 | return 0; | ||
595 | } | 580 | } |
596 | int handle_rtcp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) | 581 | int handle_rtcp_packet ( Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object ) |
597 | { | 582 | { |