diff options
Diffstat (limited to 'toxav/toxrtp.h')
-rwxr-xr-x | toxav/toxrtp.h | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/toxav/toxrtp.h b/toxav/toxrtp.h new file mode 100755 index 00000000..32234ebe --- /dev/null +++ b/toxav/toxrtp.h | |||
@@ -0,0 +1,215 @@ | |||
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 | #define MAX_SEQU_NUM 65535 | ||
33 | |||
34 | |||
35 | /** | ||
36 | * @brief Standard rtp header. | ||
37 | * | ||
38 | */ | ||
39 | |||
40 | typedef struct _RTPHeader { | ||
41 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | ||
42 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | ||
43 | uint16_t sequnum; /* Sequence Number */ | ||
44 | uint32_t timestamp; /* Timestamp */ | ||
45 | uint32_t ssrc; /* SSRC */ | ||
46 | uint32_t* csrc; /* CSRC's table */ | ||
47 | uint32_t length; /* Length of the header in payload string. */ | ||
48 | |||
49 | } RTPHeader; | ||
50 | |||
51 | |||
52 | /** | ||
53 | * @brief Standard rtp extension header. | ||
54 | * | ||
55 | */ | ||
56 | typedef struct _RTPExtHeader { | ||
57 | uint16_t type; /* Extension profile */ | ||
58 | uint16_t length; /* Number of extensions */ | ||
59 | uint32_t* table; /* Extension's table */ | ||
60 | |||
61 | } RTPExtHeader; | ||
62 | |||
63 | |||
64 | /** | ||
65 | * @brief Standard rtp message. | ||
66 | * | ||
67 | */ | ||
68 | typedef struct _RTPMessage { | ||
69 | RTPHeader* header; | ||
70 | RTPExtHeader* ext_header; | ||
71 | |||
72 | uint8_t* data; | ||
73 | uint32_t length; | ||
74 | tox_IP_Port from; | ||
75 | |||
76 | struct _RTPMessage* next; | ||
77 | } RTPMessage; | ||
78 | |||
79 | |||
80 | /** | ||
81 | * @brief Our main session descriptor. | ||
82 | * It measures the session variables and controls | ||
83 | * the entire session. There are functions for manipulating | ||
84 | * the session so tend to use those instead of directly modifying | ||
85 | * session parameters. | ||
86 | * | ||
87 | */ | ||
88 | typedef struct _RTPSession { | ||
89 | uint8_t version; | ||
90 | uint8_t padding; | ||
91 | uint8_t extension; | ||
92 | uint8_t cc; | ||
93 | uint8_t marker; | ||
94 | uint8_t payload_type; | ||
95 | uint16_t sequnum; /* Set when sending */ | ||
96 | uint16_t rsequnum; /* Check when recving msg */ | ||
97 | uint32_t timestamp; | ||
98 | uint32_t ssrc; | ||
99 | uint32_t* csrc; | ||
100 | |||
101 | /* If some additional data must be sent via message | ||
102 | * apply it here. Only by allocating this member you will be | ||
103 | * automatically placing it within a message. | ||
104 | */ | ||
105 | RTPExtHeader* ext_header; | ||
106 | |||
107 | /* External header identifiers */ | ||
108 | int resolution; | ||
109 | int framerate; | ||
110 | |||
111 | |||
112 | /* Since these are only references of the | ||
113 | * call structure don't allocate or free | ||
114 | */ | ||
115 | |||
116 | const uint8_t* encrypt_key; | ||
117 | const uint8_t* decrypt_key; | ||
118 | uint8_t* encrypt_nonce; | ||
119 | uint8_t* decrypt_nonce; | ||
120 | |||
121 | uint8_t* nonce_cycle; | ||
122 | |||
123 | RTPMessage* oldest_msg; | ||
124 | RTPMessage* last_msg; /* tail */ | ||
125 | |||
126 | /* Msg prefix for core to know when recving */ | ||
127 | uint8_t prefix; | ||
128 | |||
129 | pthread_mutex_t mutex; | ||
130 | tox_IP_Port dest; | ||
131 | |||
132 | } RTPSession; | ||
133 | |||
134 | |||
135 | /** | ||
136 | * @brief Release all messages held by session. | ||
137 | * | ||
138 | * @param session The session. | ||
139 | * @return int | ||
140 | * @retval -1 Error occurred. | ||
141 | * @retval 0 Success. | ||
142 | */ | ||
143 | int rtp_release_session_recv ( RTPSession* session ); | ||
144 | |||
145 | |||
146 | /** | ||
147 | * @brief Get's oldest message in the list. | ||
148 | * | ||
149 | * @param session Where the list is. | ||
150 | * @return RTPMessage* The message. You need to call rtp_msg_free() to free it. | ||
151 | * @retval NULL No messages in the list, or no list. | ||
152 | */ | ||
153 | RTPMessage* rtp_recv_msg ( RTPSession* session ); | ||
154 | |||
155 | |||
156 | /** | ||
157 | * @brief Sends msg to _RTPSession::dest | ||
158 | * | ||
159 | * @param session The session. | ||
160 | * @param msg The message | ||
161 | * @param messenger Tox* object. | ||
162 | * @return int | ||
163 | * @retval -1 On error. | ||
164 | * @retval 0 On success. | ||
165 | */ | ||
166 | int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uint16_t length ); | ||
167 | |||
168 | |||
169 | /** | ||
170 | * @brief Speaks for it self. | ||
171 | * | ||
172 | * @param session The control session msg belongs to. It can be NULL. | ||
173 | * @param msg The message. | ||
174 | * @return void | ||
175 | */ | ||
176 | void rtp_free_msg ( RTPSession* session, RTPMessage* msg ); | ||
177 | |||
178 | |||
179 | /** | ||
180 | * @brief Must be called before calling any other rtp function. It's used | ||
181 | * to initialize RTP control session. | ||
182 | * | ||
183 | * @param payload_type Type of payload used to send. You can use values in toxmsi.h::MSICallType | ||
184 | * @param messenger Tox* object. | ||
185 | * @param friend_num Friend id. | ||
186 | * @param encrypt_key Speaks for it self. | ||
187 | * @param decrypt_key Speaks for it self. | ||
188 | * @param encrypt_nonce Speaks for it self. | ||
189 | * @param decrypt_nonce Speaks for it self. | ||
190 | * @return RTPSession* Created control session. | ||
191 | * @retval NULL Error occurred. | ||
192 | */ | ||
193 | RTPSession* rtp_init_session ( int payload_type, | ||
194 | Tox* messenger, | ||
195 | int friend_num, | ||
196 | const uint8_t* encrypt_key, | ||
197 | const uint8_t* decrypt_key, | ||
198 | const uint8_t* encrypt_nonce, | ||
199 | const uint8_t* decrypt_nonce ); | ||
200 | |||
201 | |||
202 | /** | ||
203 | * @brief Terminate the session. | ||
204 | * | ||
205 | * @param session The session. | ||
206 | * @param messenger The messenger who owns the session | ||
207 | * @return int | ||
208 | * @retval -1 Error occurred. | ||
209 | * @retval 0 Success. | ||
210 | */ | ||
211 | int rtp_terminate_session ( RTPSession* session, Tox* messenger ); | ||
212 | |||
213 | |||
214 | |||
215 | #endif /* __TOXRTP */ | ||