diff options
author | mannol <eniz_vukovic@hotmail.com> | 2014-01-25 01:32:33 +0100 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2014-01-25 01:32:33 +0100 |
commit | 65d320e31daa4709bb48b7f2a52c269dde0927e9 (patch) | |
tree | 45081a96be413d850a837d6afcee19fcfbfe7aca /toxav/toxrtp.h | |
parent | 51d8c41390be853a13693476802a834daf8d156a (diff) |
Done with encryption and core adaptations.
Diffstat (limited to 'toxav/toxrtp.h')
-rwxr-xr-x | toxav/toxrtp.h | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/toxav/toxrtp.h b/toxav/toxrtp.h new file mode 100755 index 00000000..b4275aba --- /dev/null +++ b/toxav/toxrtp.h | |||
@@ -0,0 +1,211 @@ | |||
1 | /** toxrtp.h | ||
2 | * | ||
3 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
4 | * | ||
5 | * This file is part of Tox. | ||
6 | * | ||
7 | * Tox is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation, either version 3 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * Tox is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | ||
20 | * | ||
21 | * Report bugs/suggestions to me ( mannol ) at either #tox-dev @ freenode.net:6667 or | ||
22 | * my email: eniz_vukovic@hotmail.com | ||
23 | */ | ||
24 | |||
25 | #ifndef __TOXRTP | ||
26 | #define __TOXRTP | ||
27 | |||
28 | #define RTP_VERSION 2 | ||
29 | #include <inttypes.h> | ||
30 | #include "../toxcore/tox.h" | ||
31 | |||
32 | /** | ||
33 | * Standard rtp header | ||
34 | */ | ||
35 | |||
36 | typedef struct _RTPHeader { | ||
37 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | ||
38 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | ||
39 | uint16_t sequnum; /* Sequence Number */ | ||
40 | uint32_t timestamp; /* Timestamp */ | ||
41 | uint32_t ssrc; /* SSRC */ | ||
42 | uint32_t* csrc; /* CSRC's table */ | ||
43 | uint32_t length; /* Length of the header in payload string. */ | ||
44 | |||
45 | } RTPHeader; | ||
46 | |||
47 | |||
48 | /** | ||
49 | * @brief Standard rtp extension header. | ||
50 | * | ||
51 | */ | ||
52 | typedef struct _RTPExtHeader { | ||
53 | uint16_t type; /* Extension profile */ | ||
54 | uint16_t length; /* Number of extensions */ | ||
55 | uint32_t* table; /* Extension's table */ | ||
56 | |||
57 | } RTPExtHeader; | ||
58 | |||
59 | |||
60 | /** | ||
61 | * @brief Standard rtp message. | ||
62 | * | ||
63 | */ | ||
64 | typedef struct _RTPMessage { | ||
65 | RTPHeader* header; | ||
66 | RTPExtHeader* ext_header; | ||
67 | |||
68 | uint8_t* data; | ||
69 | uint32_t length; | ||
70 | tox_IP_Port from; | ||
71 | |||
72 | struct _RTPMessage* next; | ||
73 | } RTPMessage; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * @brief Our main session descriptor. | ||
78 | * It measures the session variables and controls | ||
79 | * the entire session. There are functions for manipulating | ||
80 | * the session so tend to use those instead of directly modifying | ||
81 | * session parameters. | ||
82 | * | ||
83 | */ | ||
84 | typedef struct _RTPSession { | ||
85 | uint8_t version; | ||
86 | uint8_t padding; | ||
87 | uint8_t extension; | ||
88 | uint8_t cc; | ||
89 | uint8_t marker; | ||
90 | uint8_t payload_type; | ||
91 | uint16_t sequnum; /* Set when sending */ | ||
92 | uint16_t rsequnum; /* Check when recving msg */ | ||
93 | uint32_t timestamp; | ||
94 | uint32_t ssrc; | ||
95 | uint32_t* csrc; | ||
96 | |||
97 | /* If some additional data must be sent via message | ||
98 | * apply it here. Only by allocating this member you will be | ||
99 | * automatically placing it within a message. | ||
100 | */ | ||
101 | RTPExtHeader* ext_header; | ||
102 | |||
103 | /* External header identifiers */ | ||
104 | int resolution; | ||
105 | int framerate; | ||
106 | |||
107 | |||
108 | /* Since these are only references of the | ||
109 | * call structure don't allocate or free | ||
110 | */ | ||
111 | |||
112 | const uint8_t* encrypt_key; | ||
113 | const uint8_t* decrypt_key; | ||
114 | uint8_t* encrypt_nonce; | ||
115 | uint8_t* decrypt_nonce; | ||
116 | |||
117 | uint8_t* nonce_cycle; | ||
118 | |||
119 | RTPMessage* oldest_msg; | ||
120 | RTPMessage* last_msg; /* tail */ | ||
121 | |||
122 | /* Msg prefix for core to know when recving */ | ||
123 | uint8_t prefix; | ||
124 | |||
125 | pthread_mutex_t mutex; | ||
126 | tox_IP_Port dest; | ||
127 | |||
128 | } RTPSession; | ||
129 | |||
130 | |||
131 | /** | ||
132 | * @brief Release all messages held by session. | ||
133 | * | ||
134 | * @param session The session. | ||
135 | * @return int | ||
136 | * @retval -1 Error occurred. | ||
137 | * @retval 0 Success. | ||
138 | */ | ||
139 | int rtp_release_session_recv ( RTPSession* session ); | ||
140 | |||
141 | |||
142 | /** | ||
143 | * @brief Get's oldest message in the list. | ||
144 | * | ||
145 | * @param session Where the list is. | ||
146 | * @return RTPMessage* The message. You need to call rtp_msg_free() to free it. | ||
147 | * @retval NULL No messages in the list, or no list. | ||
148 | */ | ||
149 | RTPMessage* rtp_recv_msg ( RTPSession* session ); | ||
150 | |||
151 | |||
152 | /** | ||
153 | * @brief Sends msg to _RTPSession::dest | ||
154 | * | ||
155 | * @param session The session. | ||
156 | * @param msg The message | ||
157 | * @param messenger Tox* object. | ||
158 | * @return int | ||
159 | * @retval -1 On error. | ||
160 | * @retval 0 On success. | ||
161 | */ | ||
162 | int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uint16_t length ); | ||
163 | |||
164 | |||
165 | /** | ||
166 | * @brief Speaks for it self. | ||
167 | * | ||
168 | * @param session The control session msg belongs to. It can be NULL. | ||
169 | * @param msg The message. | ||
170 | * @return void | ||
171 | */ | ||
172 | void rtp_free_msg ( RTPSession* session, RTPMessage* msg ); | ||
173 | |||
174 | |||
175 | /** | ||
176 | * @brief Must be called before calling any other rtp function. It's used | ||
177 | * to initialize RTP control session. | ||
178 | * | ||
179 | * @param payload_type Type of payload used to send. You can use values in toxmsi.h::MSICallType | ||
180 | * @param messenger Tox* object. | ||
181 | * @param friend_num Friend id. | ||
182 | * @param encrypt_key Speaks for it self. | ||
183 | * @param decrypt_key Speaks for it self. | ||
184 | * @param encrypt_nonce Speaks for it self. | ||
185 | * @param decrypt_nonce Speaks for it self. | ||
186 | * @return RTPSession* Created control session. | ||
187 | * @retval NULL Error occurred. | ||
188 | */ | ||
189 | RTPSession* rtp_init_session ( int payload_type, | ||
190 | Tox* messenger, | ||
191 | int friend_num, | ||
192 | const uint8_t* encrypt_key, | ||
193 | const uint8_t* decrypt_key, | ||
194 | const uint8_t* encrypt_nonce, | ||
195 | const uint8_t* decrypt_nonce ); | ||
196 | |||
197 | |||
198 | /** | ||
199 | * @brief Terminate the session. | ||
200 | * | ||
201 | * @param session The session. | ||
202 | * @param messenger The messenger who owns the session | ||
203 | * @return int | ||
204 | * @retval -1 Error occurred. | ||
205 | * @retval 0 Success. | ||
206 | */ | ||
207 | int rtp_terminate_session ( RTPSession* session, Tox* messenger ); | ||
208 | |||
209 | |||
210 | |||
211 | #endif /* __TOXRTP */ | ||